Skip to content

Commit ce015ac

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 ba5639b commit ce015ac

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
@@ -193,6 +193,7 @@ static int rpi_firmware_notify_reboot(struct notifier_block *nb,
193193
{
194194
struct rpi_firmware *fw;
195195
struct platform_device *pdev = g_pdev;
196+
u32 reboot_flags = 0;
196197

197198
if (!pdev)
198199
return 0;
@@ -201,8 +202,28 @@ static int rpi_firmware_notify_reboot(struct notifier_block *nb,
201202
if (!fw)
202203
return 0;
203204

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

207228
return 0;
208229
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ enum rpi_firmware_property_tag {
9393
RPI_FIRMWARE_GET_POE_HAT_VAL = 0x00030049,
9494
RPI_FIRMWARE_SET_POE_HAT_VAL = 0x00030050,
9595
RPI_FIRMWARE_NOTIFY_XHCI_RESET = 0x00030058,
96+
RPI_FIRMWARE_GET_REBOOT_FLAGS = 0x00030064,
97+
RPI_FIRMWARE_SET_REBOOT_FLAGS = 0x00038064,
9698
RPI_FIRMWARE_NOTIFY_DISPLAY_DONE = 0x00030066,
9799

98100
/* Dispmanx TAGS */

0 commit comments

Comments
 (0)