From 917d61188391338acde3ffc4c6761e0fef0d6598 Mon Sep 17 00:00:00 2001 From: Eduard Shishkin Date: Fri, 17 Mar 2023 16:23:41 +0100 Subject: [PATCH] zipl: add/move some definitions to header files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the listed changes which are needed to re-use some definitions by the new zipl-debug(8) tool introduced by the next patch in the series: . Add definitions to boot_defs.h: . a named union disk_bloclkptr (instead of the anonymous one); . a named structure disk_program_table; . Remove a 'typedef union disk_blockptr_t' from boot/stage2.h (cleanup), use the named union in boot_defs.h instead; . Move the definition of scsi_layout types and the function get_scsi_layout() from install.c to install.h; . Move definition of PROGRAM_TABLE_BLOCK_SIZE from bootmap.c to bootmap.h Signed-off-by: Eduard Shishkin Reviewed-by: Stefan Haberland Signed-off-by: Jan Höppner --- include/boot/boot_defs.h | 20 +++++++++++++++----- zipl/boot/eckd2.c | 6 +++--- zipl/boot/fba2.c | 2 +- zipl/boot/stage2.c | 17 ++++++++--------- zipl/boot/stage2.h | 8 ++------ zipl/include/bootmap.h | 1 + zipl/include/disk.h | 2 +- zipl/include/install.h | 21 +++++++++++++++++++++ zipl/src/bootmap.c | 2 -- zipl/src/install.c | 23 ----------------------- 10 files changed, 52 insertions(+), 50 deletions(-) diff --git a/include/boot/boot_defs.h b/include/boot/boot_defs.h index 2b39b417..8fdd569f 100644 --- a/include/boot/boot_defs.h +++ b/include/boot/boot_defs.h @@ -195,15 +195,25 @@ struct boot_info_bp_dump { uint8_t unused[16]; } __packed; +/* This represents on-disk pointer to a block on disk */ +union disk_blockptr { + struct eckd_blockptr_legacy eckd_legacy; + struct eckd_blockptr eckd; + struct linear_blockptr linear; +}; + struct boot_info_bp_ipl { - union { - struct eckd_blockptr_legacy eckd_legacy; - struct eckd_blockptr eckd; - struct linear_blockptr lin; - } bm_ptr; + union disk_blockptr bm_ptr; uint8_t unused[16]; } __packed; +struct disk_program_table { + uint32_t magic; + uint32_t version; + uint64_t unused; + union disk_blockptr component_table[0]; +} __packed; + struct boot_info { char magic[4]; uint8_t version; diff --git a/zipl/boot/eckd2.c b/zipl/boot/eckd2.c index ae598aec..4c4872c0 100644 --- a/zipl/boot/eckd2.c +++ b/zipl/boot/eckd2.c @@ -29,10 +29,10 @@ int is_zero_block(void *data) return blockptr->cyl || blockptr->head || blockptr->sec; } -void * load_direct(disk_blockptr_t *data, struct subchannel_id subchannel_id, - void *load_addr) +void *load_direct(union disk_blockptr *data, struct subchannel_id subchannel_id, + void *load_addr) { - struct eckd_blockptr_legacy *blockptr = &data->eckd; + struct eckd_blockptr_legacy *blockptr = &data->eckd_legacy; struct ccw1 *ccws; unsigned long record_size; struct seek_arg seek_addr; diff --git a/zipl/boot/fba2.c b/zipl/boot/fba2.c index 7842b57c..1024f1ec 100644 --- a/zipl/boot/fba2.c +++ b/zipl/boot/fba2.c @@ -25,7 +25,7 @@ int is_zero_block(void *data) { return blockptr->blockno; } -void *load_direct(disk_blockptr_t *data, struct subchannel_id subchannel_id, +void *load_direct(union disk_blockptr *data, struct subchannel_id subchannel_id, void *load_addr) { struct linear_blockptr *blockptr = &data->linear; diff --git a/zipl/boot/stage2.c b/zipl/boot/stage2.c index 9fefee6f..ecfbd6aa 100644 --- a/zipl/boot/stage2.c +++ b/zipl/boot/stage2.c @@ -18,7 +18,7 @@ #include "boot/loaders_layout.h" #include "stage2.h" -static int is_null_descriptor(disk_blockptr_t *address) +static int is_null_descriptor(union disk_blockptr *address) { unsigned long long *value = (unsigned long long *)address; @@ -28,13 +28,12 @@ static int is_null_descriptor(disk_blockptr_t *address) static void *load_blocklist(struct component_entry *descriptor_address, struct subchannel_id subchannel_id, void *load_address) { - disk_blockptr_t *indirect_blocks, *indirect_blockspace, - *start_addr; + union disk_blockptr *indirect_blocks, *indirect_blockspace, *start_addr; unsigned long length; long long nr_descr; /* start address to load first indirect blocks */ - start_addr = (disk_blockptr_t *)&descriptor_address->data; + start_addr = (union disk_blockptr *)&descriptor_address->data; /* get a free page to store indirect blocks in */ indirect_blockspace = (void *)get_zeroed_page(); @@ -90,7 +89,7 @@ void __noreturn start(void) struct subchannel_id subchannel_id; void *load_address; struct component_entry *entry; - disk_blockptr_t *blockptr; + union disk_blockptr *blockptr; uint64_t load_psw; void *load_page; int config_nr; @@ -106,14 +105,14 @@ void __noreturn start(void) set_device(subchannel_id, ENABLED); load_page = (void *)get_zeroed_page(); - load_address = (disk_blockptr_t *) load_page; + load_address = (union disk_blockptr *) load_page; /* load blockpointer list to load address */ - load_direct((disk_blockptr_t *)&stage2_descr, subchannel_id, + load_direct((union disk_blockptr *)&stage2_descr, subchannel_id, load_address); - blockptr = (disk_blockptr_t *)(load_address + - sizeof(disk_blockptr_t)); + blockptr = (union disk_blockptr *)(load_address + + sizeof(union disk_blockptr)); load_direct(&blockptr[config_nr], subchannel_id, load_address); diff --git a/zipl/boot/stage2.h b/zipl/boot/stage2.h index 786002c8..d1fbf70e 100644 --- a/zipl/boot/stage2.h +++ b/zipl/boot/stage2.h @@ -26,16 +26,12 @@ #include "cio.h" #include "error.h" -typedef union { - struct eckd_blockptr_legacy eckd; - struct linear_blockptr linear; -} disk_blockptr_t; - struct stage2_descr { uint8_t reserved[16]; } __packed __aligned(8); -void *load_direct(disk_blockptr_t *, struct subchannel_id , void *); +void *load_direct(union disk_blockptr *data, struct subchannel_id sid, + void *load_addr); int extract_length(void *); int is_zero_block(void *); void kdump_stage2(unsigned long); diff --git a/zipl/include/bootmap.h b/zipl/include/bootmap.h index c1c921a3..d9050a34 100644 --- a/zipl/include/bootmap.h +++ b/zipl/include/bootmap.h @@ -21,6 +21,7 @@ #define BOOTMAP_HEADER_VERSION 1 +#define PROGRAM_TABLE_BLOCK_SIZE 512 #define SIGNATURE_MAGIC "~Module signature appended~\n" #define PKCS7_FORMAT 0x01 diff --git a/zipl/include/disk.h b/zipl/include/disk.h index d689c766..0eb19958 100644 --- a/zipl/include/disk.h +++ b/zipl/include/disk.h @@ -38,7 +38,7 @@ struct disk_blockptr_linear { int blockct; }; -/* Pointer to a block on disk */ +/* This represents in-memory pointer to a block on disk */ typedef union { struct disk_blockptr_chs chs; struct disk_blockptr_linear linear; diff --git a/zipl/include/install.h b/zipl/include/install.h index d2135548..69fb1a3c 100644 --- a/zipl/include/install.h +++ b/zipl/include/install.h @@ -35,6 +35,14 @@ enum program_component_id { NR_PROGRAM_COMPONENTS }; +/* Types of SCSI disk layouts */ +enum scsi_layout { + scsi_layout_pcbios, + scsi_layout_sun, + scsi_layout_sgi, + scsi_layout_unknown +}; + struct component_loc { address_t addr; size_t size; @@ -76,6 +84,19 @@ struct install_set { extern struct component_footer component_footers[NR_PROGRAM_COMPONENTS]; +/* Determine SCSI disk layout from the specified BOOTBLOCK. */ +static inline enum scsi_layout get_scsi_layout(unsigned char *bootblock) +{ + if ((bootblock[510] == 0x55) && (bootblock[511] == 0xaa)) + return scsi_layout_pcbios; + else if ((bootblock[508] == 0xda) && (bootblock[509] == 0xbe)) + return scsi_layout_sun; + else if ((bootblock[0] == 0x0b) && (bootblock[1] == 0xe5) && + (bootblock[2] == 0xa9) && (bootblock[3] == 0x41)) + return scsi_layout_sgi; + return scsi_layout_unknown; +} + static inline component_type component_type_by_id(enum program_component_id id) { return component_footers[id].type; diff --git a/zipl/src/bootmap.c b/zipl/src/bootmap.c index 0da5cbe5..1e18ecbf 100644 --- a/zipl/src/bootmap.c +++ b/zipl/src/bootmap.c @@ -119,8 +119,6 @@ void bootmap_store_blockptr(void *buffer, disk_blockptr_t *ptr, } } -#define PROGRAM_TABLE_BLOCK_SIZE 512 - /* Calculate the maximum number of entries in the program table. INFO * specifies the type of disk. */ static int diff --git a/zipl/src/install.c b/zipl/src/install.c index 5241380f..3e2545da 100644 --- a/zipl/src/install.c +++ b/zipl/src/install.c @@ -45,32 +45,9 @@ static inline unsigned long blk_cnt(int size, struct disk_info *info) return (size + info->phy_block_size - 1) / info->phy_block_size; } -/* Types of SCSI disk layouts */ -enum scsi_layout { - scsi_layout_pcbios, - scsi_layout_sun, - scsi_layout_sgi, - scsi_layout_unknown -}; - /* From linux/fs.h */ #define BLKFLSBUF _IO(0x12, 97) - -/* Determine SCSI disk layout from the specified BOOTBLOCK. */ -static enum scsi_layout -get_scsi_layout(unsigned char* bootblock) -{ - if ((bootblock[510] == 0x55) && (bootblock[511] == 0xaa)) - return scsi_layout_pcbios; - else if ((bootblock[508] == 0xda) && (bootblock[509] == 0xbe)) - return scsi_layout_sun; - else if ((bootblock[0] == 0x0b) && (bootblock[1] == 0xe5) && - (bootblock[2] == 0xa9) && (bootblock[3] == 0x41)) - return scsi_layout_sgi; - return scsi_layout_unknown; -} - static int overwrite_partition_start(int fd, struct disk_info* info, int mv_dump_magic);