42cb682e0bed628e6b16d4300c9e5e1e91d118df
[openwrt/staging/svanheule.git] /
1 From b31a82051bb9d4ba1c854df645a9195d3f00216f Mon Sep 17 00:00:00 2001
2 From: Tim Gover <tim.gover@raspberrypi.com>
3 Date: Tue, 20 Oct 2020 11:55:37 +0100
4 Subject: [PATCH] firmware: raspberrypi: Add support for tryonce reboot
5 flag
6
7 Define a new mailbox (SET_REBOOT_FLAGS) which may be used to
8 pass optional flags to the Raspberry Pi firmware that changes
9 the behaviour of the bootloader and firmware during a reboot.
10
11 Currently this just defines the 'tryboot' flag which causes
12 the firmware to load tryboot.txt instead config.txt. This
13 alternate configuration file can be used to specify the
14 path of an alternate firmware and kernels allowing a fallback
15 mechanism to be implemented for OS upgrades.
16 ---
17 drivers/firmware/raspberrypi.c | 25 +++++++++++++++++++++++--
18 1 file changed, 23 insertions(+), 2 deletions(-)
19
20 --- a/drivers/firmware/raspberrypi.c
21 +++ b/drivers/firmware/raspberrypi.c
22 @@ -193,6 +193,7 @@ static int rpi_firmware_notify_reboot(st
23 {
24 struct rpi_firmware *fw;
25 struct platform_device *pdev = g_pdev;
26 + u32 reboot_flags = 0;
27
28 if (!pdev)
29 return 0;
30 @@ -201,8 +202,28 @@ static int rpi_firmware_notify_reboot(st
31 if (!fw)
32 return 0;
33
34 - (void)rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_REBOOT,
35 - 0, 0);
36 + // The partition id is the first parameter followed by zero or
37 + // more flags separated by spaces indicating the reason for the reboot.
38 + //
39 + // 'tryboot': Sets a one-shot flag which is cleared upon reboot and
40 + // causes the tryboot.txt to be loaded instead of config.txt
41 + // by the bootloader and the start.elf firmware.
42 + //
43 + // This is intended to allow automatic fallback to a known
44 + // good image if an OS/FW upgrade fails.
45 + //
46 + // N.B. The firmware mechanism for storing reboot flags may vary
47 + // on different Raspberry Pi models.
48 + if (data && strstr(data, " tryboot"))
49 + reboot_flags |= 0x1;
50 +
51 + // The mailbox might have been called earlier, directly via vcmailbox
52 + // so only overwrite if reboot flags are passed to the reboot command.
53 + if (reboot_flags)
54 + (void)rpi_firmware_property(fw, RPI_FIRMWARE_SET_REBOOT_FLAGS,
55 + &reboot_flags, sizeof(reboot_flags));
56 +
57 + (void)rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_REBOOT, NULL, 0);
58
59 return 0;
60 }