Skip to contentSkip to conversation

pxelinux.cfg-style booting for the s390x bios

GIT PULL Thomas Huth 1 participant 8 messages Jun 14, 2018

lore
Share & tools
lore
#0 lore raw

This PULL request is not for master.

Hi Cornelia,

the following changes since commit f0b9be93001e6215dc1195f3d75ad2da8b3b694a:

s390x/cpumodels: add z14 Model ZR1 (2018-06-13 13:36:19 +0200)

are available in the git repository at:

https://gitlab.com/huth/qemu.git tags/s390x-2018-06-14

for you to fetch changes up to 298d87666ddaf329326f7ed351a2d407f06d8b1a:

pc-bios/s390-ccw: Update the s390-netboot.img binary (2018-06-14 16:13:49 +0200)

------------------------------------------------------------------------
Add support for pxelinux.cfg-style network booting to the s390x firmware
------------------------------------------------------------------------

Collin Walling (1):
pc-bios/s390-ccw: define loadparm length

Thomas Huth (6):
roms: Update SLOF submodule to current status pc-bios/s390-ccw/net: Update code for the latest changes in SLOF pc-bios/s390-ccw/net: Add support for pxelinux-style config files pc-bios/s390-ccw/net: Try to load pxelinux.cfg file accoring to the UUID pc-bios/s390-ccw: Optimize the s390-netboot.img for size pc-bios/s390-ccw: Update the s390-netboot.img binary

 pc-bios/s390-ccw/Makefile    |   1 +
 pc-bios/s390-ccw/iplb.h      |   4 +-
 pc-bios/s390-ccw/main.c      |   8 +-
 pc-bios/s390-ccw/netboot.mak |  13 +--
 pc-bios/s390-ccw/netmain.c   | 226 +++++++++++++++++++++++++++++--------------
 pc-bios/s390-ccw/sclp.c      |   2 +-
 pc-bios/s390-ccw/sclp.h      |   2 +-
 pc-bios/s390-netboot.img     | Bin 87872 -> 54944 bytes
 roms/SLOF                    |   2 +-
 9 files changed, 174 insertions(+), 84 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

[Qemu-devel] [PULL SUBSYSTEM s390x 1/7] pc-bios/s390-ccw: define loadparm length

From: Collin Walling <[email protected]>

Loadparm is defined by the s390 architecture to be 8 bytes in length. Let's define this size in the s390-ccw bios.

---
 pc-bios/s390-ccw/iplb.h | 4 +++-
 pc-bios/s390-ccw/main.c | 8 ++++----
 pc-bios/s390-ccw/sclp.c | 2 +-
 pc-bios/s390-ccw/sclp.h | 2 +-
 4 files changed, 9 insertions(+), 7 deletions(-)
pc-bios/s390-ccw/iplb.h +3 -1
index ded20c8..772d5c5 100644
@@ -12,6 +12,8 @@
 #ifndef IPLB_H
 #define IPLB_H
 
+#define LOADPARM_LEN    8
+
 struct IplBlockCcw {
     uint8_t  reserved0[85];
     uint8_t  ssid;
@@ -61,7 +63,7 @@ struct IplParameterBlock {
     uint8_t  pbt;
     uint8_t  flags;
     uint16_t reserved01;
-    uint8_t  loadparm[8];
+    uint8_t  loadparm[LOADPARM_LEN];
     union {
         IplBlockCcw ccw;
         IplBlockFcp fcp;
pc-bios/s390-ccw/main.c +4 -4
index 26f9adf..544851d 100644
@@ -15,7 +15,7 @@
 char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE)));
 static SubChannelId blk_schid = { .one = 1 };
 IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
-static char loadparm_str[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+static char loadparm_str[LOADPARM_LEN + 1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 QemuIplParameters qipl;
 
 #define LOADPARM_PROMPT "PROMPT  "
@@ -80,13 +80,13 @@ static bool find_dev(Schib *schib, int dev_no)
 
 static void menu_setup(void)
 {
-    if (memcmp(loadparm_str, LOADPARM_PROMPT, 8) == 0) {
+    if (memcmp(loadparm_str, LOADPARM_PROMPT, LOADPARM_LEN) == 0) {
         menu_set_parms(QIPL_FLAG_BM_OPTS_CMD, 0);
         return;
     }
 
     /* If loadparm was set to any other value, then do not enable menu */
-    if (memcmp(loadparm_str, LOADPARM_EMPTY, 8) != 0) {
+    if (memcmp(loadparm_str, LOADPARM_EMPTY, LOADPARM_LEN) != 0) {
         return;
     }
 
@@ -117,7 +117,7 @@ static void virtio_setup(void)
     enable_mss_facility();
 
     sclp_get_loadparm_ascii(loadparm_str);
-    memcpy(ldp + 10, loadparm_str, 8);
+    memcpy(ldp + 10, loadparm_str, LOADPARM_LEN);
     sclp_print(ldp);
 
     memcpy(&qipl, early_qipl, sizeof(QemuIplParameters));
pc-bios/s390-ccw/sclp.c +1 -1
index 3836cb4..c0223fa 100644
@@ -114,7 +114,7 @@ void sclp_get_loadparm_ascii(char *loadparm)
     memset((char *)_sccb, 0, sizeof(ReadInfo));
     sccb->h.length = sizeof(ReadInfo);
     if (!sclp_service_call(SCLP_CMDW_READ_SCP_INFO, sccb)) {
-        ebcdic_to_ascii((char *) sccb->loadparm, loadparm, 8);
+        ebcdic_to_ascii((char *) sccb->loadparm, loadparm, LOADPARM_LEN);
     }
 }
 
pc-bios/s390-ccw/sclp.h +1 -1
index 0dd987f..8450161 100644
@@ -56,7 +56,7 @@ typedef struct ReadInfo {
     uint16_t rnmax;
     uint8_t rnsize;
     uint8_t reserved[13];
-    uint8_t loadparm[8];
+    uint8_t loadparm[LOADPARM_LEN];
 } __attribute__((packed)) ReadInfo;
 
 typedef struct SCCB {
Signature · 1 line
1.8.3.1
#2 lore raw

[Qemu-devel] [PULL SUBSYSTEM s390x 2/7] roms: Update SLOF submodule to current status

In reply to Thomas Huth

We need the latest version of SLOF's libnet for adding pxelinux.cfg support in the s390-ccw bios, too.

---
 roms/SLOF | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
roms/SLOF +1 -1
index fa98132..2317427 160000
@@ -1 +1 @@
-Subproject commit fa981320a1e0968d6fc1b8de319723ff8212b337
+Subproject commit 2317427ce76006723f7ae103a6998ab41dd79c68
Signature · 1 line
1.8.3.1
#3 lore raw

[Qemu-devel] [PULL SUBSYSTEM s390x 3/7] pc-bios/s390-ccw/net: Update code for the latest changes in SLOF

In reply to Thomas Huth

The ip_version information now has to be stored in the filename_ip_t structure, and there is now a common function called tftp_get_error_info() which can be used to get the error string for a TFTP error code. We can also get rid of some superfluous "(char *)" casts now.

---
 pc-bios/s390-ccw/netboot.mak |  2 +-
 pc-bios/s390-ccw/netmain.c   | 86 +++++++++-----------------------------------
 2 files changed, 18 insertions(+), 70 deletions(-)
pc-bios/s390-ccw/netboot.mak +1 -1
index 4f64128..a73be36 100644
@@ -34,7 +34,7 @@ STDLIB_OBJS = atoi.o atol.o strtoul.o strtol.o rand.o malloc.o free.o
 %.o : $(SLOF_DIR)/lib/libc/stdlib/%.c
 	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
 
-STDIO_OBJS = sprintf.o vfprintf.o vsnprintf.o vsprintf.o fprintf.o \
+STDIO_OBJS = sprintf.o snprintf.o vfprintf.o vsnprintf.o vsprintf.o fprintf.o \
 	     printf.o putc.o puts.o putchar.o stdchnls.o fileno.o
 %.o : $(SLOF_DIR)/lib/libc/stdio/%.c
 	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
pc-bios/s390-ccw/netmain.c +17 -69

159 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#4 lore raw

[Qemu-devel] [PULL SUBSYSTEM s390x 4/7] pc-bios/s390-ccw/net: Add support for pxelinux-style config files

In reply to Thomas Huth

Since it is quite cumbersome to manually create a combined kernel with initrd image for network booting, we now support loading via pxelinux configuration files, too. In these files, the kernel, initrd and command line parameters can be specified seperately, and the firmware then takes care of glueing everything together in memory after the files have been downloaded. See this URL for details about the config file layout:
https://www.syslinux.org/wiki/index.php?title=PXELINUX

The user can either specify a config file directly as bootfile via DHCP (but in this case, the file has to start either with "default" or a "#" comment so we can distinguish it from binary kernels), or a folder (i.e. the bootfile name must end with "/") where the firmware should look for the typical pxelinux.cfg file names, e.g. based on MAC or IP address. We also support the pxelinux.cfg DHCP options 209 and 210 from RFC 5071.

---
 pc-bios/s390-ccw/netboot.mak |  7 ++--
 pc-bios/s390-ccw/netmain.c   | 86 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 89 insertions(+), 4 deletions(-)
pc-bios/s390-ccw/netboot.mak +4 -3
index a73be36..8af0cfd 100644
@@ -25,8 +25,9 @@ CTYPE_OBJS = isdigit.o isxdigit.o toupper.o
 %.o : $(SLOF_DIR)/lib/libc/ctype/%.c
 	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
 
-STRING_OBJS = strcat.o strchr.o strcmp.o strcpy.o strlen.o strncmp.o strncpy.o \
-	      strstr.o memset.o memcpy.o memmove.o memcmp.o
+STRING_OBJS = strcat.o strchr.o strrchr.o strcpy.o strlen.o strncpy.o \
+	      strcmp.o strncmp.o strcasecmp.o strncasecmp.o strstr.o \
+	      memset.o memcpy.o memmove.o memcmp.o
 %.o : $(SLOF_DIR)/lib/libc/string/%.c
 	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
 
@@ -50,7 +51,7 @@ libc.a: $(LIBCOBJS)
 # libnet files:
 
 LIBNETOBJS := args.o dhcp.o dns.o icmpv6.o ipv6.o tcp.o udp.o bootp.o \
-	      dhcpv6.o ethernet.o ipv4.o ndp.o tftp.o
+	      dhcpv6.o ethernet.o ipv4.o ndp.o tftp.o pxelinux.o
 LIBNETCFLAGS := $(QEMU_CFLAGS) -DDHCPARCH=0x1F $(LIBC_INC) $(LIBNET_INC)
 
 %.o : $(SLOF_DIR)/lib/libnet/%.c
pc-bios/s390-ccw/netmain.c +85 -1

128 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

[Qemu-devel] [PULL SUBSYSTEM s390x 5/7] pc-bios/s390-ccw/net: Try to load pxelinux.cfg file accoring to the UUID

In reply to Thomas Huth

With the STSI instruction, we can get the UUID of the current VM instance, so we can support loading pxelinux config files via UUID in the file name, too.

---
 pc-bios/s390-ccw/netmain.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)
pc-bios/s390-ccw/netmain.c +55 -1
index c059546..0392131 100644
@@ -44,6 +44,9 @@ extern char _start[];
 #define KERNEL_MAX_SIZE         ((long)_start)
 #define ARCH_COMMAND_LINE_SIZE  896              /* Taken from Linux kernel */
 
+/* STSI 3.2.2 offset of first vmdb + offset of uuid inside vmdb */
+#define STSI322_VMDB_UUID_OFFSET ((8 + 12) * 4)
+
 char stack[PAGE_SIZE * 8] __attribute__((aligned(PAGE_SIZE)));
 IplParameterBlock iplb __attribute__((aligned(PAGE_SIZE)));
 static char cfgbuf[2048];
@@ -236,6 +239,56 @@ static void net_release(filename_ip_t *fn_ip)
 }
 
 /**
+ * Retrieve the Universally Unique Identifier of the VM.
+ * @return UUID string, or NULL in case of errors
+ */
+static const char *get_uuid(void)
+{
+    register int r0 asm("0");
+    register int r1 asm("1");
+    uint8_t *mem, *buf, uuid[16];
+    int i, cc, chk = 0;
+    static char uuid_str[37];
+
+    mem = malloc(2 * PAGE_SIZE);
+    if (!mem) {
+        puts("Out of memory ... can not get UUID.");
+        return NULL;
+    }
+    buf = (uint8_t *)(((uint64_t)mem + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1));
+    memset(buf, 0, PAGE_SIZE);
+
+    /* Get SYSIB 3.2.2 */
+    r0 = (3 << 28) | 2;
+    r1 = 2;
+    asm volatile(" stsi 0(%[addr])\n"
+                 " ipm  %[cc]\n"
+                 " srl  %[cc],28\n"
+                 : [cc] "=d" (cc)
+                 : "d" (r0), "d" (r1), [addr] "a" (buf)
+                 : "cc", "memory");
+    if (cc) {
+        return NULL;
+    }
+
+    for (i = 0; i < 16; i++) {
+        uuid[i] = buf[STSI322_VMDB_UUID_OFFSET + i];
+        chk |= uuid[i];
+    }
+    free(mem);
+    if (!chk) {
+        return NULL;
+    }
+
+    sprintf(uuid_str, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
+            "%02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3],
+            uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10],
+            uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
+
+    return uuid_str;
+}
+
+/**
  * Load a kernel with initrd (i.e. with the information that we've got from
  * a pxelinux.cfg config file)
  */
@@ -285,7 +338,8 @@ static int net_try_pxelinux_cfg(filename_ip_t *fn_ip)
     struct pl_cfg_entry entries[MAX_PXELINUX_ENTRIES];
     int num_ent, def_ent = 0;
 
-    num_ent = pxelinux_load_parse_cfg(fn_ip, mac, NULL, DEFAULT_TFTP_RETRIES,
+    num_ent = pxelinux_load_parse_cfg(fn_ip, mac, get_uuid(),
+                                      DEFAULT_TFTP_RETRIES,
                                       cfgbuf, sizeof(cfgbuf),
                                       entries, MAX_PXELINUX_ENTRIES, &def_ent);
     if (num_ent > 0) {
Signature · 1 line
1.8.3.1
#6 lore raw

[Qemu-devel] [PULL SUBSYSTEM s390x 6/7] pc-bios/s390-ccw: Optimize the s390-netboot.img for size

In reply to Thomas Huth

The -O2 optimization flag is passed via CFLAGS to the firmware Makefile, but in netbook.mak, we've got some rules that only use QEMU_CFLAGS for compiling the libc and libnet from SLOF, so these files get compiled without optimization so far. Use CFLAGS here, too, to create faster and smaller code.

We can additionally save some more bytes in the firmware images by compi- ling the code with -fno-asynchronous-unwind-tables. This will omit some ELF sections (used for stack unwinding for example) from the image that we do not need in the firmware.

---
 pc-bios/s390-ccw/Makefile    | 1 +
 pc-bios/s390-ccw/netboot.mak | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
pc-bios/s390-ccw/Makefile +1 -0
index 439e3cc..1eb316b 100644
@@ -15,6 +15,7 @@ OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \
 QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS))
 QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -msoft-float
 QEMU_CFLAGS += -march=z900 -fPIE -fno-strict-aliasing
+QEMU_CFLAGS += -fno-asynchronous-unwind-tables
 QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector)
 LDFLAGS += -Wl,-pie -nostdlib
 
pc-bios/s390-ccw/netboot.mak +2 -2
index 8af0cfd..14e96b2 100644
@@ -19,7 +19,7 @@ s390-netboot.img: s390-netboot.elf
 
 # libc files:
 
-LIBC_CFLAGS :=  $(QEMU_CFLAGS) $(LIBC_INC) $(LIBNET_INC)
+LIBC_CFLAGS :=  $(QEMU_CFLAGS) $(CFLAGS) $(LIBC_INC) $(LIBNET_INC)
 
 CTYPE_OBJS = isdigit.o isxdigit.o toupper.o
 %.o : $(SLOF_DIR)/lib/libc/ctype/%.c
@@ -52,7 +52,7 @@ libc.a: $(LIBCOBJS)
 
 LIBNETOBJS := args.o dhcp.o dns.o icmpv6.o ipv6.o tcp.o udp.o bootp.o \
 	      dhcpv6.o ethernet.o ipv4.o ndp.o tftp.o pxelinux.o
-LIBNETCFLAGS := $(QEMU_CFLAGS) -DDHCPARCH=0x1F $(LIBC_INC) $(LIBNET_INC)
+LIBNETCFLAGS := $(QEMU_CFLAGS) $(CFLAGS) -DDHCPARCH=0x1F $(LIBC_INC) $(LIBNET_INC)
 
 %.o : $(SLOF_DIR)/lib/libnet/%.c
 	$(call quiet-command,$(CC) $(LIBNETCFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
Signature · 1 line
1.8.3.1
#7 lore raw

[Qemu-devel] [PULL SUBSYSTEM s390x 7/7] pc-bios/s390-ccw: Update the s390-netboot.img binary

In reply to Thomas Huth

This binary now contains the support for pxelinux.cfg-style network booting.

---
 pc-bios/s390-netboot.img | Bin 87872 -> 54944 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-netboot.img binary +0 -0
index ef561efd2e222e03138705e9cf30d9e125a7970e..2c6886efb8320ff711589119ffbf077e68ec8784 100644
GIT binary patch
Signature · 1 line
1.8.3.1