Commit dc19be27 authored by Guillaume Tucker's avatar Guillaume Tucker Committed by Ricardo Cañuelo Navarro
Browse files

arch/x86: populate header->ramdisk_{image,size} when provided



When a ramdisk image is provided in the boot_info structure, copy it
at an appropriate address according to the x86 Linux kernel boot
protocol and pass it on via the kernel header.

BRANCH=none
BUG=b:154536870
TEST=boot on x86
Signed-off-by: Guillaume Tucker's avatarGuillaume Tucker <guillaume.tucker@collabora.com>
Change-Id: I2bc1dc2cc8f5788af18b5af8f556c2c9a2100c95
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/depthcharge/+/2288611

Reviewed-by: default avatarDuncan Laurie <dlaurie@google.com>
Reviewed-by: default avatarFurquan Shaikh <furquan@chromium.org>
Reviewed-by: default avatarGuenter Roeck <groeck@chromium.org>
Reviewed-by: default avatarJulius Werner <jwerner@chromium.org>
Commit-Queue: Guenter Roeck <groeck@chromium.org>
Tested-by: default avatarGuenter Roeck <groeck@chromium.org>
parent 97d33bf9
......@@ -22,6 +22,9 @@
#include "vboot/boot_policy.h"
#include "vboot/util/acpi.h"
/* See "The Linux/x86 Boot Protocol" in kernel docs */
#define INITRD_MAX_ADDRESS 0x37FFFFFF
int boot(struct boot_info *bi)
{
/*
......@@ -44,6 +47,30 @@ int boot(struct boot_info *bi)
// Find the kernel header.
struct setup_header *header = &bparams->hdr;
// Add ramdisk if provided
if (bi->ramdisk_addr) {
uint32_t initrd_addr_max = header->initrd_addr_max;
if (initrd_addr_max > INITRD_MAX_ADDRESS)
initrd_addr_max = INITRD_MAX_ADDRESS;
void *ramdisk = (void*)ALIGN_DOWN(
initrd_addr_max - bi->ramdisk_size, 4096);
unsigned long kernel_size = header->syssize * 16;
if (((uintptr_t)bi->kernel + kernel_size) >
(uintptr_t)ramdisk) {
printf("Not enough space for initrd\n");
return -1;
}
memcpy(ramdisk, bi->ramdisk_addr, bi->ramdisk_size);
header->ramdisk_image = (uintptr_t)ramdisk;
header->ramdisk_size = bi->ramdisk_size;
}
uintptr_t header_start = (uintptr_t)header;
uintptr_t header_end = (uintptr_t)&header->jump +
((header->jump >> 8) & 0xff);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment