|
@@ -8,7 +8,8 @@
|
|
|
* directory.
|
|
|
*/
|
|
|
|
|
|
-#include "libc.h"
|
|
|
+#include <string.h>
|
|
|
+#include <stdio.h>
|
|
|
#include "s390-ccw.h"
|
|
|
#include "s390-arch.h"
|
|
|
#include "bootmap.h"
|
|
@@ -21,7 +22,7 @@
|
|
|
|
|
|
#ifdef DEBUG_FALLBACK
|
|
|
#define dputs(txt) \
|
|
|
- do { sclp_print("zipl: " txt); } while (0)
|
|
|
+ do { printf("zipl: " txt); } while (0)
|
|
|
#else
|
|
|
#define dputs(fmt, ...) \
|
|
|
do { } while (0)
|
|
@@ -61,15 +62,34 @@ static void *s2_prev_blk = _s2;
|
|
|
static void *s2_cur_blk = _s2 + MAX_SECTOR_SIZE;
|
|
|
static void *s2_next_blk = _s2 + MAX_SECTOR_SIZE * 2;
|
|
|
|
|
|
-static inline void verify_boot_info(BootInfo *bip)
|
|
|
+static inline int verify_boot_info(BootInfo *bip)
|
|
|
{
|
|
|
- IPL_assert(magic_match(bip->magic, ZIPL_MAGIC), "No zIPL sig in BootInfo");
|
|
|
- IPL_assert(bip->version == BOOT_INFO_VERSION, "Wrong zIPL version");
|
|
|
- IPL_assert(bip->bp_type == BOOT_INFO_BP_TYPE_IPL, "DASD is not for IPL");
|
|
|
- IPL_assert(bip->dev_type == BOOT_INFO_DEV_TYPE_ECKD, "DASD is not ECKD");
|
|
|
- IPL_assert(bip->flags == BOOT_INFO_FLAGS_ARCH, "Not for this arch");
|
|
|
- IPL_assert(block_size_ok(bip->bp.ipl.bm_ptr.eckd.bptr.size),
|
|
|
- "Bad block size in zIPL section of the 1st record.");
|
|
|
+ if (!magic_match(bip->magic, ZIPL_MAGIC)) {
|
|
|
+ puts("No zIPL sig in BootInfo");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
+ if (bip->version != BOOT_INFO_VERSION) {
|
|
|
+ puts("Wrong zIPL version");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
+ if (bip->bp_type != BOOT_INFO_BP_TYPE_IPL) {
|
|
|
+ puts("DASD is not for IPL");
|
|
|
+ return -ENODEV;
|
|
|
+ }
|
|
|
+ if (bip->dev_type != BOOT_INFO_DEV_TYPE_ECKD) {
|
|
|
+ puts("DASD is not ECKD");
|
|
|
+ return -ENODEV;
|
|
|
+ }
|
|
|
+ if (bip->flags != BOOT_INFO_FLAGS_ARCH) {
|
|
|
+ puts("Not for this arch");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
+ if (!block_size_ok(bip->bp.ipl.bm_ptr.eckd.bptr.size)) {
|
|
|
+ puts("Bad block size in zIPL section of 1st record");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
static void eckd_format_chs(ExtEckdBlockPtr *ptr, bool ldipl,
|
|
@@ -144,14 +164,17 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
|
|
|
bool more_data;
|
|
|
|
|
|
memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
|
|
|
- read_block(blk, bprs, "BPRS read failed");
|
|
|
+ if (virtio_read(blk, bprs)) {
|
|
|
+ puts("BPRS read failed");
|
|
|
+ return ERROR_BLOCK_NR;
|
|
|
+ }
|
|
|
|
|
|
do {
|
|
|
more_data = false;
|
|
|
for (j = 0;; j++) {
|
|
|
block_nr = gen_eckd_block_num(&bprs[j].xeckd, ldipl);
|
|
|
if (is_null_block_number(block_nr)) { /* end of chunk */
|
|
|
- break;
|
|
|
+ return NULL_BLOCK_NR;
|
|
|
}
|
|
|
|
|
|
/* we need the updated blockno for the next indirect entry
|
|
@@ -162,15 +185,20 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
|
|
|
}
|
|
|
|
|
|
/* List directed pointer does not store block size */
|
|
|
- IPL_assert(ldipl || block_size_ok(bprs[j].xeckd.bptr.size),
|
|
|
- "bad chunk block size");
|
|
|
+ if (!ldipl && !block_size_ok(bprs[j].xeckd.bptr.size)) {
|
|
|
+ puts("Bad chunk block size");
|
|
|
+ return ERROR_BLOCK_NR;
|
|
|
+ }
|
|
|
|
|
|
if (!eckd_valid_address(&bprs[j].xeckd, ldipl)) {
|
|
|
/*
|
|
|
* If an invalid address is found during LD-IPL then break and
|
|
|
- * retry as CCW
|
|
|
+ * retry as CCW-IPL, otherwise abort on error
|
|
|
*/
|
|
|
- IPL_assert(ldipl, "bad chunk ECKD addr");
|
|
|
+ if (!ldipl) {
|
|
|
+ puts("Bad chunk ECKD address");
|
|
|
+ return ERROR_BLOCK_NR;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -188,7 +216,10 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
|
|
|
* I.e. the next ptr must point to the unused memory area
|
|
|
*/
|
|
|
memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
|
|
|
- read_block(block_nr, bprs, "BPRS continuation read failed");
|
|
|
+ if (virtio_read(block_nr, bprs)) {
|
|
|
+ puts("BPRS continuation read failed");
|
|
|
+ return ERROR_BLOCK_NR;
|
|
|
+ }
|
|
|
more_data = true;
|
|
|
break;
|
|
|
}
|
|
@@ -197,7 +228,10 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
|
|
|
* to memory (address).
|
|
|
*/
|
|
|
rc = virtio_read_many(block_nr, (void *)(*address), count + 1);
|
|
|
- IPL_assert(rc == 0, "code chunk read failed");
|
|
|
+ if (rc != 0) {
|
|
|
+ puts("Code chunk read failed");
|
|
|
+ return ERROR_BLOCK_NR;
|
|
|
+ }
|
|
|
|
|
|
*address += (count + 1) * virtio_get_block_size();
|
|
|
}
|
|
@@ -231,7 +265,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
|
|
|
|
|
|
/* Get Stage1b data */
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(s1b_block_nr, s1b, "Cannot read stage1b boot loader");
|
|
|
+ if (virtio_read(s1b_block_nr, s1b)) {
|
|
|
+ puts("Cannot read stage1b boot loader");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
memset(_s2, FREE_SPACE_FILLER, sizeof(_s2));
|
|
|
|
|
@@ -243,7 +280,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- read_block(cur_block_nr, s2_cur_blk, "Cannot read stage2 boot loader");
|
|
|
+ if (virtio_read(cur_block_nr, s2_cur_blk)) {
|
|
|
+ puts("Cannot read stage2 boot loader");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
if (find_zipl_boot_menu_banner(&banner_offset)) {
|
|
|
/*
|
|
@@ -251,8 +291,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
|
|
|
* possibility of menu data spanning multiple blocks.
|
|
|
*/
|
|
|
if (prev_block_nr) {
|
|
|
- read_block(prev_block_nr, s2_prev_blk,
|
|
|
- "Cannot read stage2 boot loader");
|
|
|
+ if (virtio_read(prev_block_nr, s2_prev_blk)) {
|
|
|
+ puts("Cannot read stage2 boot loader");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (i + 1 < STAGE2_BLK_CNT_MAX) {
|
|
@@ -260,8 +302,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
|
|
|
}
|
|
|
|
|
|
if (next_block_nr && !is_null_block_number(next_block_nr)) {
|
|
|
- read_block(next_block_nr, s2_next_blk,
|
|
|
- "Cannot read stage2 boot loader");
|
|
|
+ if (virtio_read(next_block_nr, s2_next_blk)) {
|
|
|
+ puts("Cannot read stage2 boot loader");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return menu_get_zipl_boot_index(s2_cur_blk + banner_offset);
|
|
@@ -270,11 +314,11 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
|
|
|
prev_block_nr = cur_block_nr;
|
|
|
}
|
|
|
|
|
|
- sclp_print("No zipl boot menu data found. Booting default entry.");
|
|
|
+ printf("No zipl boot menu data found. Booting default entry.");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static void run_eckd_boot_script(block_number_t bmt_block_nr,
|
|
|
+static int run_eckd_boot_script(block_number_t bmt_block_nr,
|
|
|
block_number_t s1b_block_nr)
|
|
|
{
|
|
|
int i;
|
|
@@ -291,17 +335,28 @@ static void run_eckd_boot_script(block_number_t bmt_block_nr,
|
|
|
}
|
|
|
|
|
|
debug_print_int("loadparm", loadparm);
|
|
|
- IPL_assert(loadparm < MAX_BOOT_ENTRIES, "loadparm value greater than"
|
|
|
- " maximum number of boot entries allowed");
|
|
|
+ if (loadparm >= MAX_BOOT_ENTRIES) {
|
|
|
+ puts("loadparm value greater than max number of boot entries allowed");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(bmt_block_nr, sec, "Cannot read Boot Map Table");
|
|
|
+ if (virtio_read(bmt_block_nr, sec)) {
|
|
|
+ puts("Cannot read Boot Map Table");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
block_nr = gen_eckd_block_num(&bmt->entry[loadparm].xeckd, ldipl);
|
|
|
- IPL_assert(block_nr != -1, "Cannot find Boot Map Table Entry");
|
|
|
+ if (block_nr == NULL_BLOCK_NR) {
|
|
|
+ puts("Cannot find Boot Map Table Entry");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(block_nr, sec, "Cannot read Boot Map Script");
|
|
|
+ if (virtio_read(block_nr, sec)) {
|
|
|
+ puts("Cannot read Boot Map Script");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
for (i = 0; bms->entry[i].type == BOOT_SCRIPT_LOAD ||
|
|
|
bms->entry[i].type == BOOT_SCRIPT_SIGNATURE; i++) {
|
|
@@ -316,21 +371,27 @@ static void run_eckd_boot_script(block_number_t bmt_block_nr,
|
|
|
|
|
|
do {
|
|
|
block_nr = load_eckd_segments(block_nr, ldipl, &address);
|
|
|
- } while (block_nr != -1);
|
|
|
+ if (block_nr == ERROR_BLOCK_NR) {
|
|
|
+ return ldipl ? 0 : -EIO;
|
|
|
+ }
|
|
|
+ } while (block_nr != NULL_BLOCK_NR);
|
|
|
}
|
|
|
|
|
|
if (ldipl && bms->entry[i].type != BOOT_SCRIPT_EXEC) {
|
|
|
/* Abort LD-IPL and retry as CCW-IPL */
|
|
|
- return;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
- IPL_assert(bms->entry[i].type == BOOT_SCRIPT_EXEC,
|
|
|
- "Unknown script entry type");
|
|
|
- write_reset_psw(bms->entry[i].address.load_address); /* no return */
|
|
|
- jump_to_IPL_code(0); /* no return */
|
|
|
+ if (bms->entry[i].type != BOOT_SCRIPT_EXEC) {
|
|
|
+ puts("Unknown script entry type");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
+ write_reset_psw(bms->entry[i].address.load_address);
|
|
|
+ jump_to_IPL_code(0);
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
-static void ipl_eckd_cdl(void)
|
|
|
+static int ipl_eckd_cdl(void)
|
|
|
{
|
|
|
XEckdMbr *mbr;
|
|
|
EckdCdlIpl2 *ipl2 = (void *)sec;
|
|
@@ -338,23 +399,26 @@ static void ipl_eckd_cdl(void)
|
|
|
block_number_t bmt_block_nr, s1b_block_nr;
|
|
|
|
|
|
/* we have just read the block #0 and recognized it as "IPL1" */
|
|
|
- sclp_print("CDL\n");
|
|
|
+ puts("CDL");
|
|
|
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(1, ipl2, "Cannot read IPL2 record at block 1");
|
|
|
+ if (virtio_read(1, ipl2)) {
|
|
|
+ puts("Cannot read IPL2 record at block 1");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
mbr = &ipl2->mbr;
|
|
|
if (!magic_match(mbr, ZIPL_MAGIC)) {
|
|
|
- sclp_print("No zIPL section in IPL2 record.\n");
|
|
|
- return;
|
|
|
+ puts("No zIPL section in IPL2 record.");
|
|
|
+ return 0;
|
|
|
}
|
|
|
if (!block_size_ok(mbr->blockptr.xeckd.bptr.size)) {
|
|
|
- sclp_print("Bad block size in zIPL section of IPL2 record.\n");
|
|
|
- return;
|
|
|
+ puts("Bad block size in zIPL section of IPL2 record.");
|
|
|
+ return 0;
|
|
|
}
|
|
|
if (mbr->dev_type != DEV_TYPE_ECKD) {
|
|
|
- sclp_print("Non-ECKD device type in zIPL section of IPL2 record.\n");
|
|
|
- return;
|
|
|
+ puts("Non-ECKD device type in zIPL section of IPL2 record.");
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
/* save pointer to Boot Map Table */
|
|
@@ -364,19 +428,21 @@ static void ipl_eckd_cdl(void)
|
|
|
s1b_block_nr = eckd_block_num(&ipl2->stage1.seek[0].chs);
|
|
|
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(2, vlbl, "Cannot read Volume Label at block 2");
|
|
|
+ if (virtio_read(2, vlbl)) {
|
|
|
+ puts("Cannot read Volume Label at block 2");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
if (!magic_match(vlbl->key, VOL1_MAGIC)) {
|
|
|
- sclp_print("Invalid magic of volume label block.\n");
|
|
|
- return;
|
|
|
+ puts("Invalid magic of volume label block.");
|
|
|
+ return 0;
|
|
|
}
|
|
|
if (!magic_match(vlbl->f.key, VOL1_MAGIC)) {
|
|
|
- sclp_print("Invalid magic of volser block.\n");
|
|
|
- return;
|
|
|
+ puts("Invalid magic of volser block.");
|
|
|
+ return 0;
|
|
|
}
|
|
|
print_volser(vlbl->f.volser);
|
|
|
|
|
|
- run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
|
|
|
- /* no return */
|
|
|
+ return run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
|
|
|
}
|
|
|
|
|
|
static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode)
|
|
@@ -384,8 +450,8 @@ static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode)
|
|
|
LDL_VTOC *vlbl = (void *)sec; /* already read, 3rd block */
|
|
|
char msg[4] = { '?', '.', '\n', '\0' };
|
|
|
|
|
|
- sclp_print((mode == ECKD_CMS) ? "CMS" : "LDL");
|
|
|
- sclp_print(" version ");
|
|
|
+ printf((mode == ECKD_CMS) ? "CMS" : "LDL");
|
|
|
+ printf(" version ");
|
|
|
switch (vlbl->LDL_version) {
|
|
|
case LDL1_VERSION:
|
|
|
msg[0] = '1';
|
|
@@ -398,11 +464,11 @@ static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode)
|
|
|
msg[1] = '?';
|
|
|
break;
|
|
|
}
|
|
|
- sclp_print(msg);
|
|
|
+ printf("%s", msg);
|
|
|
print_volser(vlbl->volser);
|
|
|
}
|
|
|
|
|
|
-static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
|
|
|
+static int ipl_eckd_ldl(ECKD_IPL_mode_t mode)
|
|
|
{
|
|
|
block_number_t bmt_block_nr, s1b_block_nr;
|
|
|
EckdLdlIpl1 *ipl1 = (void *)sec;
|
|
@@ -414,12 +480,15 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
|
|
|
/* DO NOT read BootMap pointer (only one, xECKD) at block #2 */
|
|
|
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(0, sec, "Cannot read block 0 to grab boot info.");
|
|
|
+ if (virtio_read(0, sec)) {
|
|
|
+ puts("Cannot read block 0 to grab boot info.");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
if (mode == ECKD_LDL_UNLABELED) {
|
|
|
if (!magic_match(ipl1->bip.magic, ZIPL_MAGIC)) {
|
|
|
- return; /* not applicable layout */
|
|
|
+ return 0; /* not applicable layout */
|
|
|
}
|
|
|
- sclp_print("unlabeled LDL.\n");
|
|
|
+ puts("unlabeled LDL.");
|
|
|
}
|
|
|
verify_boot_info(&ipl1->bip);
|
|
|
|
|
@@ -429,8 +498,7 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
|
|
|
/* save pointer to Stage1b Data */
|
|
|
s1b_block_nr = eckd_block_num(&ipl1->stage1.seek[0].chs);
|
|
|
|
|
|
- run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
|
|
|
- /* no return */
|
|
|
+ return run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
|
|
|
}
|
|
|
|
|
|
static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr)
|
|
@@ -440,7 +508,10 @@ static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr)
|
|
|
BootRecord *br;
|
|
|
|
|
|
blockno = gen_eckd_block_num(ptr, 0);
|
|
|
- read_block(blockno, tmp_sec, "Cannot read boot record");
|
|
|
+ if (virtio_read(blockno, tmp_sec)) {
|
|
|
+ puts("Cannot read boot record");
|
|
|
+ return ERROR_BLOCK_NR;
|
|
|
+ }
|
|
|
br = (BootRecord *)tmp_sec;
|
|
|
if (!magic_match(br->magic, ZIPL_MAGIC)) {
|
|
|
/* If the boot record is invalid, return and try CCW-IPL instead */
|
|
@@ -466,10 +537,10 @@ static void print_eckd_msg(void)
|
|
|
*p-- = ' ';
|
|
|
}
|
|
|
}
|
|
|
- sclp_print(msg);
|
|
|
+ printf("%s", msg);
|
|
|
}
|
|
|
|
|
|
-static void ipl_eckd(void)
|
|
|
+static int ipl_eckd(void)
|
|
|
{
|
|
|
IplVolumeLabel *vlbl = (void *)sec;
|
|
|
LDL_VTOC *vtoc = (void *)sec;
|
|
@@ -479,7 +550,10 @@ static void ipl_eckd(void)
|
|
|
|
|
|
/* Block 2 can contain either the CDL VOL1 label or the LDL VTOC */
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(2, vlbl, "Cannot read block 2");
|
|
|
+ if (virtio_read(2, vlbl)) {
|
|
|
+ puts("Cannot read block 2");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
/*
|
|
|
* First check for a list-directed-format pointer which would
|
|
@@ -487,43 +561,60 @@ static void ipl_eckd(void)
|
|
|
*/
|
|
|
if (eckd_valid_address((ExtEckdBlockPtr *)&vlbl->f.br, 0)) {
|
|
|
ldipl_bmt = eckd_find_bmt((ExtEckdBlockPtr *)&vlbl->f.br);
|
|
|
- if (ldipl_bmt) {
|
|
|
- sclp_print("List-Directed\n");
|
|
|
- /* LD-IPL does not use the S1B bock, just make it NULL */
|
|
|
- run_eckd_boot_script(ldipl_bmt, NULL_BLOCK_NR);
|
|
|
- /* Only return in error, retry as CCW-IPL */
|
|
|
- sclp_print("Retrying IPL ");
|
|
|
+ switch (ldipl_bmt) {
|
|
|
+ case ERROR_BLOCK_NR:
|
|
|
+ return -EIO;
|
|
|
+ case NULL_BLOCK_NR:
|
|
|
+ break; /* Invalid BMT but the device may still boot with CCW-IPL */
|
|
|
+ default:
|
|
|
+ puts("List-Directed");
|
|
|
+ /*
|
|
|
+ * LD-IPL does not use the S1B bock, just make it NULL_BLOCK_NR.
|
|
|
+ * In some failure cases retry IPL before aborting.
|
|
|
+ */
|
|
|
+ if (run_eckd_boot_script(ldipl_bmt, NULL_BLOCK_NR)) {
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
+ /* Non-fatal error, retry as CCW-IPL */
|
|
|
+ printf("Retrying IPL ");
|
|
|
print_eckd_msg();
|
|
|
}
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(2, vtoc, "Cannot read block 2");
|
|
|
+ if (virtio_read(2, vtoc)) {
|
|
|
+ puts("Cannot read block 2");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* Not list-directed */
|
|
|
if (magic_match(vtoc->magic, VOL1_MAGIC)) {
|
|
|
- ipl_eckd_cdl(); /* may return in error */
|
|
|
+ if (ipl_eckd_cdl()) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (magic_match(vtoc->magic, CMS1_MAGIC)) {
|
|
|
- ipl_eckd_ldl(ECKD_CMS); /* no return */
|
|
|
+ return ipl_eckd_ldl(ECKD_CMS);
|
|
|
}
|
|
|
if (magic_match(vtoc->magic, LNX1_MAGIC)) {
|
|
|
- ipl_eckd_ldl(ECKD_LDL); /* no return */
|
|
|
+ return ipl_eckd_ldl(ECKD_LDL);
|
|
|
}
|
|
|
|
|
|
- ipl_eckd_ldl(ECKD_LDL_UNLABELED); /* it still may return */
|
|
|
+ if (ipl_eckd_ldl(ECKD_LDL_UNLABELED)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
/*
|
|
|
* Ok, it is not a LDL by any means.
|
|
|
* It still might be a CDL with zero record keys for IPL1 and IPL2
|
|
|
*/
|
|
|
- ipl_eckd_cdl();
|
|
|
+ return ipl_eckd_cdl();
|
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
|
* IPL a SCSI disk
|
|
|
*/
|
|
|
|
|
|
-static void zipl_load_segment(ComponentEntry *entry)
|
|
|
+static int zipl_load_segment(ComponentEntry *entry)
|
|
|
{
|
|
|
const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));
|
|
|
ScsiBlockPtr *bprs = (void *)sec;
|
|
@@ -543,7 +634,10 @@ static void zipl_load_segment(ComponentEntry *entry)
|
|
|
do {
|
|
|
memset(bprs, FREE_SPACE_FILLER, bprs_size);
|
|
|
fill_hex_val(blk_no, &blockno, sizeof(blockno));
|
|
|
- read_block(blockno, bprs, err_msg);
|
|
|
+ if (virtio_read(blockno, bprs)) {
|
|
|
+ puts(err_msg);
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
for (i = 0;; i++) {
|
|
|
uint64_t *cur_desc = (void *)&bprs[i];
|
|
@@ -571,23 +665,37 @@ static void zipl_load_segment(ComponentEntry *entry)
|
|
|
}
|
|
|
address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
|
|
|
(void *)address);
|
|
|
- IPL_assert(address != -1, "zIPL load segment failed");
|
|
|
+ if (!address) {
|
|
|
+ puts("zIPL load segment failed");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
}
|
|
|
} while (blockno);
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
/* Run a zipl program */
|
|
|
-static void zipl_run(ScsiBlockPtr *pte)
|
|
|
+static int zipl_run(ScsiBlockPtr *pte)
|
|
|
{
|
|
|
ComponentHeader *header;
|
|
|
ComponentEntry *entry;
|
|
|
uint8_t tmp_sec[MAX_SECTOR_SIZE];
|
|
|
|
|
|
- read_block(pte->blockno, tmp_sec, "Cannot read header");
|
|
|
+ if (virtio_read(pte->blockno, tmp_sec)) {
|
|
|
+ puts("Cannot read header");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
header = (ComponentHeader *)tmp_sec;
|
|
|
|
|
|
- IPL_assert(magic_match(tmp_sec, ZIPL_MAGIC), "No zIPL magic in header");
|
|
|
- IPL_assert(header->type == ZIPL_COMP_HEADER_IPL, "Bad header type");
|
|
|
+ if (!magic_match(tmp_sec, ZIPL_MAGIC)) {
|
|
|
+ puts("No zIPL magic in header");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
+ if (header->type != ZIPL_COMP_HEADER_IPL) {
|
|
|
+ puts("Bad header type");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
|
|
|
dputs("start loading images\n");
|
|
|
|
|
@@ -602,22 +710,30 @@ static void zipl_run(ScsiBlockPtr *pte)
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- zipl_load_segment(entry);
|
|
|
+ if (zipl_load_segment(entry)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
entry++;
|
|
|
|
|
|
- IPL_assert((uint8_t *)(&entry[1]) <= (tmp_sec + MAX_SECTOR_SIZE),
|
|
|
- "Wrong entry value");
|
|
|
+ if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) {
|
|
|
+ puts("Wrong entry value");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- IPL_assert(entry->component_type == ZIPL_COMP_ENTRY_EXEC, "No EXEC entry");
|
|
|
+ if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) {
|
|
|
+ puts("No EXEC entry");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
|
|
|
/* should not return */
|
|
|
write_reset_psw(entry->compdat.load_psw);
|
|
|
jump_to_IPL_code(0);
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
-static void ipl_scsi(void)
|
|
|
+static int ipl_scsi(void)
|
|
|
{
|
|
|
ScsiMbr *mbr = (void *)sec;
|
|
|
int program_table_entries = 0;
|
|
@@ -628,22 +744,34 @@ static void ipl_scsi(void)
|
|
|
|
|
|
/* Grab the MBR */
|
|
|
memset(sec, FREE_SPACE_FILLER, sizeof(sec));
|
|
|
- read_block(0, mbr, "Cannot read block 0");
|
|
|
+ if (virtio_read(0, mbr)) {
|
|
|
+ puts("Cannot read block 0");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
if (!magic_match(mbr->magic, ZIPL_MAGIC)) {
|
|
|
- return;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
- sclp_print("Using SCSI scheme.\n");
|
|
|
+ puts("Using SCSI scheme.");
|
|
|
debug_print_int("MBR Version", mbr->version_id);
|
|
|
IPL_check(mbr->version_id == 1,
|
|
|
"Unknown MBR layout version, assuming version 1");
|
|
|
debug_print_int("program table", mbr->pt.blockno);
|
|
|
- IPL_assert(mbr->pt.blockno, "No Program Table");
|
|
|
+ if (!mbr->pt.blockno) {
|
|
|
+ puts("No Program Table");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
|
|
|
/* Parse the program table */
|
|
|
- read_block(mbr->pt.blockno, sec, "Error reading Program Table");
|
|
|
- IPL_assert(magic_match(sec, ZIPL_MAGIC), "No zIPL magic in PT");
|
|
|
+ if (virtio_read(mbr->pt.blockno, sec)) {
|
|
|
+ puts("Error reading Program Table");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
+ if (!magic_match(sec, ZIPL_MAGIC)) {
|
|
|
+ puts("No zIPL magic in Program Table");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
|
|
|
for (i = 0; i < MAX_BOOT_ENTRIES; i++) {
|
|
|
if (prog_table->entry[i].scsi.blockno) {
|
|
@@ -653,17 +781,22 @@ static void ipl_scsi(void)
|
|
|
}
|
|
|
|
|
|
debug_print_int("program table entries", program_table_entries);
|
|
|
- IPL_assert(program_table_entries != 0, "Empty Program Table");
|
|
|
+ if (program_table_entries == 0) {
|
|
|
+ puts("Empty Program Table");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
|
|
|
if (menu_is_enabled_enum()) {
|
|
|
loadparm = menu_get_enum_boot_index(valid_entries);
|
|
|
}
|
|
|
|
|
|
debug_print_int("loadparm", loadparm);
|
|
|
- IPL_assert(loadparm < MAX_BOOT_ENTRIES, "loadparm value greater than"
|
|
|
- " maximum number of boot entries allowed");
|
|
|
+ if (loadparm >= MAX_BOOT_ENTRIES) {
|
|
|
+ puts("loadparm value greater than max number of boot entries allowed");
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
|
|
|
- zipl_run(&prog_table->entry[loadparm].scsi); /* no return */
|
|
|
+ return zipl_run(&prog_table->entry[loadparm].scsi);
|
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
@@ -677,8 +810,10 @@ static bool is_iso_bc_entry_compatible(IsoBcSection *s)
|
|
|
if (s->unused || !s->sector_count) {
|
|
|
return false;
|
|
|
}
|
|
|
- read_iso_sector(bswap32(s->load_rba), magic_sec,
|
|
|
- "Failed to read image sector 0");
|
|
|
+ if (virtio_read(bswap32(s->load_rba), magic_sec)) {
|
|
|
+ puts("Failed to read image sector 0");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
/* Checking bytes 8 - 32 for S390 Linux magic */
|
|
|
return !memcmp(magic_sec + 8, linux_s390_magic, 24);
|
|
@@ -691,28 +826,35 @@ static uint32_t sec_offset[ISO9660_MAX_DIR_DEPTH];
|
|
|
/* Remained directory space in bytes */
|
|
|
static uint32_t dir_rem[ISO9660_MAX_DIR_DEPTH];
|
|
|
|
|
|
-static inline uint32_t iso_get_file_size(uint32_t load_rba)
|
|
|
+static inline long iso_get_file_size(uint32_t load_rba)
|
|
|
{
|
|
|
IsoVolDesc *vd = (IsoVolDesc *)sec;
|
|
|
IsoDirHdr *cur_record = &vd->vd.primary.rootdir;
|
|
|
uint8_t *temp = sec + ISO_SECTOR_SIZE;
|
|
|
int level = 0;
|
|
|
|
|
|
- read_iso_sector(ISO_PRIMARY_VD_SECTOR, sec,
|
|
|
- "Failed to read ISO primary descriptor");
|
|
|
+ if (virtio_read(ISO_PRIMARY_VD_SECTOR, sec)) {
|
|
|
+ puts("Failed to read ISO primary descriptor");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
+
|
|
|
sec_loc[0] = iso_733_to_u32(cur_record->ext_loc);
|
|
|
dir_rem[0] = 0;
|
|
|
sec_offset[0] = 0;
|
|
|
|
|
|
while (level >= 0) {
|
|
|
- IPL_assert(sec_offset[level] <= ISO_SECTOR_SIZE,
|
|
|
- "Directory tree structure violation");
|
|
|
+ if (sec_offset[level] > ISO_SECTOR_SIZE) {
|
|
|
+ puts("Directory tree structure violation");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
|
|
|
cur_record = (IsoDirHdr *)(temp + sec_offset[level]);
|
|
|
|
|
|
if (sec_offset[level] == 0) {
|
|
|
- read_iso_sector(sec_loc[level], temp,
|
|
|
- "Failed to read ISO directory");
|
|
|
+ if (virtio_read(sec_loc[level], temp)) {
|
|
|
+ puts("Failed to read ISO directory");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
if (dir_rem[level] == 0) {
|
|
|
/* Skip self and parent records */
|
|
|
dir_rem[level] = iso_733_to_u32(cur_record->data_len) -
|
|
@@ -743,7 +885,7 @@ static inline uint32_t iso_get_file_size(uint32_t load_rba)
|
|
|
if (cur_record->file_flags & 0x2) {
|
|
|
/* Subdirectory */
|
|
|
if (level == ISO9660_MAX_DIR_DEPTH - 1) {
|
|
|
- sclp_print("ISO-9660 directory depth limit exceeded\n");
|
|
|
+ puts("ISO-9660 directory depth limit exceeded");
|
|
|
} else {
|
|
|
level++;
|
|
|
sec_loc[level] = iso_733_to_u32(cur_record->ext_loc);
|
|
@@ -757,8 +899,10 @@ static inline uint32_t iso_get_file_size(uint32_t load_rba)
|
|
|
if (dir_rem[level] == 0) {
|
|
|
/* Nothing remaining */
|
|
|
level--;
|
|
|
- read_iso_sector(sec_loc[level], temp,
|
|
|
- "Failed to read ISO directory");
|
|
|
+ if (virtio_read(sec_loc[level], temp)) {
|
|
|
+ puts("Failed to read ISO directory");
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -773,19 +917,24 @@ static void load_iso_bc_entry(IsoBcSection *load)
|
|
|
* is padded and ISO_SECTOR_SIZE bytes aligned
|
|
|
*/
|
|
|
uint32_t blks_to_load = bswap16(s.sector_count) >> ET_SECTOR_SHIFT;
|
|
|
- uint32_t real_size = iso_get_file_size(bswap32(s.load_rba));
|
|
|
+ long real_size = iso_get_file_size(bswap32(s.load_rba));
|
|
|
|
|
|
- if (real_size) {
|
|
|
+ if (real_size > 0) {
|
|
|
/* Round up blocks to load */
|
|
|
blks_to_load = (real_size + ISO_SECTOR_SIZE - 1) / ISO_SECTOR_SIZE;
|
|
|
- sclp_print("ISO boot image size verified\n");
|
|
|
+ puts("ISO boot image size verified");
|
|
|
} else {
|
|
|
- sclp_print("ISO boot image size could not be verified\n");
|
|
|
+ puts("ISO boot image size could not be verified");
|
|
|
+ if (real_size < 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- read_iso_boot_image(bswap32(s.load_rba),
|
|
|
+ if (read_iso_boot_image(bswap32(s.load_rba),
|
|
|
(void *)((uint64_t)bswap16(s.load_segment)),
|
|
|
- blks_to_load);
|
|
|
+ blks_to_load)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
jump_to_low_kernel();
|
|
|
}
|
|
@@ -808,17 +957,18 @@ static uint32_t find_iso_bc(void)
|
|
|
return bswap32(et->bc_offset);
|
|
|
}
|
|
|
}
|
|
|
- read_iso_sector(block_num++, sec,
|
|
|
- "Failed to read ISO volume descriptor");
|
|
|
+ if (virtio_read(block_num++, sec)) {
|
|
|
+ puts("Failed to read ISO volume descriptor");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static IsoBcSection *find_iso_bc_entry(void)
|
|
|
+static IsoBcSection *find_iso_bc_entry(uint32_t offset)
|
|
|
{
|
|
|
IsoBcEntry *e = (IsoBcEntry *)sec;
|
|
|
- uint32_t offset = find_iso_bc();
|
|
|
int i;
|
|
|
unsigned int loadparm = get_loadparm_index();
|
|
|
|
|
@@ -826,11 +976,13 @@ static IsoBcSection *find_iso_bc_entry(void)
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
- read_iso_sector(offset, sec, "Failed to read El Torito boot catalog");
|
|
|
+ if (virtio_read(offset, sec)) {
|
|
|
+ puts("Failed to read El Torito boot catalog");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
|
|
|
if (!is_iso_bc_valid(e)) {
|
|
|
/* The validation entry is mandatory */
|
|
|
- panic("No valid boot catalog found!\n");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
@@ -850,19 +1002,25 @@ static IsoBcSection *find_iso_bc_entry(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- panic("No suitable boot entry found on ISO-9660 media!\n");
|
|
|
-
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-static void ipl_iso_el_torito(void)
|
|
|
+static int ipl_iso_el_torito(void)
|
|
|
{
|
|
|
- IsoBcSection *s = find_iso_bc_entry();
|
|
|
+ uint32_t offset = find_iso_bc();
|
|
|
+ if (!offset) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ IsoBcSection *s = find_iso_bc_entry(offset);
|
|
|
|
|
|
if (s) {
|
|
|
- load_iso_bc_entry(s);
|
|
|
- /* no return */
|
|
|
+ load_iso_bc_entry(s); /* only return in error */
|
|
|
+ return -1;
|
|
|
}
|
|
|
+
|
|
|
+ puts("No suitable boot entry found on ISO-9660 media!");
|
|
|
+ return -EIO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -884,7 +1042,7 @@ static bool has_iso_signature(void)
|
|
|
* Bus specific IPL sequences
|
|
|
*/
|
|
|
|
|
|
-static void zipl_load_vblk(void)
|
|
|
+static int zipl_load_vblk(void)
|
|
|
{
|
|
|
int blksize = virtio_get_block_size();
|
|
|
|
|
@@ -892,26 +1050,30 @@ static void zipl_load_vblk(void)
|
|
|
if (blksize != VIRTIO_ISO_BLOCK_SIZE) {
|
|
|
virtio_assume_iso9660();
|
|
|
}
|
|
|
- ipl_iso_el_torito();
|
|
|
+ if (ipl_iso_el_torito()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (blksize != VIRTIO_DASD_DEFAULT_BLOCK_SIZE) {
|
|
|
- sclp_print("Using guessed DASD geometry.\n");
|
|
|
+ puts("Using guessed DASD geometry.");
|
|
|
virtio_assume_eckd();
|
|
|
}
|
|
|
- ipl_eckd();
|
|
|
+ return ipl_eckd();
|
|
|
}
|
|
|
|
|
|
-static void zipl_load_vscsi(void)
|
|
|
+static int zipl_load_vscsi(void)
|
|
|
{
|
|
|
if (virtio_get_block_size() == VIRTIO_ISO_BLOCK_SIZE) {
|
|
|
/* Is it an ISO image in non-CD drive? */
|
|
|
- ipl_iso_el_torito();
|
|
|
+ if (ipl_iso_el_torito()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- sclp_print("Using guessed DASD geometry.\n");
|
|
|
+ puts("Using guessed DASD geometry.");
|
|
|
virtio_assume_eckd();
|
|
|
- ipl_eckd();
|
|
|
+ return ipl_eckd();
|
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
@@ -924,14 +1086,20 @@ void zipl_load(void)
|
|
|
|
|
|
if (vdev->is_cdrom) {
|
|
|
ipl_iso_el_torito();
|
|
|
- panic("\n! Cannot IPL this ISO image !\n");
|
|
|
+ puts("Failed to IPL this ISO image!");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
if (virtio_get_device_type() == VIRTIO_ID_NET) {
|
|
|
- jump_to_IPL_code(vdev->netboot_start_addr);
|
|
|
+ netmain();
|
|
|
+ puts("Failed to IPL from this network!");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- ipl_scsi();
|
|
|
+ if (ipl_scsi()) {
|
|
|
+ puts("Failed to IPL from this SCSI device!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
switch (virtio_get_device_type()) {
|
|
|
case VIRTIO_ID_BLOCK:
|
|
@@ -941,8 +1109,9 @@ void zipl_load(void)
|
|
|
zipl_load_vscsi();
|
|
|
break;
|
|
|
default:
|
|
|
- panic("\n! Unknown IPL device type !\n");
|
|
|
+ puts("Unknown IPL device type!");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- sclp_print("zIPL load failed.\n");
|
|
|
+ puts("zIPL load failed!");
|
|
|
}
|