Skip to content

Commit 196d6dc

Browse files
stormcjan-kiszka
authored andcommitted
Rollback in TESTING state when kernel image cannot load
In an update scenario, if ustate was just switched from INSTALLED=1 to TESTING=2 but the kernel image to be tested is not present, reboot to trigger a fallback into the original boot path. This is a simple optimization to not wait until the watchdog kicks in and reboots the system to the same effect. Incidentally, this also help to fix downstream issues where U-Boot was incorrectly configured to feed the watchdog indefinitely, i.e., no reboot happens, ever. Signed-off-by: Christian Storm <christian.storm@siemens.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
1 parent 189b6ac commit 196d6dc

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

env/fatvars.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ BG_STATUS load_config(BG_LOADER_PARAMS *bglp)
198198
save_current_config(config_volumes, numHandles);
199199
}
200200

201+
bglp->ustate = env[latest_idx].ustate;
201202
bglp->payload_path = StrDuplicate(env[current_partition].kernelfile);
202203
bglp->payload_options =
203204
StrDuplicate(env[current_partition].kernelparams);

include/bootguard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ typedef struct _BG_LOADER_PARAMS {
3737
CHAR16 *payload_path;
3838
CHAR16 *payload_options;
3939
UINTN timeout;
40+
UINT8 ustate;
4041
} BG_LOADER_PARAMS;

main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
184184
status = BS->LoadImage(TRUE, this_image, payload_dev_path, NULL, 0,
185185
&payload_handle);
186186
if (EFI_ERROR(status)) {
187+
if (bg_loader_params.ustate == USTATE_TESTING) {
188+
/*
189+
* `ustate` was just switched from `1` (INSTALLED)
190+
* to `2` (TESTING), but the kernel image to be
191+
* tested is not present. Reboot to trigger a
192+
* fallback into the original boot path.
193+
*/
194+
ERROR(L"Failed to load kernel image %s (%r).\n",
195+
bg_loader_params.payload_path, status);
196+
ERROR(L"Triggering Rollback as ustate==2 (TESTING).\n");
197+
(VOID) BS->Stall(3 * 1000 * 1000);
198+
ST->RuntimeServices->ResetSystem(EfiResetCold,
199+
EFI_SUCCESS, 0, NULL);
200+
}
187201
error_exit(L"Cannot load specified kernel image", status);
188202
}
189203

0 commit comments

Comments
 (0)