From 9ada8332d86e1fcca95536faa293151650c1cc4f Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Wed, 18 Jan 2023 16:39:57 +0000 Subject: [PATCH] zipl: Embed loader data directly into boot object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, each generated loader binary is linked into one data.o object file which is then linked against boot.o. The data.o file is also used to generate the data.h header file using nm, which will contain all symbols required by zipl. The linking process is somewhat depended on the directory, as the symbol names are derived from the file names of the input files, which is the default behavior of the linker. The file name in this case being the entire path. Examples for the current situation (starting from root dir in each case): $ cd zipl/boot && make eckd0_cdl.bin $ cc -no-pie -static -nostdlib -Wl,--relocatable -Wl,--format,binary -o data.o eckd0_cdl.bin $ nm data.o 0000000000000018 D _binary_eckd0_cdl_bin_end 0000000000000018 A _binary_eckd0_cdl_bin_size 0000000000000000 D _binary_eckd0_cdl_bin_start $ make -C zipl/boot eckd0_cdl.bin $ cc -no-pie -static -nostdlib -Wl,--relocatable -Wl,--format,binary -o data.o zipl/boot/eckd0_cdl.bin $ nm data.o 000000000000018 D _binary_zipl_boot_eckd0_cdl_bin_end 000000000000018 A _binary_zipl_boot_eckd0_cdl_bin_size 000000000000000 D _binary_zipl_boot_eckd0_cdl_bin_start The example above shows that the entire path would end up in the symbol name if specified that way. To make this more robust, future proof, and get more control of the resulting symbol names, use '.incbin' and some macros for embedding the loader binary files. This also reduces the linker step and the generation of the data.h header file. Reviewed-by: Steffen Eiden Reviewed-by: Stefan Haberland Signed-off-by: Marc Hartmayer Co-developed-by: Jan Höppner Signed-off-by: Jan Höppner --- .gitignore | 1 + common.mak | 4 ++-- zipl/boot/Makefile | 16 ++++++---------- zipl/src/Makefile | 14 +++++--------- zipl/src/boot.c | 41 ++++++++++++++++++++++++++++++++++++++--- 5 files changed, 52 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index e1f23f24..a0b218be 100644 --- a/.gitignore +++ b/.gitignore @@ -109,6 +109,7 @@ ziomon/ziorep_traffic ziomon/ziorep_utilization zipl/boot/*.bin zipl/boot/*.exec +zipl/boot/.loaders zipl/boot/data.h zipl/src/chreipl_helper.device-mapper zdev/src/zdev_id diff --git a/common.mak b/common.mak index a863496f..269fff32 100644 --- a/common.mak +++ b/common.mak @@ -406,8 +406,8 @@ $(rootdir)/libpv/libpv.a: $(rootdir)/libpv $(MAKE) -C $(rootdir)/libpv libpv.a .PHONY: $(rootdir)/libpv -$(rootdir)/zipl/boot/data.o: - $(MAKE) -C $(rootdir)/zipl/boot/ data.o +$(rootdir)/zipl/boot/.loaders: + $(MAKE) -C $(rootdir)/zipl/boot/ .loaders install_dirs: for dir in $(INSTDIRS); do \ diff --git a/zipl/boot/Makefile b/zipl/boot/Makefile index 2bae890c..26c31586 100644 --- a/zipl/boot/Makefile +++ b/zipl/boot/Makefile @@ -19,7 +19,10 @@ FILES = fba0.bin fba1b.bin fba2.bin \ tape0.bin \ eckd2dump_sv.bin tape2dump.bin fba2dump.bin eckd2dump_mv.bin -all: data.o data.h tape0.bin stage3.bin +all: .loaders tape0.bin stage3.bin + +.loaders: $(FILES) + touch .loaders # Prevent make from using some default rules... %: %.S @@ -75,16 +78,9 @@ stage3.exec: head.o stage3.o kdump3.o libc.o ebcdic.o ebcdic_conv.o sclp.o \ %.bin: %.exec $(OBJCOPY) -O binary $< $@ -data.o: $(FILES) - $(LINK) $(NO_PIE_LDFLAGS) -static -nostdlib -Wl,--relocatable -Wl,--format,binary -o data.o $(FILES) - -data.h: data.o - rm -f data.h - $(NM) data.o | while read ADDR TYPE SYMBOL ; do \ - echo "extern char $$SYMBOL;" >>data.h; done clean: - rm -f -- *.o *.exec *.bin $(FILES) data.o data.h tape0.bin *.xxx *.yyy \ - stage3.bin *.lds .*.lds.d + rm -f -- *.o *.exec *.bin $(FILES) tape0.bin *.xxx *.yyy \ + stage3.bin *.lds .*.lds.d .loaders .PHONY: all clean diff --git a/zipl/src/Makefile b/zipl/src/Makefile index 64eabe40..cab56557 100644 --- a/zipl/src/Makefile +++ b/zipl/src/Makefile @@ -4,14 +4,14 @@ include ../../common.mak ALL_CPPFLAGS += -I../include -I../boot \ -DZFCPDUMP_IMAGE="STRINGIFY($(ZFCPDUMP_DIR)/$(ZFCPDUMP_IMAGE))" \ -DZFCPDUMP_INITRD="STRINGIFY($(ZFCPDUMP_DIR)/$(ZFCPDUMP_INITRD))" \ - -D_FILE_OFFSET_BITS=64 $(NO_PIE_CFLAGS) + -D_FILE_OFFSET_BITS=64 $(NO_PIE_CFLAGS) -DBUILD_PATH="../boot" ALL_LDFLAGS += -Wl,-z,noexecstack $(NO_PIE_LDFLAGS) libs = $(rootdir)/libutil/libutil.a \ $(rootdir)/libvtoc/libvtoc.a \ objects = misc.o error.o scan.o job.o boot.o bootmap.o fs-map.o disk.o \ - bootmap_header.o envblk.o install.o zipl.o $(rootdir)/zipl/boot/data.o + bootmap_header.o envblk.o install.o zipl.o zipl_helpers = $(basename $(wildcard zipl_helper.*.c)) chreipl_helpers = $(subst zipl_,chreipl_, $(zipl_helpers)) @@ -19,6 +19,7 @@ zipl_stage3 = ../boot/stage3.bin all: zipl zipl-editenv $(chreipl_helpers) $(zipl_stage3) +boot.o: ../boot/.loaders zipl: $(objects) $(libs) zipl_helper.device-mapper: $(rootdir)/libdasd/libdasd.a \ @@ -47,13 +48,8 @@ clean: # Additional manual dependencies -.boot.o.d boot.o: ../boot/data.h - -../boot/data.h: - $(MAKE) -C ../boot data.h - -../boot/data.o: - $(MAKE) -C ../boot data.o +../boot/.loaders: + $(MAKE) -C ../boot .loaders ../boot/stage3.bin: $(MAKE) -C ../boot stage3.bin diff --git a/zipl/src/boot.c b/zipl/src/boot.c index bbfefcbc..3aebe168 100644 --- a/zipl/src/boot.c +++ b/zipl/src/boot.c @@ -21,14 +21,49 @@ #include "stage3.h" -#include "../boot/data.h" #include "boot.h" #include "bootmap.h" #include "error.h" #include "misc.h" -#define DATA_SIZE(x) ((size_t) (&_binary_##x##_bin_end - &_binary_##x##_bin_start)) -#define DATA_ADDR(x) (&_binary_##x##_bin_start) +/* Import a binary file */ +/* clang-format off */ +#define DATA_NAME(SYM, SUFFIX) _binary_##SYM##_bin##SUFFIX +#define DATA_SIZE(SYM) ((size_t)(&DATA_NAME(SYM, _end) - &DATA_NAME(SYM, _start))) +#define DATA_ADDR(SYM) (&DATA_NAME(SYM, _start)) +#define BIN_FILE_PATH(FILE_NAME) STRINGIFY(BUILD_PATH) "/" STRINGIFY(FILE_NAME) ".bin" +#define IMPORT_DATA(SYM) \ + extern const uint8_t DATA_NAME(SYM, _start); \ + extern const uint8_t DATA_NAME(SYM, _end); \ + asm(".section \".rodata\", \"a\", @progbits\n" \ + ".balign 4\n" \ + ".global " STRINGIFY(DATA_NAME(SYM, _start)) "\n" \ + STRINGIFY(DATA_NAME(SYM, _start)) ":\n" \ + ".incbin \"" BIN_FILE_PATH(SYM) "\"\n" \ + ".global " STRINGIFY(DATA_NAME(SYM, _end)) "\n" \ + STRINGIFY(DATA_NAME(SYM, _end)) ":\n" \ + ".balign 4\n" \ + ".previous\n") +/* clang-format on */ + +/* Stage 0 Loader */ +IMPORT_DATA(eckd0_cdl); +IMPORT_DATA(eckd0_ldl); +IMPORT_DATA(fba0); +IMPORT_DATA(tape0); +/* Stage 1 Loader */ +IMPORT_DATA(eckd1); +/* Stage 1b Loader */ +IMPORT_DATA(eckd1b); +IMPORT_DATA(fba1b); +/* Stage 2 Loader */ +IMPORT_DATA(eckd2); +IMPORT_DATA(fba2); +/* Stage 2 Dump Loader */ +IMPORT_DATA(eckd2dump_mv); +IMPORT_DATA(eckd2dump_sv); +IMPORT_DATA(fba2dump); +IMPORT_DATA(tape2dump); #define CCW_FLAG_CC 0x40 #define CCW_FLAG_SLI 0x20