pc-bios/s390-ccw: Unify error handling

Convert to IPL_assert and friends

Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Eugene (jno) Dvurechenski <jno@linux.vnet.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
This commit is contained in:
Eugene (jno) Dvurechenski 2014-05-19 20:11:07 +02:00 committed by Cornelia Huck
parent a94b485e17
commit 60612d5cbb
3 changed files with 31 additions and 66 deletions

View File

@ -86,7 +86,7 @@ static int zipl_magic(uint8_t *ptr)
return 1; return 1;
} }
static int zipl_load_segment(ComponentEntry *entry) static void zipl_load_segment(ComponentEntry *entry)
{ {
const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr)); const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));
ScsiBlockPtr *bprs = (void *)sec; ScsiBlockPtr *bprs = (void *)sec;
@ -103,10 +103,8 @@ static int zipl_load_segment(ComponentEntry *entry)
do { do {
memset(bprs, FREE_SPACE_FILLER, bprs_size); memset(bprs, FREE_SPACE_FILLER, bprs_size);
if (virtio_read(blockno, (uint8_t *)bprs)) { debug_print_int("reading bprs at", blockno);
debug_print_int("failed reading bprs at", blockno); read_block(blockno, bprs, "zipl_load_segment: cannot read block");
goto fail;
}
for (i = 0;; i++) { for (i = 0;; i++) {
u64 *cur_desc = (void *)&bprs[i]; u64 *cur_desc = (void *)&bprs[i];
@ -134,21 +132,13 @@ static int zipl_load_segment(ComponentEntry *entry)
} }
address = virtio_load_direct(cur_desc[0], cur_desc[1], 0, address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
(void *)address); (void *)address);
if (address == -1) { IPL_assert(address != -1, "zipl_load_segment: wrong IPL address");
goto fail;
}
} }
} while (blockno); } while (blockno);
return 0;
fail:
sclp_print("failed loading segment\n");
return -1;
} }
/* Run a zipl program */ /* Run a zipl program */
static int zipl_run(ScsiBlockPtr *pte) static void zipl_run(ScsiBlockPtr *pte)
{ {
ComponentHeader *header; ComponentHeader *header;
ComponentEntry *entry; ComponentEntry *entry;
@ -157,75 +147,53 @@ static int zipl_run(ScsiBlockPtr *pte)
virtio_read(pte->blockno, tmp_sec); virtio_read(pte->blockno, tmp_sec);
header = (ComponentHeader *)tmp_sec; header = (ComponentHeader *)tmp_sec;
if (!zipl_magic(tmp_sec)) { IPL_assert(zipl_magic(tmp_sec), "zipl_run: zipl_magic");
goto fail;
}
if (header->type != ZIPL_COMP_HEADER_IPL) { IPL_assert(header->type == ZIPL_COMP_HEADER_IPL,
goto fail; "zipl_run: wrong header type");
}
dputs("start loading images\n"); dputs("start loading images\n");
/* Load image(s) into RAM */ /* Load image(s) into RAM */
entry = (ComponentEntry *)(&header[1]); entry = (ComponentEntry *)(&header[1]);
while (entry->component_type == ZIPL_COMP_ENTRY_LOAD) { while (entry->component_type == ZIPL_COMP_ENTRY_LOAD) {
if (zipl_load_segment(entry) < 0) { zipl_load_segment(entry);
goto fail;
}
entry++; entry++;
if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) { IPL_assert((uint8_t *)(&entry[1]) <= (tmp_sec + MAX_SECTOR_SIZE),
goto fail; "zipl_run: wrong entry size");
}
} }
if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) { IPL_assert(entry->component_type == ZIPL_COMP_ENTRY_EXEC,
goto fail; "zipl_run: no EXEC entry");
}
/* should not return */ /* should not return */
jump_to_IPL_code(entry->load_address); jump_to_IPL_code(entry->load_address);
return 0;
fail:
sclp_print("failed running zipl\n");
return -1;
} }
int zipl_load(void) void zipl_load(void)
{ {
ScsiMbr *mbr = (void *)sec; ScsiMbr *mbr = (void *)sec;
uint8_t *ns, *ns_end; uint8_t *ns, *ns_end;
int program_table_entries = 0; int program_table_entries = 0;
const int pte_len = sizeof(ScsiBlockPtr); const int pte_len = sizeof(ScsiBlockPtr);
ScsiBlockPtr *prog_table_entry; ScsiBlockPtr *prog_table_entry;
const char *error = "";
/* Grab the MBR */ /* Grab the MBR */
virtio_read(0, (void *)mbr); read_block(0, mbr, "zipl_load: cannot read block 0");
dputs("checking magic\n"); dputs("checking magic\n");
if (!zipl_magic(mbr->magic)) { IPL_assert(zipl_magic(mbr->magic), "zipl_load: zipl_magic 1");
error = "zipl_magic 1";
goto fail;
}
debug_print_int("program table", mbr->blockptr.blockno); debug_print_int("program table", mbr->blockptr.blockno);
/* Parse the program table */ /* Parse the program table */
if (virtio_read(mbr->blockptr.blockno, sec)) { read_block(mbr->blockptr.blockno, sec,
error = "virtio_read"; "zipl_load: cannot read program table");
goto fail;
}
if (!zipl_magic(sec)) { IPL_assert(zipl_magic(sec), "zipl_load: zipl_magic 2");
error = "zipl_magic 2";
goto fail;
}
ns_end = sec + virtio_get_block_size(); ns_end = sec + virtio_get_block_size();
for (ns = (sec + pte_len); (ns + pte_len) < ns_end; ns++) { for (ns = (sec + pte_len); (ns + pte_len) < ns_end; ns++) {
@ -239,19 +207,11 @@ int zipl_load(void)
debug_print_int("program table entries", program_table_entries); debug_print_int("program table entries", program_table_entries);
if (!program_table_entries) { IPL_assert(program_table_entries, "zipl_load: no program table");
goto fail;
}
/* Run the default entry */ /* Run the default entry */
prog_table_entry = (ScsiBlockPtr *)(sec + pte_len); prog_table_entry = (ScsiBlockPtr *)(sec + pte_len);
return zipl_run(prog_table_entry); zipl_run(prog_table_entry); /* no return */
fail:
sclp_print("failed loading zipl: ");
sclp_print(error);
sclp_print("\n");
return -1;
} }

View File

@ -9,6 +9,7 @@
*/ */
#include "s390-ccw.h" #include "s390-ccw.h"
#include "virtio.h"
char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE))); char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE)));
uint64_t boot_value; uint64_t boot_value;
@ -64,6 +65,10 @@ static void virtio_setup(uint64_t dev_info)
} }
virtio_setup_block(blk_schid); virtio_setup_block(blk_schid);
if (!virtio_ipl_disk_is_valid()) {
virtio_panic("No valid hard disk detected.\n");
}
} }
int main(void) int main(void)
@ -72,8 +77,8 @@ int main(void)
debug_print_int("boot reg[7] ", boot_value); debug_print_int("boot reg[7] ", boot_value);
virtio_setup(boot_value); virtio_setup(boot_value);
if (zipl_load() < 0) zipl_load(); /* no return */
sclp_print("Failed to load OS from hard disk\n");
disabled_wait(); virtio_panic("Failed to load OS from hard disk\n");
while (1) { } return 0; /* make compiler happy */
} }

View File

@ -64,7 +64,7 @@ int virtio_read(ulong sector, void *load_addr);
int enable_mss_facility(void); int enable_mss_facility(void);
/* bootmap.c */ /* bootmap.c */
int zipl_load(void); void zipl_load(void);
static inline void *memset(void *s, int c, size_t n) static inline void *memset(void *s, int c, size_t n)
{ {