From nobody Wed Oct 29 09:12:06 2025 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 1524647574309241.32982741848434; Wed, 25 Apr 2018 02:12:54 -0700 (PDT) Received: from localhost ([::1]:35336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBGTt-0000zT-KK for importer@patchew.org; Wed, 25 Apr 2018 05:12:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBGQ7-0006X3-J7 for qemu-devel@nongnu.org; Wed, 25 Apr 2018 05:09:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBGQ6-00021l-8X for qemu-devel@nongnu.org; Wed, 25 Apr 2018 05:08:59 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39906 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 1fBGQ6-00021T-3n; Wed, 25 Apr 2018 05:08:58 -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 F292D4022414; Wed, 25 Apr 2018 09:08:56 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-32.ams2.redhat.com [10.36.116.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F0B8215CDC8; Wed, 25 Apr 2018 09:08:54 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Wed, 25 Apr 2018 11:08:43 +0200 Message-Id: <1524647323-6449-4-git-send-email-thuth@redhat.com> In-Reply-To: <1524647323-6449-1-git-send-email-thuth@redhat.com> References: <1524647323-6449-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.6]); Wed, 25 Apr 2018 09:08:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 25 Apr 2018 09:08:57 +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 v3 3/3] 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 , Alexey Kardashevskiy , 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 | 100 +++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 95 insertions(+), 5 deletions(-) diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index 5f28ea0..c10b0ac 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -39,8 +39,12 @@ =20 extern char _start[]; =20 +#define KERNEL_ADDR ((void *)0L) +#define KERNEL_MAX_SIZE ((long)_start) + 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; @@ -136,9 +140,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) { @@ -275,6 +285,83 @@ static void net_release(filename_ip_t *fn_ip) } } =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_bootfile_load(filename_ip_t *fn_ip) +{ + int rc; + void *loadaddr =3D (void *)0x2000; /* Load right after the low-core */ + + rc =3D tftp_load(fn_ip, loadaddr, KERNEL_MAX_SIZE - (long)loadaddr); + 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, loadaddr, rc); + cfgbuf[rc] =3D 0; /* Make sure that it is NUL-terminated */ + if (!strncmp("* ", cfgbuf, 2)) { + return handle_ins_cfg(fn_ip, cfgbuf, rc); + } + } + + /* Move kernel to right location */ + memmove(KERNEL_ADDR, loadaddr, rc); + + return rc; +} + void panic(const char *string) { sclp_print(string); @@ -356,7 +443,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"); @@ -368,7 +455,10 @@ 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_bootfile_load(&fn_ip); + } =20 net_release(&fn_ip); =20 --=20 1.8.3.1