Skip to content

Commit

Permalink
core: Correctly load initramfs in stb container
Browse files Browse the repository at this point in the history
Skiboot does not calculate the actual size and start location of the
initramfs if it is wrapped by an STB container (for example if loading
an initramfs from the ROOTFS partition).

Check if the initramfs is in an STB container and determine the size and
location correctly in the same manner as the kernel. Since
load_initramfs() is called after load_kernel() move the call to
trustedboot_exit_boot_services() into load_and_boot_kernel() so it is
called after both of these.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
sammj authored and stewartsmith committed Apr 11, 2018
1 parent 217e5a4 commit e7a2da8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion core/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ static int flash_load_resource(enum resource_id id, uint32_t subid,
* Back to the old way of doing things, no STB header.
*/
if (subid == RESOURCE_SUBID_NONE) {
if (id == RESOURCE_ID_KERNEL) {
if (id == RESOURCE_ID_KERNEL ||
id == RESOURCE_ID_INITRAMFS) {
/*
* Because actualSize is a lie, we compute the
* size of the BOOTKERNEL based on what the ELF
Expand Down
26 changes: 22 additions & 4 deletions core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@ static bool load_kernel(void)
SECURE_BOOT_HEADERS_SIZE + kernel_size);
}

trustedboot_exit_boot_services();

return true;
}

static void load_initramfs(void)
{
uint64_t *initramfs_start;
void *stb_container = NULL;
int loaded;

loaded = wait_for_resource_loaded(RESOURCE_ID_INITRAMFS,
Expand All @@ -443,15 +443,31 @@ static void load_initramfs(void)
if (loaded != OPAL_SUCCESS || !initramfs_size)
return;

if (stb_is_container(INITRAMFS_LOAD_BASE, initramfs_size)) {
stb_container = INITRAMFS_LOAD_BASE;
initramfs_start = INITRAMFS_LOAD_BASE + SECURE_BOOT_HEADERS_SIZE;
} else {
initramfs_start = INITRAMFS_LOAD_BASE;
}

dt_check_del_prop(dt_chosen, "linux,initrd-start");
dt_check_del_prop(dt_chosen, "linux,initrd-end");

printf("INIT: Initramfs loaded, size: %zu bytes\n", initramfs_size);

dt_add_property_u64(dt_chosen, "linux,initrd-start",
(uint64_t)INITRAMFS_LOAD_BASE);
(uint64_t)initramfs_start);
dt_add_property_u64(dt_chosen, "linux,initrd-end",
(uint64_t)INITRAMFS_LOAD_BASE + initramfs_size);
(uint64_t)initramfs_start + initramfs_size);

if (chip_quirk(QUIRK_MAMBO_CALLOUTS)) {
secureboot_verify(RESOURCE_ID_INITRAMFS,
stb_container,
SECURE_BOOT_HEADERS_SIZE + initramfs_size);
trustedboot_measure(RESOURCE_ID_INITRAMFS,
stb_container,
SECURE_BOOT_HEADERS_SIZE + initramfs_size);
}
}

void *fdt;
Expand Down Expand Up @@ -482,6 +498,8 @@ void __noreturn load_and_boot_kernel(bool is_reboot)

load_initramfs();

trustedboot_exit_boot_services();

ipmi_set_fw_progress_sensor(IPMI_FW_OS_BOOT);

occ_pstates_init();
Expand Down

0 comments on commit e7a2da8

Please sign in to comment.