@samitouri / QOSamiQemu / commits / 54b4a5ad50

pc-bios/s390-ccw: Refactor zipl_run()

Refactor to enhance readability before enabling secure IPL in later patches. Signed-off-by: Zhuoying Cai <zycai@linux.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Jared Rossi <jrossi@linux.ibm.com> Reviewed-by: Collin Walling <walling@linux.ibm.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Link: https://lore.kernel.org/qemu-devel/20260730214624.2328883-21-zycai@linux.ibm.com Signed-off-by: Eric Farman <farman@linux.ibm.com>

Zhuoying Cai committed Jul 30, 2026 at 17:46 UTC 54b4a5ad50d8a06aac442223ac52d5137d3a62ca
1 file changed +34 -20
pc-bios/s390-ccw/bootmap.c
+34 -20
@@ -676,12 +676,42 @@ static int zipl_load_segment(ComponentEntry *entry)
676 return 0;
677 }
678
679 +static int zipl_run_normal(ComponentEntry **entry_ptr, const uint8_t *tmp_sec)
680 +{
681 + ComponentEntry *entry = *entry_ptr;
682 +
683 + while (entry->component_type == ZIPL_COMP_ENTRY_LOAD ||
684 + entry->component_type == ZIPL_COMP_ENTRY_SIGNATURE) {
685 +
686 + /* Secure boot is off, so we skip signature entries */
687 + if (entry->component_type == ZIPL_COMP_ENTRY_SIGNATURE) {
688 + entry++;
689 + continue;
690 + }
691 +
692 + if (zipl_load_segment(entry)) {
693 + return -1;
694 + }
695 +
696 + entry++;
697 +
698 + if ((uint8_t *)&entry[1] > tmp_sec + MAX_SECTOR_SIZE) {
699 + puts("Wrong entry value");
700 + return -EINVAL;
701 + }
702 + }
703 +
704 + *entry_ptr = entry;
705 + return 0;
706 +}
707 +
708 /* Run a zipl program */
709 static int zipl_run(ScsiBlockPtr *pte)
710 {
711 ComponentHeader *header;
712 ComponentEntry *entry;
713 uint8_t tmp_sec[MAX_SECTOR_SIZE];
714 + int rc;
715
716 if (virtio_read(pte->blockno, tmp_sec)) {
717 puts("Cannot read header");
@@ -702,25 +732,10 @@ static int zipl_run(ScsiBlockPtr *pte)
732
733 /* Load image(s) into RAM */
734 entry = (ComponentEntry *)(&header[1]);
705 - while (entry->component_type == ZIPL_COMP_ENTRY_LOAD ||
706 - entry->component_type == ZIPL_COMP_ENTRY_SIGNATURE) {
707 -
708 - /* We don't support secure boot yet, so we skip signature entries */
709 - if (entry->component_type == ZIPL_COMP_ENTRY_SIGNATURE) {
710 - entry++;
711 - continue;
712 - }
735
714 - if (zipl_load_segment(entry)) {
715 - return -1;
716 - }
717 -
718 - entry++;
719 -
720 - if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) {
721 - puts("Wrong entry value");
722 - return -EINVAL;
723 - }
736 + rc = zipl_run_normal(&entry, tmp_sec);
737 + if (rc) {
738 + return rc;
739 }
740
741 if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) {
@@ -728,10 +743,9 @@ static int zipl_run(ScsiBlockPtr *pte)
743 return -EINVAL;
744 }
745
731 - /* should not return */
746 write_reset_psw(entry->compdat.load_psw);
747 jump_to_IPL_code(0);
734 - return -1;
748 + return -1; /* should not return */
749 }
750
751 static int ipl_scsi(void)