From 431e4542ca9c0afa5382ffc64b761448d808222e Mon Sep 17 00:00:00 2001 From: Eduard Shishkin Date: Wed, 27 Aug 2025 14:16:42 +0200 Subject: [PATCH] zipl/src: Reuse data of file components in bootmap If the option '--add-files' is specified, don't duplicate data of components added via add_component_file() and friends to bootmap file for each mirror. Instead, reuse the data that were added when preparing a program table for the first mirror to create metadata (block lists, program tables, etc) specific for other mirrors. Signed-off-by: Eduard Shishkin Reviewed-by: Stefan Haberland Signed-off-by: Steffen Eiden --- zipl/include/install.h | 1 + zipl/src/bootmap.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/zipl/include/install.h b/zipl/include/install.h index 742d58cb..43325daf 100644 --- a/zipl/include/install.h +++ b/zipl/include/install.h @@ -80,6 +80,7 @@ struct install_set { int nr_menu_entries; struct misc_fd mfd; struct install_set_mirror mirrors[MAX_TARGETS]; + struct file_range comp_reg[NR_PROGRAM_COMPONENTS]; char *filename; unsigned int skip_prepare_device:1; unsigned int tmp_filename_created:1; diff --git a/zipl/src/bootmap.c b/zipl/src/bootmap.c index c709752b..112e6b57 100644 --- a/zipl/src/bootmap.c +++ b/zipl/src/bootmap.c @@ -376,15 +376,26 @@ static int add_component_file_range(struct install_set *bis, } size -= trailer; /* Write buffer */ - *count = disk_write_block_buffer(&bis->mfd, 0, buffer, - size, list, - bis->info->fs_block_size, - info); + *count = disk_write_block_buffer_align(&bis->mfd, + 0 /* not a base disk */, + buffer, size, list, + bis->info->fs_block_size, + info, + info->phy_block_size, + /* + * save component offset + */ + &bis->comp_reg + [comp_id].offset); free(buffer); if (*count == 0) { error_text("Could not write to bootmap file"); return -1; } + /* zero offset is occupied by bootmap header */ + assert(bis->comp_reg[comp_id].offset > 0); + /* save component size */ + bis->comp_reg[comp_id].len = size; } else { if (!file_is_on_device(filename, bis->info)) { error_reason("File is not on target device"); @@ -423,7 +434,20 @@ static int add_component_file(struct install_set *bis, const char *filename, void *component, int add_files, int comp_id, int menu_idx, int mirror_id, int program_table_id) { - return add_component_file_range(bis, filename, NULL, load_address, + struct file_range *reg = NULL; + + if (add_files && + bis->comp_reg[comp_id].offset > 0) { + /* + * The file has been already written to the bootmap. + * Use the respective region in the bootmap file to + * add the component + */ + filename = bis->filename; + reg = &bis->comp_reg[comp_id]; + add_files = 0; + } + return add_component_file_range(bis, filename, reg, load_address, trailer, component, add_files, comp_id, menu_idx, mirror_id, program_table_id);