From nobody Sat Apr 27 09:55:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524470455999927.1763690517189; Mon, 23 Apr 2018 01:00:55 -0700 (PDT) Received: from localhost ([::1]:52192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAWP3-0005MS-Fs for importer@patchew.org; Mon, 23 Apr 2018 04:00:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAWMz-0003yZ-FS for qemu-devel@nongnu.org; Mon, 23 Apr 2018 03:58:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAWMu-0003cI-La for qemu-devel@nongnu.org; Mon, 23 Apr 2018 03:58:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53192 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAWMu-0003bi-Fg; Mon, 23 Apr 2018 03:58:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3583C410FBB4; Mon, 23 Apr 2018 07:58:33 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E9402166BAE; Mon, 23 Apr 2018 07:58:31 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Mon, 23 Apr 2018 09:58:22 +0200 Message-Id: <1524470305-26484-2-git-send-email-thuth@redhat.com> In-Reply-To: <1524470305-26484-1-git-send-email-thuth@redhat.com> References: <1524470305-26484-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 07:58:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 07:58:33 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 1/4] pc-bios/s390-ccw/net: Split up net_load() into init, load and uninit parts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Farhan Ali , Collin Walling , Cornelia Huck , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When we want to support pxelinux-style network booting later, we've got to do several TFTP transfers - and we do not want to apply for a new IP address via DHCP each time. So split up net_load into three parts: 1. net_init(), which initializes virtio-net, gets an IP address via DHCP and prints out the related information. 2. The tftp_load call is now moved directly into the main() function 3. A new net_release() function which should tear down the network stack before we are done in the firmware. This will make it easier to extend the code in the next patches. Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/netmain.c | 63 +++++++++++++++++++++++++++---------------= ---- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index d86d46b..8fa9e6c 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -128,13 +128,13 @@ static void seed_rng(uint8_t mac[]) srand(seed); } =20 -static int tftp_load(filename_ip_t *fnip, void *buffer, int len, - unsigned int retries, int ip_vers) +static int tftp_load(filename_ip_t *fnip, void *buffer, int len) { tftp_err_t tftp_err; int rc; =20 - rc =3D tftp(fnip, buffer, len, retries, &tftp_err, 1, 1428, ip_vers); + rc =3D tftp(fnip, buffer, len, DEFAULT_TFTP_RETRIES, &tftp_err, 1, 142= 8, + ip_version); =20 if (rc > 0) { printf(" TFTP: Received %s (%d KBytes)\n", fnip->filename, @@ -199,20 +199,19 @@ static int tftp_load(filename_ip_t *fnip, void *buffe= r, int len, return rc; } =20 -static int net_load(char *buffer, int len) +static int net_init(filename_ip_t *fn_ip) { - filename_ip_t fn_ip; uint8_t mac[6]; int rc; =20 - memset(&fn_ip, 0, sizeof(filename_ip_t)); + memset(fn_ip, 0, sizeof(filename_ip_t)); =20 rc =3D virtio_net_init(mac); if (rc < 0) { puts("Could not initialize network device"); return -101; } - fn_ip.fd =3D rc; + fn_ip->fd =3D rc; =20 printf(" Using MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -220,10 +219,10 @@ static int net_load(char *buffer, int len) set_mac_address(mac); /* init ethernet layer */ seed_rng(mac); =20 - rc =3D dhcp(&fn_ip, DEFAULT_BOOT_RETRIES); + rc =3D dhcp(fn_ip, DEFAULT_BOOT_RETRIES); if (rc >=3D 0) { if (ip_version =3D=3D 4) { - set_ipv4_address(fn_ip.own_ip); + set_ipv4_address(fn_ip->own_ip); } } else { puts("Could not get IP address"); @@ -232,18 +231,18 @@ static int net_load(char *buffer, int len) =20 if (ip_version =3D=3D 4) { printf(" Using IPv4 address: %d.%d.%d.%d\n", - (fn_ip.own_ip >> 24) & 0xFF, (fn_ip.own_ip >> 16) & 0xFF, - (fn_ip.own_ip >> 8) & 0xFF, fn_ip.own_ip & 0xFF); + (fn_ip->own_ip >> 24) & 0xFF, (fn_ip->own_ip >> 16) & 0xFF, + (fn_ip->own_ip >> 8) & 0xFF, fn_ip->own_ip & 0xFF); } else if (ip_version =3D=3D 6) { char ip6_str[40]; - ipv6_to_str(fn_ip.own_ip6.addr, ip6_str); + ipv6_to_str(fn_ip->own_ip6.addr, ip6_str); printf(" Using IPv6 address: %s\n", ip6_str); } =20 if (rc =3D=3D -2) { printf("ARP request to TFTP server (%d.%d.%d.%d) failed\n", - (fn_ip.server_ip >> 24) & 0xFF, (fn_ip.server_ip >> 16) & 0= xFF, - (fn_ip.server_ip >> 8) & 0xFF, fn_ip.server_ip & 0xFF); + (fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) &= 0xFF, + (fn_ip->server_ip >> 8) & 0xFF, fn_ip->server_ip & 0xFF); return -102; } if (rc =3D=3D -4 || rc =3D=3D -3) { @@ -251,28 +250,31 @@ static int net_load(char *buffer, int len) return -107; } =20 + printf(" Using TFTP server: "); if (ip_version =3D=3D 4) { - printf(" Requesting file \"%s\" via TFTP from %d.%d.%d.%d\n", - fn_ip.filename, - (fn_ip.server_ip >> 24) & 0xFF, (fn_ip.server_ip >> 16) & 0= xFF, - (fn_ip.server_ip >> 8) & 0xFF, fn_ip.server_ip & 0xFF); + printf("%d.%d.%d.%d\n", + (fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) &= 0xFF, + (fn_ip->server_ip >> 8) & 0xFF, fn_ip->server_ip & 0xFF); } else if (ip_version =3D=3D 6) { char ip6_str[40]; - printf(" Requesting file \"%s\" via TFTP from ", fn_ip.filename); - ipv6_to_str(fn_ip.server_ip6.addr, ip6_str); + ipv6_to_str(fn_ip->server_ip6.addr, ip6_str); printf("%s\n", ip6_str); } =20 - /* Do the TFTP load and print error message if necessary */ - rc =3D tftp_load(&fn_ip, buffer, len, DEFAULT_TFTP_RETRIES, ip_version= ); - - if (ip_version =3D=3D 4) { - dhcp_send_release(fn_ip.fd); + if (strlen((char *)fn_ip->filename) > 0) { + printf(" Bootfile name: '%s'\n", fn_ip->filename); } =20 return rc; } =20 +static void net_release(filename_ip_t *fn_ip) +{ + if (ip_version =3D=3D 4) { + dhcp_send_release(fn_ip->fd); + } +} + void panic(const char *string) { sclp_print(string); @@ -344,6 +346,7 @@ static void virtio_setup(void) =20 void main(void) { + filename_ip_t fn_ip; int rc; =20 sclp_setup(); @@ -351,7 +354,15 @@ void main(void) =20 virtio_setup(); =20 - rc =3D net_load(NULL, (long)_start); + rc =3D net_init(&fn_ip); + if (rc) { + panic("Network initialization failed. Halting.\n"); + } + + rc =3D tftp_load(&fn_ip, NULL, (long)_start); + + net_release(&fn_ip); + if (rc > 0) { sclp_print("Network loading done, starting kernel...\n"); asm volatile (" lpsw 0(%0) " : : "r"(0) : "memory"); --=20 1.8.3.1 From nobody Sat Apr 27 09:55:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524470456277399.20986880971907; Mon, 23 Apr 2018 01:00:56 -0700 (PDT) Received: from localhost ([::1]:52197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAWP9-0005UJ-EA for importer@patchew.org; Mon, 23 Apr 2018 04:00:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAWMz-0003yV-F5 for qemu-devel@nongnu.org; Mon, 23 Apr 2018 03:58:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAWMu-0003cD-Kg for qemu-devel@nongnu.org; Mon, 23 Apr 2018 03:58:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40328 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAWMu-0003bg-Fa; Mon, 23 Apr 2018 03:58:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F679406C790; Mon, 23 Apr 2018 07:58:35 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E8302166BAE; Mon, 23 Apr 2018 07:58:33 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Mon, 23 Apr 2018 09:58:23 +0200 Message-Id: <1524470305-26484-3-git-send-email-thuth@redhat.com> In-Reply-To: <1524470305-26484-1-git-send-email-thuth@redhat.com> References: <1524470305-26484-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 07:58:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 07:58:35 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 2/4] pc-bios/s390-ccw/net: Add support for pxelinux-style config files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Farhan Ali , Collin Walling , Cornelia Huck , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. 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 based on MAC or IP address. If no direct file or folder has been specified, we still look for certain files in the default "pxelinux.cfg/" folder, but omit some of the file names to avoid to download x86 config files here by mistake. Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/netboot.mak | 5 +- pc-bios/s390-ccw/netmain.c | 225 +++++++++++++++++++++++++++++++++++++++= ++-- 2 files changed, 222 insertions(+), 8 deletions(-) diff --git a/pc-bios/s390-ccw/netboot.mak b/pc-bios/s390-ccw/netboot.mak index a25d238..8db9573 100644 --- a/pc-bios/s390-ccw/netboot.mak +++ b/pc-bios/s390-ccw/netboot.mak @@ -24,8 +24,9 @@ CTYPE_OBJS =3D isdigit.o isxdigit.o toupper.o %.o : $(SLOF_DIR)/lib/libc/ctype/%.c $(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)= $@") =20 -STRING_OBJS =3D strcat.o strchr.o strcmp.o strcpy.o strlen.o strncmp.o str= ncpy.o \ - strstr.o memset.o memcpy.o memmove.o memcmp.o +STRING_OBJS =3D strcasecmp.o strcat.o strchr.o strcmp.o strcpy.o strlen.o \ + strncasecmp.o strncmp.o strncpy.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)= $@") =20 diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index 8fa9e6c..129f009 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -39,11 +39,17 @@ =20 extern char _start[]; =20 +#define KERNEL_ADDR ((void *)0L) +#define KERNEL_MAX_SIZE ((long)_start) +#define ARCH_COMMAND_LINE_SIZE 896 /* Taken from Linux kerne= l */ + char stack[PAGE_SIZE * 8] __attribute__((aligned(PAGE_SIZE))); IplParameterBlock iplb __attribute__((aligned(PAGE_SIZE))); +static char cfgbuf[2048]; =20 static SubChannelId net_schid =3D { .one =3D 1 }; static int ip_version =3D 4; +static uint8_t mac[6]; static uint64_t dest_timer; =20 static uint64_t get_timer_ms(void) @@ -136,9 +142,15 @@ static int tftp_load(filename_ip_t *fnip, void *buffer= , int len) rc =3D tftp(fnip, buffer, len, DEFAULT_TFTP_RETRIES, &tftp_err, 1, 142= 8, ip_version); =20 - if (rc > 0) { - printf(" TFTP: Received %s (%d KBytes)\n", fnip->filename, - rc / 1024); + if (rc < 0) { + /* Make sure that error messages are put into a new line */ + printf("\n "); + } + + if (rc > 1024) { + printf(" TFTP: Received %s (%d KBytes)\n", fnip->filename, rc / 1= 024); + } else if (rc > 0) { + printf(" TFTP: Received %s (%d Bytes)\n", fnip->filename, rc); } else if (rc =3D=3D -1) { puts("unknown TFTP error"); } else if (rc =3D=3D -2) { @@ -201,7 +213,6 @@ static int tftp_load(filename_ip_t *fnip, void *buffer,= int len) =20 static int net_init(filename_ip_t *fn_ip) { - uint8_t mac[6]; int rc; =20 memset(fn_ip, 0, sizeof(filename_ip_t)); @@ -275,6 +286,202 @@ static void net_release(filename_ip_t *fn_ip) } } =20 +/* This structure holds the data from one pxelinux.cfg file entry */ +struct lkia { + const char *label; + const char *kernel; + const char *initrd; + const char *append; +}; + +static int load_kernel_with_initrd(filename_ip_t *fn_ip, struct lkia *kia) +{ + int rc; + + printf("Loading pxelinux.cfg entry '%s'\n", kia->label); + + if (!kia->kernel) { + printf("Kernel entry is missing!\n"); + return -1; + } + + strncpy((char *)&fn_ip->filename, kia->kernel, sizeof(fn_ip->filename)= ); + rc =3D tftp_load(fn_ip, KERNEL_ADDR, KERNEL_MAX_SIZE); + if (rc < 0) { + return rc; + } + + if (kia->initrd) { + uint64_t iaddr =3D (rc + 0xfff) & ~0xfffUL; + + strncpy((char *)&fn_ip->filename, kia->initrd, sizeof(fn_ip->filen= ame)); + rc =3D tftp_load(fn_ip, (void *)iaddr, KERNEL_MAX_SIZE - iaddr); + if (rc < 0) { + return rc; + } + /* Patch location and size: */ + *(uint64_t *)0x10408 =3D iaddr; + *(uint64_t *)0x10410 =3D rc; + rc +=3D iaddr; + } + + if (kia->append) { + strncpy((char *)0x10480, kia->append, ARCH_COMMAND_LINE_SIZE); + } + + return rc; +} + +#define MAX_PXELINUX_ENTRIES 16 + +/** + * Parse a pxelinux-style configuration file. + * See the following URL for more inforation about the config file syntax: + * https://www.syslinux.org/wiki/index.php?title=3DPXELINUX + */ +static int handle_pxelinux_cfg(filename_ip_t *fn_ip, char *cfg, int cfgsiz= e) +{ + struct lkia entries[MAX_PXELINUX_ENTRIES]; + int num_entries =3D 0; + char *ptr =3D cfg, *eol, *arg; + char *defaultlabel =3D NULL; + int def_ent =3D 0; + + while (ptr < cfg + cfgsize && num_entries < MAX_PXELINUX_ENTRIES) { + eol =3D strchr(ptr, '\n'); + if (!eol) { + eol =3D cfg + cfgsize; + } + if (eol > ptr && *(eol - 1) =3D=3D '\r') { + *(eol - 1) =3D 0; + } + *eol =3D '\0'; + while (*ptr =3D=3D ' ' || *ptr =3D=3D '\t') { + ptr++; + } + if (*ptr =3D=3D 0 || *ptr =3D=3D '#') { /* Ignore comments and e= mpty lines */ + goto nextline; + } + arg =3D strchr(ptr, ' '); /* Look for space between command and= arg */ + if (!arg) { + arg =3D strchr(ptr, '\t'); + } + if (!arg) { + printf("Failed to parse the following line:\n %s\n", ptr); + goto nextline; + } + *arg++ =3D 0; + while (*arg =3D=3D ' ' || *arg =3D=3D '\t') { + arg++; + } + if (!strcasecmp("default", ptr)) { + defaultlabel =3D arg; + } else if (!strcasecmp("label", ptr)) { + entries[num_entries].label =3D arg; + if (defaultlabel && !strcmp(arg, defaultlabel)) { + def_ent =3D num_entries; + } + num_entries++; + } else if (!strcasecmp("kernel", ptr) && num_entries > 0) { + entries[num_entries - 1].kernel =3D arg; + } else if (!strcasecmp("initrd", ptr) && num_entries > 0) { + entries[num_entries - 1].initrd =3D arg; + } else if (!strcasecmp("append", ptr) && num_entries > 0) { + entries[num_entries - 1].append =3D arg; + } else { + printf("Command '%s' is not supported.\n", ptr); + } +nextline: + ptr =3D eol + 1; + } + + return load_kernel_with_initrd(fn_ip, &entries[def_ent]); +} + +static int net_try_pxelinux_cfgs(filename_ip_t *fn_ip) +{ + int rc, idx; + char basedir[256]; + int has_basedir; + + cfgbuf[sizeof(cfgbuf) - 1] =3D 0; /* Make sure that it is NUL-termin= ated */ + + /* Did we get a usable base directory via DHCP? */ + idx =3D strlen((char *)fn_ip->filename); + if (idx > 0 && idx < sizeof(basedir) - 40 && + fn_ip->filename[idx - 1] =3D=3D '/') { + has_basedir =3D true; + strcpy(basedir, (char *)fn_ip->filename); + } else { + has_basedir =3D false; + strcpy(basedir, "pxelinux.cfg/"); + } + + printf("Trying pxelinux.cfg files...\n"); + + /* Look for config file with MAC address in its name */ + sprintf((char *)fn_ip->filename, "%s%02x-%02x-%02x-%02x-%02x-%02x", + basedir, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + rc =3D tftp_load(fn_ip, cfgbuf, sizeof(cfgbuf) - 1); + if (rc > 0) { + return handle_pxelinux_cfg(fn_ip, cfgbuf, sizeof(cfgbuf)); + } + + /* Look for config file with IP address in its name */ + if (ip_version =3D=3D 4) { + for (idx =3D 0; (has_basedir && idx <=3D 7) || idx < 1; idx++) { + sprintf((char *)fn_ip->filename, "%s%02X%02X%02X%02X", basedir, + (fn_ip->own_ip >> 24) & 0xff, (fn_ip->own_ip >> 16) & = 0xff, + (fn_ip->own_ip >> 8) & 0xff, fn_ip->own_ip & 0xff); + fn_ip->filename[strlen((char *)fn_ip->filename) - idx] =3D 0; + rc =3D tftp_load(fn_ip, cfgbuf, sizeof(cfgbuf) - 1); + if (rc > 0) { + return handle_pxelinux_cfg(fn_ip, cfgbuf, sizeof(cfgbuf)); + } + } + } + + /* Try "default" config file */ + if (has_basedir) { + sprintf((char *)fn_ip->filename, "%sdefault", basedir); + rc =3D tftp_load(fn_ip, cfgbuf, sizeof(cfgbuf) - 1); + if (rc > 0) { + return handle_pxelinux_cfg(fn_ip, cfgbuf, sizeof(cfgbuf)); + } + } + + return -1; +} + +static int net_try_direct_tftp_load(filename_ip_t *fn_ip) +{ + int rc; + void *baseaddr =3D (void *)0x2000; /* Load right after the low-core */ + + rc =3D tftp_load(fn_ip, baseaddr, KERNEL_MAX_SIZE - (long)baseaddr); + if (rc < 0) { + return rc; + } else if (rc < 8) { + printf("'%s' is too small (%i bytes only).\n", fn_ip->filename, rc= ); + return -1; + } + + /* Check whether it is a configuration file instead of a kernel */ + if (rc < sizeof(cfgbuf) - 1) { + memcpy(cfgbuf, baseaddr, rc); + cfgbuf[rc] =3D 0; /* Make sure that it is NUL-terminated */ + if (!strncasecmp("default", cfgbuf, 7) || !strncmp("# ", cfgbuf, 2= )) { + /* Looks like it is a pxelinux.cfg */ + return handle_pxelinux_cfg(fn_ip, cfgbuf, rc); + } + } + + /* Move kernel to right location */ + memmove(KERNEL_ADDR, baseaddr, rc); + + return rc; +} + void panic(const char *string) { sclp_print(string); @@ -347,7 +554,7 @@ static void virtio_setup(void) void main(void) { filename_ip_t fn_ip; - int rc; + int rc, fnlen; =20 sclp_setup(); sclp_print("Network boot starting...\n"); @@ -359,7 +566,13 @@ void main(void) panic("Network initialization failed. Halting.\n"); } =20 - rc =3D tftp_load(&fn_ip, NULL, (long)_start); + fnlen =3D strlen((char *)fn_ip.filename); + if (fnlen > 0 && fn_ip.filename[fnlen - 1] !=3D '/') { + rc =3D net_try_direct_tftp_load(&fn_ip); + } + if (rc <=3D 0) { + rc =3D net_try_pxelinux_cfgs(&fn_ip); + } =20 net_release(&fn_ip); =20 --=20 1.8.3.1 From nobody Sat Apr 27 09:55:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524470454308818.3768874369918; Mon, 23 Apr 2018 01:00:54 -0700 (PDT) Received: from localhost ([::1]:52194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAWP6-0005O1-82 for importer@patchew.org; Mon, 23 Apr 2018 04:00:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAWMz-0003yW-F3 for qemu-devel@nongnu.org; Mon, 23 Apr 2018 03:58:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAWMv-0003d3-UT for qemu-devel@nongnu.org; Mon, 23 Apr 2018 03:58:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53194 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAWMv-0003cl-Pz; Mon, 23 Apr 2018 03:58:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BE2C4270968; Mon, 23 Apr 2018 07:58:37 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D1382166BAE; Mon, 23 Apr 2018 07:58:35 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Mon, 23 Apr 2018 09:58:24 +0200 Message-Id: <1524470305-26484-4-git-send-email-thuth@redhat.com> In-Reply-To: <1524470305-26484-1-git-send-email-thuth@redhat.com> References: <1524470305-26484-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 07:58:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 07:58:37 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 3/4] pc-bios/s390-ccw/net: Add support for .INS config files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Farhan Ali , Collin Walling , Cornelia Huck , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The .INS config files can normally be found on CD-ROM ISO images, so by supporting these files, it is now possible to boot directly when the TFTP server is set up with the contents of such an CD-ROM image. Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/netmain.c | 51 ++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 51 insertions(+) diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index 129f009..e5418a9 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -453,6 +453,55 @@ static int net_try_pxelinux_cfgs(filename_ip_t *fn_ip) return -1; } =20 +/** + * Load via information from a .INS file (which can be found on CD-ROMs + * for example) + */ +static int handle_ins_cfg(filename_ip_t *fn_ip, char *cfg, int cfgsize) +{ + char *ptr; + int rc =3D -1, llen; + void *destaddr; + char *insbuf =3D cfg; + + ptr =3D strchr(insbuf, '\n'); + if (!ptr) { + puts("Does not seem to be a valid .INS file"); + return -1; + } + + *ptr =3D 0; + printf("\nParsing .INS file:\n %s\n", &insbuf[2]); + + insbuf =3D ptr + 1; + while (*insbuf && insbuf < cfg + cfgsize) { + ptr =3D strchr(insbuf, '\n'); + if (ptr) { + *ptr =3D 0; + } + llen =3D strlen(insbuf); + if (!llen) { + insbuf =3D ptr + 1; + continue; + } + ptr =3D strchr(insbuf, ' '); + if (!ptr) { + puts("Missing space separator in .INS file"); + return -1; + } + *ptr =3D 0; + strncpy((char *)fn_ip->filename, insbuf, sizeof(fn_ip->filename)); + destaddr =3D (char *)atol(ptr + 1); + rc =3D tftp_load(fn_ip, destaddr, (long)_start - (long)destaddr); + if (rc <=3D 0) { + break; + } + insbuf +=3D llen + 1; + } + + return rc; +} + static int net_try_direct_tftp_load(filename_ip_t *fn_ip) { int rc; @@ -473,6 +522,8 @@ static int net_try_direct_tftp_load(filename_ip_t *fn_i= p) if (!strncasecmp("default", cfgbuf, 7) || !strncmp("# ", cfgbuf, 2= )) { /* Looks like it is a pxelinux.cfg */ return handle_pxelinux_cfg(fn_ip, cfgbuf, rc); + } else if (!strncmp("* ", cfgbuf, 2)) { + return handle_ins_cfg(fn_ip, cfgbuf, rc); } } =20 --=20 1.8.3.1 From nobody Sat Apr 27 09:55:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524470660225269.4089304223529; Mon, 23 Apr 2018 01:04:20 -0700 (PDT) Received: from localhost ([::1]:52389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAWSR-0008HI-EZ for importer@patchew.org; Mon, 23 Apr 2018 04:04:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAWMz-0003ym-Ql for qemu-devel@nongnu.org; Mon, 23 Apr 2018 03:58:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAWMy-0003dv-7B for qemu-devel@nongnu.org; Mon, 23 Apr 2018 03:58:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40330 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAWMy-0003dg-26; Mon, 23 Apr 2018 03:58:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A718406C79E; Mon, 23 Apr 2018 07:58:39 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAB252166BAE; Mon, 23 Apr 2018 07:58:37 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Mon, 23 Apr 2018 09:58:25 +0200 Message-Id: <1524470305-26484-5-git-send-email-thuth@redhat.com> In-Reply-To: <1524470305-26484-1-git-send-email-thuth@redhat.com> References: <1524470305-26484-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 07:58:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 07:58:39 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 4/4] pc-bios/s390-ccw/net: Use diag308 to reset machine before jumping to the OS X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Farhan Ali , Collin Walling , Cornelia Huck , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The netboot firmware so far simply jumped directly into the OS kernel after the download has been completed. This, however, bears the risk that the virtio-net device still might be active in the background and incoming packets are still placed into the buffers - which could destroy memory of the now-running Linux kernel in case it did not take over the device fast enough. Also the SCLP console is not put into a well-defined state here. We should hand over the system in a clean state when jumping into the kernel, so let's use the same mechanism as it's done in the main s390-ccw firmware and reset the machine with diag308 into a clean state before jumping into the OS kernel code. To be able to share the code with the main s390-ccw firmware, the related functions are now extracted from bootmap.c into a new file called jump2ipl.c. Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/Makefile | 4 ++- pc-bios/s390-ccw/bootmap.c | 63 +--------------------------------- pc-bios/s390-ccw/bootmap.h | 4 --- pc-bios/s390-ccw/jump2ipl.c | 81 ++++++++++++++++++++++++++++++++++++++++= ++++ pc-bios/s390-ccw/netboot.mak | 3 +- pc-bios/s390-ccw/netmain.c | 11 +++++- pc-bios/s390-ccw/s390-ccw.h | 4 +++ 7 files changed, 101 insertions(+), 69 deletions(-) create mode 100644 pc-bios/s390-ccw/jump2ipl.c diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile index 1712c2d..439e3cc 100644 --- a/pc-bios/s390-ccw/Makefile +++ b/pc-bios/s390-ccw/Makefile @@ -9,7 +9,9 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/s390-ccw) =20 .PHONY : all clean build-all =20 -OBJECTS =3D start.o main.o bootmap.o sclp.o virtio.o virtio-scsi.o virtio-= blkdev.o libc.o menu.o +OBJECTS =3D start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \ + virtio.o virtio-scsi.o virtio-blkdev.o libc.o + QEMU_CFLAGS :=3D $(filter -W%, $(QEMU_CFLAGS)) QEMU_CFLAGS +=3D -ffreestanding -fno-delete-null-pointer-checks -msoft-flo= at QEMU_CFLAGS +=3D -march=3Dz900 -fPIE -fno-strict-aliasing diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 9287b7a..7e63e6b 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -29,14 +29,6 @@ /* Scratch space */ static uint8_t sec[MAX_SECTOR_SIZE*4] __attribute__((__aligned__(PAGE_SIZE= ))); =20 -typedef struct ResetInfo { - uint32_t ipl_mask; - uint32_t ipl_addr; - uint32_t ipl_continue; -} ResetInfo; - -static ResetInfo save; - const uint8_t el_torito_magic[] =3D "EL TORITO SPECIFICATION" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; =20 @@ -57,53 +49,6 @@ static inline bool is_iso_vd_valid(IsoVolDesc *vd) vd->type <=3D VOL_DESC_TYPE_PARTITION; } =20 -static void jump_to_IPL_2(void) -{ - ResetInfo *current =3D 0; - - void (*ipl)(void) =3D (void *) (uint64_t) current->ipl_continue; - *current =3D save; - ipl(); /* should not return */ -} - -static void jump_to_IPL_code(uint64_t address) -{ - /* store the subsystem information _after_ the bootmap was loaded */ - write_subsystem_identification(); - - /* prevent unknown IPL types in the guest */ - if (iplb.pbt =3D=3D S390_IPL_TYPE_QEMU_SCSI) { - iplb.pbt =3D S390_IPL_TYPE_CCW; - set_iplb(&iplb); - } - - /* - * The IPL PSW is at address 0. We also must not overwrite the - * content of non-BIOS memory after we loaded the guest, so we - * save the original content and restore it in jump_to_IPL_2. - */ - ResetInfo *current =3D 0; - - save =3D *current; - current->ipl_addr =3D (uint32_t) (uint64_t) &jump_to_IPL_2; - current->ipl_continue =3D address & 0x7fffffff; - - debug_print_int("set IPL addr to", current->ipl_continue); - - /* Ensure the guest output starts fresh */ - sclp_print("\n"); - - /* - * HACK ALERT. - * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2 - * can then use r15 as its stack pointer. - */ - asm volatile("lghi 1,1\n\t" - "diag 1,1,0x308\n\t" - : : : "1", "memory"); - panic("\n! IPL returns !\n"); -} - /*********************************************************************** * IPL an ECKD DASD (CDL or LDL/CMS format) */ @@ -727,13 +672,7 @@ static void load_iso_bc_entry(IsoBcSection *load) (void *)((uint64_t)bswap16(s.load_segment)), blks_to_load); =20 - /* Trying to get PSW at zero address */ - if (*((uint64_t *)0) & IPL_PSW_MASK) { - jump_to_IPL_code((*((uint64_t *)0)) & 0x7fffffff); - } - - /* Try default linux start address */ - jump_to_IPL_code(KERN_IMAGE_START); + jump_to_low_kernel(); } =20 static uint32_t find_iso_bc(void) diff --git a/pc-bios/s390-ccw/bootmap.h b/pc-bios/s390-ccw/bootmap.h index 07eb600..bef81ff 100644 --- a/pc-bios/s390-ccw/bootmap.h +++ b/pc-bios/s390-ccw/bootmap.h @@ -355,10 +355,6 @@ static inline uint32_t iso_733_to_u32(uint64_t x) #define ISO_SECTOR_SIZE 2048 /* El Torito specifies boot image size in 512 byte blocks */ #define ET_SECTOR_SHIFT 2 -#define KERN_IMAGE_START 0x010000UL -#define PSW_MASK_64 0x0000000100000000ULL -#define PSW_MASK_32 0x0000000080000000ULL -#define IPL_PSW_MASK (PSW_MASK_32 | PSW_MASK_64) =20 #define ISO_PRIMARY_VD_SECTOR 16 =20 diff --git a/pc-bios/s390-ccw/jump2ipl.c b/pc-bios/s390-ccw/jump2ipl.c new file mode 100644 index 0000000..21b25d8 --- /dev/null +++ b/pc-bios/s390-ccw/jump2ipl.c @@ -0,0 +1,81 @@ +/* + * QEMU s390-ccw firmware - jump to IPL code + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#include "libc.h" +#include "s390-ccw.h" + +#define KERN_IMAGE_START 0x010000UL +#define PSW_MASK_64 0x0000000100000000ULL +#define PSW_MASK_32 0x0000000080000000ULL +#define IPL_PSW_MASK (PSW_MASK_32 | PSW_MASK_64) + +typedef struct ResetInfo { + uint32_t ipl_mask; + uint32_t ipl_addr; + uint32_t ipl_continue; +} ResetInfo; + +static ResetInfo save; + +static void jump_to_IPL_2(void) +{ + ResetInfo *current =3D 0; + + void (*ipl)(void) =3D (void *) (uint64_t) current->ipl_continue; + *current =3D save; + ipl(); /* should not return */ +} + +void jump_to_IPL_code(uint64_t address) +{ + /* store the subsystem information _after_ the bootmap was loaded */ + write_subsystem_identification(); + + /* prevent unknown IPL types in the guest */ + if (iplb.pbt =3D=3D S390_IPL_TYPE_QEMU_SCSI) { + iplb.pbt =3D S390_IPL_TYPE_CCW; + set_iplb(&iplb); + } + + /* + * The IPL PSW is at address 0. We also must not overwrite the + * content of non-BIOS memory after we loaded the guest, so we + * save the original content and restore it in jump_to_IPL_2. + */ + ResetInfo *current =3D 0; + + save =3D *current; + current->ipl_addr =3D (uint32_t) (uint64_t) &jump_to_IPL_2; + current->ipl_continue =3D address & 0x7fffffff; + + debug_print_int("set IPL addr to", current->ipl_continue); + + /* Ensure the guest output starts fresh */ + sclp_print("\n"); + + /* + * HACK ALERT. + * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2 + * can then use r15 as its stack pointer. + */ + asm volatile("lghi 1,1\n\t" + "diag 1,1,0x308\n\t" + : : : "1", "memory"); + panic("\n! IPL returns !\n"); +} + +void jump_to_low_kernel(void) +{ + /* Trying to get PSW at zero address */ + if (*((uint64_t *)0) & IPL_PSW_MASK) { + jump_to_IPL_code((*((uint64_t *)0)) & 0x7fffffff); + } + + /* Try default linux start address */ + jump_to_IPL_code(KERN_IMAGE_START); +} diff --git a/pc-bios/s390-ccw/netboot.mak b/pc-bios/s390-ccw/netboot.mak index 8db9573..3434018 100644 --- a/pc-bios/s390-ccw/netboot.mak +++ b/pc-bios/s390-ccw/netboot.mak @@ -1,7 +1,8 @@ =20 SLOF_DIR :=3D $(SRC_PATH)/roms/SLOF =20 -NETOBJS :=3D start.o sclp.o virtio.o virtio-net.o netmain.o libnet.a libc.a +NETOBJS :=3D start.o sclp.o virtio.o virtio-net.o jump2ipl.o netmain.o \ + libnet.a libc.a =20 LIBC_INC :=3D -nostdinc -I$(SLOF_DIR)/lib/libc/include LIBNET_INC :=3D -I$(SLOF_DIR)/lib/libnet diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index e5418a9..fdf115e 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -541,6 +541,15 @@ void panic(const char *string) } } =20 +void write_subsystem_identification(void) +{ + uint32_t *schid =3D (uint32_t *) 184; + uint32_t *zeroes =3D (uint32_t *) 188; + + *schid =3D 0; /* We must not set this for virtio-net */ + *zeroes =3D 0; +} + static bool find_net_dev(Schib *schib, int dev_no) { int i, r; @@ -629,7 +638,7 @@ void main(void) =20 if (rc > 0) { sclp_print("Network loading done, starting kernel...\n"); - asm volatile (" lpsw 0(%0) " : : "r"(0) : "memory"); + jump_to_low_kernel(); } =20 panic("Failed to load OS from network\n"); diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h index fd18da2..d88e637 100644 --- a/pc-bios/s390-ccw/s390-ccw.h +++ b/pc-bios/s390-ccw/s390-ccw.h @@ -87,6 +87,10 @@ ulong get_second(void); /* bootmap.c */ void zipl_load(void); =20 +/* jump2ipl.c */ +void jump_to_IPL_code(uint64_t address); +void jump_to_low_kernel(void); + /* menu.c */ void menu_set_parms(uint8_t boot_menu_flag, uint32_t boot_menu_timeout); int menu_get_zipl_boot_index(const char *menu_data); --=20 1.8.3.1 From nobody Sat Apr 27 09:55:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524495422813503.62793135576317; Mon, 23 Apr 2018 07:57:02 -0700 (PDT) Received: from localhost ([::1]:53329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fActp-0007w8-Qd for importer@patchew.org; Mon, 23 Apr 2018 10:57:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAcss-0007XX-OY for qemu-devel@nongnu.org; Mon, 23 Apr 2018 10:56:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAcsp-0008WR-NL for qemu-devel@nongnu.org; Mon, 23 Apr 2018 10:56:02 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45102 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAcsp-0008Vt-Ho; Mon, 23 Apr 2018 10:55:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0ED92EC010; Mon, 23 Apr 2018 14:55:55 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3110B215CDC8; Mon, 23 Apr 2018 14:55:48 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Mon, 23 Apr 2018 16:55:48 +0200 Message-Id: <1524495348-435-1-git-send-email-thuth@redhat.com> In-Reply-To: <1524470305-26484-1-git-send-email-thuth@redhat.com> References: <1524470305-26484-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 23 Apr 2018 14:55:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 23 Apr 2018 14:55:55 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 5/4] pc-bios/s390-ccw/net: Try to load pxelinux.cfg file accoring to the UUID X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Farhan Ali , Collin Walling , Cornelia Huck , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Thomas Huth --- Sorry, just found out how to get the VM UUID after sending out the v2 series, so this is now patch 5 of 4 ;-) pc-bios/s390-ccw/netmain.c | 45 ++++++++++++++++++++++++++++++++++++++++++= +++ 1 file changed, 45 insertions(+) diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index fdf115e..f75bd7e 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -286,6 +286,37 @@ static void net_release(filename_ip_t *fn_ip) } } =20 +static int get_uuid(uint8_t *uuid) +{ + register int r0 asm("0"); + register int r1 asm("1"); + uint8_t *mem, *buf; + int i, chk =3D 0; + + mem =3D malloc(2 * PAGE_SIZE); + if (!mem) { + puts("Out of memory ... can not get UUID."); + return -12; + } + buf =3D (uint8_t *)(((uint64_t)mem + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)= ); + memset(buf, 0, PAGE_SIZE); + + /* Get SYSIB 3.2.2 */ + r0 =3D (3 << 28) | 2; + r1 =3D 2; + asm volatile(" stsi 0(%2)\n" : : "d" (r0), "d" (r1), "a" (buf) + : "cc", "memory"); + + for (i =3D 0; i < 16; i++) { + uuid[i] =3D buf[8 * 4 + 12 * 4 + i]; + chk |=3D uuid[i]; + } + + free(mem); + + return chk ? 0 : -1; +} + /* This structure holds the data from one pxelinux.cfg file entry */ struct lkia { const char *label; @@ -403,6 +434,7 @@ static int net_try_pxelinux_cfgs(filename_ip_t *fn_ip) int rc, idx; char basedir[256]; int has_basedir; + uint8_t uuid[16]; =20 cfgbuf[sizeof(cfgbuf) - 1] =3D 0; /* Make sure that it is NUL-termin= ated */ =20 @@ -419,6 +451,19 @@ static int net_try_pxelinux_cfgs(filename_ip_t *fn_ip) =20 printf("Trying pxelinux.cfg files...\n"); =20 + /* Try to load config file with name based on the VM UUID */ + if (get_uuid(uuid) =3D=3D 0) { + sprintf((char *)fn_ip->filename, "%s%02x%02x%02x%02x-%02x%02x-" + "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", basedir, + 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]); + rc =3D tftp_load(fn_ip, cfgbuf, sizeof(cfgbuf) - 1); + if (rc > 0) { + return handle_pxelinux_cfg(fn_ip, cfgbuf, sizeof(cfgbuf)); + } + } + /* Look for config file with MAC address in its name */ sprintf((char *)fn_ip->filename, "%s%02x-%02x-%02x-%02x-%02x-%02x", basedir, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); --=20 1.8.3.1