On 7/11/25 5:10 PM, Zhuoying Cai wrote:
> 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..ced5190888 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) {
> +

Add space to align this line with the one above, as it was in the code
you're refactoring:

       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;
>  }

Both zipl_run_normal and zipl_run_secure will end with:

   if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) {
       puts("No EXEC entry");
       return -EINVAL;
   }

   write_reset_psw(entry->compdat.load_psw);

I'd suggest making the refactor pass &entry and leaving the checks
mentioned above at the end of zipl_run.  That way there is less
duplicate code between _normal and _secure.

-- 
Regards,
  Collin

Reply via email to