Attention is currently required from: Julius Werner, Maximilian Brune, Philipp Hug, ron minnich.
Nico Huber has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/84087?usp=email )
Change subject: fit_payload: Use our region API ......................................................................
fit_payload: Use our region API
The code has always used our `struct region` but none of the API. To be able to make the struct more opaque, we have to use the API.
Test: Probably compiles.
Change-Id: I0b4cbd5bd38832036a765952b6fec2af5e63f541 Signed-off-by: Nico Huber nico.h@gmx.de --- M src/arch/arm/fit_payload.c M src/arch/arm64/fit_payload.c M src/arch/riscv/fit_payload.c M src/lib/fit_payload.c 4 files changed, 58 insertions(+), 58 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/87/84087/1
diff --git a/src/arch/arm/fit_payload.c b/src/arch/arm/fit_payload.c index 19f46a8..dbf3350 100644 --- a/src/arch/arm/fit_payload.c +++ b/src/arch/arm/fit_payload.c @@ -17,10 +17,10 @@ return true;
/* Linux 4.15 doesn't like 4KiB alignment. Align to 1 MiB for now. */ - start = ALIGN_UP(MAX(region->offset, range_entry_base(r)), 1 * MiB); + start = ALIGN_UP(MAX(region_offset(region), range_entry_base(r)), 1 * MiB);
- if (start + region->size < range_entry_end(r)) { - region->offset = (size_t)start; + if (start + region_sz(region) < range_entry_end(r)) { + *region = region_create((size_t)start, region_sz(region)); return false; }
@@ -38,7 +38,7 @@ * The kernel ARM documentation recommends loading the kernel above 32MiB * in order to avoid the need to need to relocate prior to decompression. */ - kernel->offset = (uintptr_t)_dram + 32 * MiB; + *kernel = region_create((uintptr_t)_dram + 32 * MiB, region_sz(kernel));
/** * The code assumes that bootmem_walk provides a sorted list of memory @@ -51,36 +51,36 @@ return false;
/* Mark as reserved for future allocations. */ - bootmem_add_range(kernel->offset, kernel->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(kernel), region_sz(kernel), BM_MEM_PAYLOAD);
/** * To ensure the fdt is not overwritten by the kernel decompressor, place * the fdt above the 128 MB from the start of RAM, as recommended by the * kernel documentation. */ - fdt->offset = (uintptr_t)_dram + 128 * MiB; + *fdt = region_create((uintptr_t)_dram + 128 * MiB, region_sz(fdt));
if (!bootmem_walk(fit_place_mem, fdt)) return false;
/* Mark as reserved for future allocations. */ - bootmem_add_range(fdt->offset, fdt->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(fdt), region_sz(fdt), BM_MEM_PAYLOAD);
/* Place INITRD */ if (config->ramdisk) { - initrd->offset = fdt->offset + fdt->size; + *initrd = region_create(region_offset(fdt) + region_sz(fdt), region_sz(initrd));
if (!bootmem_walk(fit_place_mem, initrd)) return false;
/* Mark as reserved for future allocations. */ - bootmem_add_range(initrd->offset, initrd->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(initrd), region_sz(initrd), BM_MEM_PAYLOAD); }
/* Kernel expects FDT as argument */ - arg = (void *)fdt->offset; + arg = (void *)region_offset(fdt);
- prog_set_entry(payload, (void *)kernel->offset, arg); + prog_set_entry(payload, (void *)region_offset(kernel), arg);
bootmem_dump_ranges();
diff --git a/src/arch/arm64/fit_payload.c b/src/arch/arm64/fit_payload.c index f8ae16a..854f485 100644 --- a/src/arch/arm64/fit_payload.c +++ b/src/arch/arm64/fit_payload.c @@ -126,8 +126,8 @@ * At least image_size bytes from the start of the image must be free * for use by the kernel. */ - if (start + region->size < range_entry_end(r)) { - region->offset = (size_t)start; + if (start + region_sz(region) < range_entry_end(r)) { + *region = region_create((size_t)start, region_sz(region)); return false; }
@@ -137,8 +137,8 @@ /** * Place the region in free memory range. * - * The caller has to set region->offset to the minimum allowed address. - * The region->offset is usually 0 on kernel >v4.6 and kernel_base + kernel_size + * The caller has to set the region offset to the minimum allowed address. + * The region offset is usually 0 on kernel >v4.6 and kernel_base + kernel_size * on kernel <v4.6. */ static bool fit_place_mem(const struct range_entry *r, void *arg) @@ -150,10 +150,10 @@ return true;
/* Linux 4.15 doesn't like 4KiB alignment. Align to 1 MiB for now. */ - start = ALIGN_UP(MAX(region->offset, range_entry_base(r)), 1 * MiB); + start = ALIGN_UP(MAX(region_offset(region), range_entry_base(r)), 1 * MiB);
- if (start + region->size < range_entry_end(r)) { - region->offset = (size_t)start; + if (start + region_sz(region) < range_entry_end(r)) { + *region = region_create((size_t)start, region_sz(region)); return false; }
@@ -175,9 +175,9 @@ }
/* Update kernel size from image header, if possible */ - kernel->size = get_kernel_size(config->kernel); + *kernel = region_create(region_offset(kernel), get_kernel_size(config->kernel)); printk(BIOS_DEBUG, "FIT: Using kernel size of 0x%zx bytes\n", - kernel->size); + region_sz(kernel));
/** * The code assumes that bootmem_walk provides a sorted list of memory @@ -191,7 +191,7 @@ return false;
/* Mark as reserved for future allocations. */ - bootmem_add_range(kernel->offset, kernel->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(kernel), region_sz(kernel), BM_MEM_PAYLOAD);
/** * NOTE: versions prior to v4.6 cannot make use of memory below the @@ -208,31 +208,31 @@ /* Place INITRD */ if (config->ramdisk) { if (place_anywhere) - initrd->offset = 0; + *initrd = region_create(0, region_sz(initrd)); else - initrd->offset = kernel->offset + kernel->size; + *initrd = region_create(region_offset(kernel) + region_sz(kernel), region_sz(initrd));
if (!bootmem_walk(fit_place_mem, initrd)) return false; /* Mark as reserved for future allocations. */ - bootmem_add_range(initrd->offset, initrd->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(initrd), region_sz(initrd), BM_MEM_PAYLOAD); }
/* Place FDT */ if (place_anywhere) - fdt->offset = 0; + *fdt = region_create(0, region_sz(fdt)); else - fdt->offset = kernel->offset + kernel->size; + *fdt = region_create(region_offset(kernel) + region_sz(kernel), region_sz(fdt));
if (!bootmem_walk(fit_place_mem, fdt)) return false; /* Mark as reserved for future allocations. */ - bootmem_add_range(fdt->offset, fdt->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(fdt), region_sz(fdt), BM_MEM_PAYLOAD);
/* Kernel expects FDT as argument */ - arg = (void *)fdt->offset; + arg = (void *)region_offset(fdt);
- prog_set_entry(payload, (void *)kernel->offset, arg); + prog_set_entry(payload, (void *)region_offset(kernel), arg);
bootmem_dump_ranges();
diff --git a/src/arch/riscv/fit_payload.c b/src/arch/riscv/fit_payload.c index bfa0c98..c9a0b41 100644 --- a/src/arch/riscv/fit_payload.c +++ b/src/arch/riscv/fit_payload.c @@ -38,7 +38,7 @@ /** * Place the region in free memory range. * - * The caller has to set region->offset to the minimum allowed address. + * The caller has to set the region offset to the minimum allowed address. */ static bool fit_place_mem(const struct range_entry *r, void *arg) { @@ -49,10 +49,10 @@ return true;
/* Section must be aligned at page boundary */ - start = ALIGN_UP(MAX(region->offset, range_entry_base(r)), SECTION_ALIGN); + start = ALIGN_UP(MAX(region_offset(region), range_entry_base(r)), SECTION_ALIGN);
- if (start + region->size < range_entry_end(r)) { - region->offset = (size_t)start; + if (start + region_sz(region) < range_entry_end(r)) { + *region = region_create((size_t)start, region_sz(region)); return false; }
@@ -74,9 +74,8 @@ }
/* Update kernel size from image header, if possible */ - kernel->size = get_kernel_size(config->kernel); - printk(BIOS_DEBUG, "FIT: Using kernel size of 0x%zx bytes\n", - kernel->size); + *kernel = region_create(region_offset(kernel), get_kernel_size(config->kernel)); + printk(BIOS_DEBUG, "FIT: Using kernel size of 0x%zx bytes\n", region_sz(kernel));
/* * The code assumes that bootmem_walk provides a sorted list of memory @@ -85,37 +84,37 @@ * enforced in the called functions. * For details check code on top. */ - kernel->offset = 0; + *kernel = region_create(0, region_sz(kernel)); if (!bootmem_walk(fit_place_mem, kernel)) return false;
/* Mark as reserved for future allocations. */ - bootmem_add_range(kernel->offset, kernel->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(kernel), region_sz(kernel), BM_MEM_PAYLOAD);
/* Place FDT and INITRD after kernel. */
/* Place INITRD */ if (config->ramdisk) { - initrd->offset = kernel->offset + kernel->size; + *initrd = region_create(region_offset(kernel) + region_sz(kernel), region_sz(initrd));
if (!bootmem_walk(fit_place_mem, initrd)) return false; /* Mark as reserved for future allocations. */ - bootmem_add_range(initrd->offset, initrd->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(initrd), region_sz(initrd), BM_MEM_PAYLOAD); }
/* Place FDT */ - fdt->offset = kernel->offset + kernel->size; + *fdt = region_create(region_offset(kernel) + region_sz(kernel), region_sz(fdt));
if (!bootmem_walk(fit_place_mem, fdt)) return false; /* Mark as reserved for future allocations. */ - bootmem_add_range(fdt->offset, fdt->size, BM_MEM_PAYLOAD); + bootmem_add_range(region_offset(fdt), region_sz(fdt), BM_MEM_PAYLOAD);
/* Kernel expects FDT as argument */ - arg = (void *)fdt->offset; + arg = (void *)region_offset(fdt);
- prog_set_entry(payload, (void *)kernel->offset, arg); + prog_set_entry(payload, (void *)region_offset(kernel), arg);
bootmem_dump_ranges();
diff --git a/src/lib/fit_payload.c b/src/lib/fit_payload.c index 21bc4e8..d84a5ad 100644 --- a/src/lib/fit_payload.c +++ b/src/lib/fit_payload.c @@ -18,10 +18,10 @@ static void pack_fdt(struct region *fdt, struct device_tree *dt) { printk(BIOS_INFO, "FIT: Flattening FDT to %p\n", - (void *)fdt->offset); + (void *)region_offset(fdt));
- dt_flatten(dt, (void *)fdt->offset); - prog_segment_loaded(fdt->offset, fdt->size, 0); + dt_flatten(dt, (void *)region_offset(fdt)); + prog_segment_loaded(region_offset(fdt), region_sz(fdt), 0); }
/** @@ -30,7 +30,7 @@ */ static bool extract(struct region *region, struct fit_image_node *node) { - void *dst = (void *)region->offset; + void *dst = (void *)region_offset(region); const char *comp_name; size_t true_size = 0;
@@ -63,12 +63,12 @@ break; case CBFS_COMPRESS_LZMA: timestamp_add_now(TS_ULZMA_START); - true_size = ulzman(node->data, node->size, dst, region->size); + true_size = ulzman(node->data, node->size, dst, region_sz(region)); timestamp_add_now(TS_ULZMA_END); break; case CBFS_COMPRESS_LZ4: timestamp_add_now(TS_ULZ4F_START); - true_size = ulz4fn(node->data, node->size, dst, region->size); + true_size = ulz4fn(node->data, node->size, dst, region_sz(region)); timestamp_add_now(TS_ULZ4F_END); break; default: @@ -92,9 +92,10 @@ /* TODO: This is an ugly heuristic for how much the size will expand on decompression, fix once FIT images support storing the real uncompressed size. */ - struct region r = { .offset = 0, .size = image_node->size * 5 }; - data = malloc(r.size); - r.offset = (uintptr_t)data; + const size_t size = image_node->size * 5; + data = malloc(size); + + struct region r = region_create((uintptr_t)data, size); if (!data || extract(&r, image_node)) return NULL; } @@ -169,7 +170,7 @@ void fit_payload(struct prog *payload, void *data) { struct device_tree *dt = NULL; - struct region kernel = {0}, fdt = {0}, initrd = {0}; + struct region kernel, fdt, initrd;
printk(BIOS_INFO, "FIT: Examine payload %s\n", payload->name);
@@ -207,9 +208,9 @@ fit_update_memory(dt);
/* Collect infos for fit_payload_arch */ - kernel.size = config->kernel->size; - fdt.size = dt_flat_size(dt); - initrd.size = config->ramdisk ? config->ramdisk->size : 0; + kernel = region_create(0, config->kernel->size); + fdt = region_create(0, dt_flat_size(dt)); + initrd = region_create(0, config->ramdisk ? config->ramdisk->size : 0);
/* Invoke arch specific payload placement and fixups */ if (!fit_payload_arch(payload, config, &kernel, &fdt, &initrd)) { @@ -220,7 +221,7 @@
/* Update ramdisk location in FDT */ if (config->ramdisk) - fit_add_ramdisk(dt, (void *)initrd.offset, initrd.size); + fit_add_ramdisk(dt, (void *)region_offset(&initrd), region_sz(&initrd));
/* Repack FDT for handoff to kernel */ pack_fdt(&fdt, dt);