zipl/src: Add ->set_location() private method of program component

Add/use ->set_location() private method of struct component_footer
instead of checking component types every time when operating with
program components.

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Eduard Shishkin
2026-06-11 15:43:20 +02:00
committed by Jan Höppner
parent 4f622325ef
commit ee8897f9db
3 changed files with 57 additions and 27 deletions

View File

@@ -58,6 +58,9 @@ struct component_footer {
* in the bootmap file. Otherwise, to * in the bootmap file. Otherwise, to
* phy_block_size boundary. * phy_block_size boundary.
*/ */
void (*set_location)(struct component_loc *location,
address_t load_address, blocknum_t count,
int block_size);
}; };
struct program_component { struct program_component {
@@ -109,6 +112,12 @@ static inline enum scsi_layout get_scsi_layout(unsigned char *bootblock)
return scsi_layout_unknown; return scsi_layout_unknown;
} }
static inline struct component_footer *
component_footer_by_id(enum program_component_id id)
{
return &component_footers[id];
}
static inline component_type component_type_by_id(enum program_component_id id) static inline component_type component_type_by_id(enum program_component_id id)
{ {
return component_footers[id].type; return component_footers[id].type;

View File

@@ -353,6 +353,7 @@ static int add_component_file_range(struct install_set *bis,
{ {
struct program_component *pc = get_component(bis, mirror_id, struct program_component *pc = get_component(bis, mirror_id,
comp_id, menu_idx); comp_id, menu_idx);
struct component_footer *cf = component_footer_by_id(comp_id);
struct disk_info *info = &bis->info->base[mirror_id]; struct disk_info *info = &bis->info->base[mirror_id];
struct component_loc *location = &pc->loc; struct component_loc *location = &pc->loc;
disk_blockptr_t **list = &pc->list; disk_blockptr_t **list = &pc->list;
@@ -413,13 +414,7 @@ static int add_component_file_range(struct install_set *bis,
*count -= DIV_ROUND_UP(trailer, info->phy_block_size); *count -= DIV_ROUND_UP(trailer, info->phy_block_size);
} }
/* Fill in component location */ /* Fill in component location */
if (component_type_by_id(comp_id) == COMPONENT_TYPE_LOAD) { cf->set_location(location, load_address, *count, info->phy_block_size);
location->addr = load_address;
location->size = *count * info->phy_block_size;
} else {
location->addr = 0;
location->size = 0;
}
/* Try to compact list */ /* Try to compact list */
*count = disk_compact_blocklist(*list, *count, info); *count = disk_compact_blocklist(*list, *count, info);
write_segment_table: write_segment_table:
@@ -472,6 +467,7 @@ static int add_component_buffer_base(struct install_set *bis, void *buffer,
comp_id, menu_idx); comp_id, menu_idx);
struct file_range *comp_reg = get_component_range(bis, comp_id, struct file_range *comp_reg = get_component_range(bis, comp_id,
menu_idx); menu_idx);
struct component_footer *cf = component_footer_by_id(comp_id);
struct disk_info *info = &bis->info->base[mirror_id]; struct disk_info *info = &bis->info->base[mirror_id];
struct component_loc *location = &pc->loc; struct component_loc *location = &pc->loc;
disk_blockptr_t **list = &pc->list; disk_blockptr_t **list = &pc->list;
@@ -506,14 +502,9 @@ static int add_component_buffer_base(struct install_set *bis, void *buffer,
comp_reg->offset = offset; comp_reg->offset = offset;
comp_reg->len = size; comp_reg->len = size;
} }
if (component_type_by_id(comp_id) == COMPONENT_TYPE_LOAD) { /* Fill in component location */
/* Fill in component location */ cf->set_location(location, data.load_address, *count,
location->addr = data.load_address; info->phy_block_size);
location->size = *count * info->phy_block_size;
} else {
location->addr = 0;
location->size = 0;
}
/* Try to compact list */ /* Try to compact list */
*count = disk_compact_blocklist(*list, *count, info); *count = disk_compact_blocklist(*list, *count, info);
write_segment_table: write_segment_table:

View File

@@ -257,57 +257,87 @@ main(int argc, char* argv[])
return abs(rc); return abs(rc);
} }
static void set_location_common(struct component_loc *location,
address_t load_address,
blocknum_t count,
int block_size)
{
location->addr = load_address;
location->size = count * block_size;
}
static void set_location_noop(struct component_loc *location,
__attribute__((unused)) address_t load_address,
__attribute__((unused)) blocknum_t count,
__attribute__((unused)) int block_size)
{
location->addr = 0;
location->size = 0;
}
/** /**
* Program Component Footers * Program Component Footers
*/ */
struct component_footer component_footers[NR_PROGRAM_COMPONENTS] = { struct component_footer component_footers[NR_PROGRAM_COMPONENTS] = {
[COMPONENT_ID_HEAP_AREA] = { [COMPONENT_ID_HEAP_AREA] = {
.type = COMPONENT_TYPE_LOAD, .type = COMPONENT_TYPE_LOAD,
.desc = "heap area" .desc = "heap area",
.set_location = set_location_common
}, },
[COMPONENT_ID_STACK_AREA] = { [COMPONENT_ID_STACK_AREA] = {
.type = COMPONENT_TYPE_LOAD, .type = COMPONENT_TYPE_LOAD,
.desc = "stack area" .desc = "stack area",
.set_location = set_location_common
}, },
[COMPONENT_ID_LOADER_SIGNATURE] = { [COMPONENT_ID_LOADER_SIGNATURE] = {
.type = COMPONENT_TYPE_SIGNATURE, .type = COMPONENT_TYPE_SIGNATURE,
.desc = "loader signature" .desc = "loader signature",
.set_location = set_location_noop
}, },
[COMPONENT_ID_LOADER] = { [COMPONENT_ID_LOADER] = {
.type = COMPONENT_TYPE_LOAD, .type = COMPONENT_TYPE_LOAD,
.desc = "internal loader" .desc = "internal loader",
.set_location = set_location_common
}, },
[COMPONENT_ID_PARAMETERS] = { [COMPONENT_ID_PARAMETERS] = {
.type = COMPONENT_TYPE_LOAD, .type = COMPONENT_TYPE_LOAD,
.desc = "parameters" .desc = "parameters",
.set_location = set_location_common
}, },
[COMPONENT_ID_IMAGE_SIGNATURE] = { [COMPONENT_ID_IMAGE_SIGNATURE] = {
.type = COMPONENT_TYPE_SIGNATURE, .type = COMPONENT_TYPE_SIGNATURE,
.desc = "image signature" .desc = "image signature",
.set_location = set_location_noop,
}, },
[COMPONENT_ID_KERNEL_IMAGE] = { [COMPONENT_ID_KERNEL_IMAGE] = {
.type = COMPONENT_TYPE_LOAD, .type = COMPONENT_TYPE_LOAD,
.desc = "kernel image" .desc = "kernel image",
.set_location = set_location_common
}, },
[COMPONENT_ID_PARMLINE] = { [COMPONENT_ID_PARMLINE] = {
.type = COMPONENT_TYPE_LOAD, .type = COMPONENT_TYPE_LOAD,
.desc = "parmline" .desc = "parmline",
.set_location = set_location_common
}, },
[COMPONENT_ID_RAMDISK_SIGNATURE] = { [COMPONENT_ID_RAMDISK_SIGNATURE] = {
.type = COMPONENT_TYPE_SIGNATURE, .type = COMPONENT_TYPE_SIGNATURE,
.desc = "ramdisk signature" .desc = "ramdisk signature",
.set_location = set_location_noop
}, },
[COMPONENT_ID_RAMDISK] = { [COMPONENT_ID_RAMDISK] = {
.type = COMPONENT_TYPE_LOAD, .type = COMPONENT_TYPE_LOAD,
.desc = "initial ramdisk" .desc = "initial ramdisk",
.set_location = set_location_common
}, },
[COMPONENT_ID_ENVBLK] = { [COMPONENT_ID_ENVBLK] = {
.type = COMPONENT_TYPE_LOAD, .type = COMPONENT_TYPE_LOAD,
.desc = "environment blk", .desc = "environment blk",
.fs_block_aligned = 1 .fs_block_aligned = 1,
.set_location = set_location_common
}, },
[COMPONENT_ID_SEGMENT_FILE] = { [COMPONENT_ID_SEGMENT_FILE] = {
.type = COMPONENT_TYPE_EXECUTE, .type = COMPONENT_TYPE_EXECUTE,
.desc = "segment file" .desc = "segment file",
.set_location = set_location_noop
} }
}; };