Refactor to enhance readability before enabling secure IPL in later patches.
Signed-off-by: Zhuoying Cai <zy...@linux.ibm.com> --- pc-bios/s390-ccw/bootmap.c | 58 ++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 0f8baa0198..485b55f1bf 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -674,6 +674,38 @@ static int zipl_load_segment(ComponentEntry *entry) return 0; } +static int zipl_run_normal(ComponentEntry *entry, uint8_t *tmp_sec) +{ + while (entry->component_type == ZIPL_COMP_ENTRY_LOAD || + entry->component_type == ZIPL_COMP_ENTRY_SIGNATURE) { + + /* Secure boot is off, so we skip signature entries */ + if (entry->component_type == ZIPL_COMP_ENTRY_SIGNATURE) { + entry++; + continue; + } + + if (zipl_load_segment(entry)) { + return -1; + } + + entry++; + + if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) { + puts("Wrong entry value"); + return -EINVAL; + } + } + + if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) { + puts("No EXEC entry"); + return -EINVAL; + } + + write_reset_psw(entry->compdat.load_psw); + return 0; +} + /* Run a zipl program */ static int zipl_run(ScsiBlockPtr *pte) { @@ -700,34 +732,12 @@ static int zipl_run(ScsiBlockPtr *pte) /* Load image(s) into RAM */ entry = (ComponentEntry *)(&header[1]); - while (entry->component_type == ZIPL_COMP_ENTRY_LOAD || - entry->component_type == ZIPL_COMP_ENTRY_SIGNATURE) { - - /* We don't support secure boot yet, so we skip signature entries */ - if (entry->component_type == ZIPL_COMP_ENTRY_SIGNATURE) { - entry++; - continue; - } - - if (zipl_load_segment(entry)) { - return -1; - } - entry++; - - if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) { - puts("Wrong entry value"); - return -EINVAL; - } - } - - if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) { - puts("No EXEC entry"); - return -EINVAL; + if (zipl_run_normal(entry, tmp_sec)) { + return -1; } /* should not return */ - write_reset_psw(entry->compdat.load_psw); jump_to_IPL_code(0); return -1; } -- 2.49.0