On 7/1/26 4:49 PM, Zhuoying Cai wrote:
Change zipl_load_segment() to accept explicit blockno and address
parameters instead of ComponentEntry pointer and return segment length.

Modify this function to allow the caller to specify a memory address
where segment data should be loaded into.

seg_len variable is necessary to store the calculated segment length and
is used during signature verification. Return the length on success, or
a negative return code on failure.

Remove static qualifier and add function declaration to bootmap.h to
make it accessible to other modules.

Signed-off-by: Zhuoying Cai <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: Collin Walling <[email protected]>
---
  pc-bios/s390-ccw/bootmap.c | 18 ++++++++++--------
  pc-bios/s390-ccw/bootmap.h |  2 ++
  2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
index b9ba004cfc..b19981feb1 100644
--- a/pc-bios/s390-ccw/bootmap.c
+++ b/pc-bios/s390-ccw/bootmap.c
@@ -613,19 +613,19 @@ static int ipl_eckd(void)
   * IPL a SCSI disk
   */
-static int zipl_load_segment(ComponentEntry *entry)
+/*
+ * Returns: length of the segment on success,
+ *          negative value on error.
+ */
+int zipl_load_segment(block_number_t blockno, uint64_t address)
  {
      const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));
      ScsiBlockPtr *bprs = (void *)sec;
      const int bprs_size = sizeof(sec);
-    block_number_t blockno;
-    uint64_t address;
      int i;
      char err_msg[] = "zIPL failed to read BPRS at 0xZZZZZZZZZZZZZZZZ";
      char *blk_no = &err_msg[30]; /* where to print blockno in (those ZZs) */
-
-    blockno = entry->data.blockno;
-    address = entry->compdat.load_addr;
+    int seg_len = 0;
debug_print_int("loading segment at block", blockno);
      debug_print_int("addr", address);
@@ -668,10 +668,12 @@ static int zipl_load_segment(ComponentEntry *entry)
                  puts("zIPL load segment failed");
                  return -EIO;
              }
+
+            seg_len += bprs->size * (bprs[i].blockct + 1);
          }
      } while (blockno);
- return 0;
+    return seg_len;
  }
static int zipl_run_normal(ComponentEntry **entry_ptr, uint8_t *tmp_sec)
@@ -687,7 +689,7 @@ static int zipl_run_normal(ComponentEntry **entry_ptr, 
uint8_t *tmp_sec)
              continue;
          }
- if (zipl_load_segment(entry)) {
+        if (zipl_load_segment(entry->data.blockno, entry->compdat.load_addr) < 
0) {
              return -1;
          }
diff --git a/pc-bios/s390-ccw/bootmap.h b/pc-bios/s390-ccw/bootmap.h
index 95943441d3..8d61ac383c 100644
--- a/pc-bios/s390-ccw/bootmap.h
+++ b/pc-bios/s390-ccw/bootmap.h
@@ -113,6 +113,8 @@ typedef struct ScsiMbr {
      ScsiBlockPtr pt;   /* block pointer to program table */
  } __attribute__ ((packed)) ScsiMbr;
+int zipl_load_segment(block_number_t blockno, uint64_t address);
+
  #define ZIPL_MAGIC              "zIPL"
  #define ZIPL_MAGIC_EBCDIC       "\xa9\xc9\xd7\xd3"
  #define IPL1_MAGIC "\xc9\xd7\xd3\xf1" /* == "IPL1" in EBCDIC */

Reviewed-by: Jared Rossi <[email protected]>

Reply via email to