Skip to content

Commit 67c8e22

Browse files
timg236popcornmix
authored andcommitted
firmware: raspberrypi: Add support for tryonce reboot flag
Define a new mailbox (SET_REBOOT_FLAGS) which may be used to pass optional flags to the Raspberry Pi firmware that changes the behaviour of the bootloader and firmware during a reboot. Currently this just defines the 'tryboot' flag which causes the firmware to load tryboot.txt instead config.txt. This alternate configuration file can be used to specify the path of an alternate firmware and kernels allowing a fallback mechanism to be implemented for OS upgrades.
1 parent 3b30011 commit 67c8e22

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎drivers/firmware/raspberrypi.c‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ static int rpi_firmware_notify_reboot(struct notifier_block *nb,
195195
{
196196
struct rpi_firmware *fw;
197197
struct platform_device *pdev = g_pdev;
198+
u32 reboot_flags = 0;
198199

199200
if (!pdev)
200201
return 0;
@@ -203,8 +204,28 @@ static int rpi_firmware_notify_reboot(struct notifier_block *nb,
203204
if (!fw)
204205
return 0;
205206

206-
(void)rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_REBOOT,
207-
0, 0);
207+
// The partition id is the first parameter followed by zero or
208+
// more flags separated by spaces indicating the reason for the reboot.
209+
//
210+
// 'tryboot': Sets a one-shot flag which is cleared upon reboot and
211+
// causes the tryboot.txt to be loaded instead of config.txt
212+
// by the bootloader and the start.elf firmware.
213+
//
214+
// This is intended to allow automatic fallback to a known
215+
// good image if an OS/FW upgrade fails.
216+
//
217+
// N.B. The firmware mechanism for storing reboot flags may vary
218+
// on different Raspberry Pi models.
219+
if (data && strstr(data, " tryboot"))
220+
reboot_flags |= 0x1;
221+
222+
// The mailbox might have been called earlier, directly via vcmailbox
223+
// so only overwrite if reboot flags are passed to the reboot command.
224+
if (reboot_flags)
225+
(void)rpi_firmware_property(fw, RPI_FIRMWARE_SET_REBOOT_FLAGS,
226+
&reboot_flags, sizeof(reboot_flags));
227+
228+
(void)rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_REBOOT, NULL, 0);
208229

209230
return 0;
210231
}

‎include/soc/bcm2835/raspberrypi-firmware.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ enum rpi_firmware_property_tag {
9797
RPI_FIRMWARE_GET_POE_HAT_VAL = 0x00030049,
9898
RPI_FIRMWARE_SET_POE_HAT_VAL = 0x00030050,
9999
RPI_FIRMWARE_NOTIFY_XHCI_RESET = 0x00030058,
100+
RPI_FIRMWARE_GET_REBOOT_FLAGS = 0x00030064,
101+
RPI_FIRMWARE_SET_REBOOT_FLAGS = 0x00038064,
100102

101103
/* Dispmanx TAGS */
102104
RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE = 0x00040001,

0 commit comments

Comments
 (0)