From nobody Mon Apr 29 12:18:26 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 1524054877006799.7446821214166; Wed, 18 Apr 2018 05:34:37 -0700 (PDT) Received: from localhost ([::1]:54026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8mIG-00025k-5U for importer@patchew.org; Wed, 18 Apr 2018 08:34:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8mFd-0000gd-GZ for qemu-devel@nongnu.org; Wed, 18 Apr 2018 08:31:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8mFc-0003F8-5l for qemu-devel@nongnu.org; Wed, 18 Apr 2018 08:31:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34604 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 1f8mFb-0003El-VN; Wed, 18 Apr 2018 08:31:52 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F6828DC4C; Wed, 18 Apr 2018 12:31:51 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1D5410F1BEC; Wed, 18 Apr 2018 12:31:49 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Wed, 18 Apr 2018 14:31:44 +0200 Message-Id: <1524054707-20663-2-git-send-email-thuth@redhat.com> In-Reply-To: <1524054707-20663-1-git-send-email-thuth@redhat.com> References: <1524054707-20663-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 18 Apr 2018 12:31:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 18 Apr 2018 12:31:51 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v1 for-2.13 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: 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_uninit() 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..ebdc440 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_uninit(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_uninit(&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 Mon Apr 29 12:18:26 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 1524054877575803.5480863136607; Wed, 18 Apr 2018 05:34:37 -0700 (PDT) Received: from localhost ([::1]:54027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8mIG-000270-Lb for importer@patchew.org; Wed, 18 Apr 2018 08:34:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8mFg-0000jW-Oh for qemu-devel@nongnu.org; Wed, 18 Apr 2018 08:31:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8mFe-0003H1-0B for qemu-devel@nongnu.org; Wed, 18 Apr 2018 08:31:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55120 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 1f8mFd-0003GD-RM; Wed, 18 Apr 2018 08:31:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 687DD4023335; Wed, 18 Apr 2018 12:31:53 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED95E10F1BEA; Wed, 18 Apr 2018 12:31:51 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Wed, 18 Apr 2018 14:31:45 +0200 Message-Id: <1524054707-20663-3-git-send-email-thuth@redhat.com> In-Reply-To: <1524054707-20663-1-git-send-email-thuth@redhat.com> References: <1524054707-20663-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 18 Apr 2018 12:31:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 18 Apr 2018 12:31:53 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v1 for-2.13 2/4] pc-bios/s390-ccw/net: Stop virtio-net device before jumping into 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: 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 virtio-net receive buffers are filled asynchronously, so we should make sure to properly shut down the virtio-net device before we jump into the loaded kernel. Otherwise an incoming packet could destroy memory of the OS kernel if it did not re-initialize the virtio-net device fast enough yet. Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/netmain.c | 1 + pc-bios/s390-ccw/virtio-net.c | 8 ++++++++ pc-bios/s390-ccw/virtio.c | 19 ++++++++++++++----- pc-bios/s390-ccw/virtio.h | 3 +++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index ebdc440..e11ed4e 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -273,6 +273,7 @@ static void net_uninit(filename_ip_t *fn_ip) if (ip_version =3D=3D 4) { dhcp_send_release(fn_ip->fd); } + virtio_net_uninit(); } =20 void panic(const char *string) diff --git a/pc-bios/s390-ccw/virtio-net.c b/pc-bios/s390-ccw/virtio-net.c index ff7f4da..339fe53 100644 --- a/pc-bios/s390-ccw/virtio-net.c +++ b/pc-bios/s390-ccw/virtio-net.c @@ -67,6 +67,14 @@ int virtio_net_init(void *mac_addr) return 0; } =20 +void virtio_net_uninit(void) +{ + VDev *vdev =3D virtio_get_device(); + + virtio_status_set(vdev, VIRTIO_CONFIG_S_FAILED); + virtio_reset_dev(vdev); +} + int send(int fd, const void *buf, int len, int flags) { VirtioNetHdr tx_hdr; diff --git a/pc-bios/s390-ccw/virtio.c b/pc-bios/s390-ccw/virtio.c index cdb66f4..1d15b03 100644 --- a/pc-bios/s390-ccw/virtio.c +++ b/pc-bios/s390-ccw/virtio.c @@ -248,10 +248,21 @@ int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd) return 0; } =20 +void virtio_status_set(VDev *vdev, uint8_t status) +{ + IPL_assert( + run_ccw(vdev, CCW_CMD_WRITE_STATUS, &status, sizeof(status)) =3D= =3D 0, + "Could not write status to host"); +} + +void virtio_reset_dev(VDev *vdev) +{ + run_ccw(vdev, CCW_CMD_VDEV_RESET, NULL, 0); +} + void virtio_setup_ccw(VDev *vdev) { int i, rc, cfg_size =3D 0; - unsigned char status =3D VIRTIO_CONFIG_S_DRIVER_OK; struct VirtioFeatureDesc { uint32_t features; uint8_t index; @@ -263,7 +274,7 @@ void virtio_setup_ccw(VDev *vdev) vdev->config.blk.blk_size =3D 0; /* mark "illegal" - setup started... = */ vdev->guessed_disk_nature =3D VIRTIO_GDN_NONE; =20 - run_ccw(vdev, CCW_CMD_VDEV_RESET, NULL, 0); + virtio_reset_dev(vdev); =20 switch (vdev->senseid.cu_model) { case VIRTIO_ID_NET: @@ -320,9 +331,7 @@ void virtio_setup_ccw(VDev *vdev) IPL_assert(run_ccw(vdev, CCW_CMD_SET_VQ, &info, sizeof(info)) =3D= =3D 0, "Cannot set VQ info"); } - IPL_assert( - run_ccw(vdev, CCW_CMD_WRITE_STATUS, &status, sizeof(status)) =3D= =3D 0, - "Could not write status to host"); + virtio_status_set(vdev, VIRTIO_CONFIG_S_DRIVER_OK); } =20 bool virtio_is_supported(SubChannelId schid) diff --git a/pc-bios/s390-ccw/virtio.h b/pc-bios/s390-ccw/virtio.h index 19fceb6..c2479be 100644 --- a/pc-bios/s390-ccw/virtio.h +++ b/pc-bios/s390-ccw/virtio.h @@ -277,8 +277,11 @@ void vring_send_buf(VRing *vr, void *p, int len, int f= lags); int vr_poll(VRing *vr); int vring_wait_reply(void); int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd); +void virtio_status_set(VDev *vdev, uint8_t status); +void virtio_reset_dev(VDev *vdev); void virtio_setup_ccw(VDev *vdev); =20 int virtio_net_init(void *mac_addr); +void virtio_net_uninit(void); =20 #endif /* VIRTIO_H */ --=20 1.8.3.1 From nobody Mon Apr 29 12:18:26 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 1524055083404639.4672536889195; Wed, 18 Apr 2018 05:38:03 -0700 (PDT) Received: from localhost ([::1]:54093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8mLa-0004qx-Ft for importer@patchew.org; Wed, 18 Apr 2018 08:38:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8mFh-0000jv-RX for qemu-devel@nongnu.org; Wed, 18 Apr 2018 08:31:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8mFg-0003Ib-1t for qemu-devel@nongnu.org; Wed, 18 Apr 2018 08:31:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34628 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 1f8mFf-0003IH-Sb; Wed, 18 Apr 2018 08:31:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7448F857EA; Wed, 18 Apr 2018 12:31:55 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id C752610F1BEE; Wed, 18 Apr 2018 12:31:53 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Wed, 18 Apr 2018 14:31:46 +0200 Message-Id: <1524054707-20663-4-git-send-email-thuth@redhat.com> In-Reply-To: <1524054707-20663-1-git-send-email-thuth@redhat.com> References: <1524054707-20663-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 18 Apr 2018 12:31:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 18 Apr 2018 12:31:55 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v1 for-2.13 3/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: 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. Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/netboot.mak | 5 +- pc-bios/s390-ccw/netmain.c | 203 +++++++++++++++++++++++++++++++++++++++= ++-- 2 files changed, 201 insertions(+), 7 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 e11ed4e..fa62bfe 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)); @@ -276,6 +287,183 @@ static void net_uninit(filename_ip_t *fn_ip) virtio_net_uninit(); } =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)) { + entries[num_entries - 1].kernel =3D arg; + } else if (!strcasecmp("initrd", ptr)) { + entries[num_entries - 1].initrd =3D arg; + } else if (!strcasecmp("append", ptr)) { + 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; + + cfgbuf[sizeof(cfgbuf) - 1] =3D 0; /* Make sure that it is NUL-termin= ated */ + + printf("Trying pxelinux.cfg files...\n"); + + /* Look for config file with MAC address in its name */ + sprintf((char *)fn_ip->filename, + "pxelinux.cfg/%02x-%02x-%02x-%02x-%02x-%02x", + 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; idx <=3D 7; idx++) { + sprintf((char *)fn_ip->filename, + "pxelinux.cfg/%02X%02X%02X%02X", + (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 */ + strcpy((char *)fn_ip->filename, "pxelinux.cfg/default"); + 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 && rc < sizeof(cfgbuf) - 1) { + /* Check whether it is a configuration file instead of a kernel */ + 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); @@ -360,7 +548,12 @@ void main(void) panic("Network initialization failed. Halting.\n"); } =20 - rc =3D tftp_load(&fn_ip, NULL, (long)_start); + if (strlen((char *)fn_ip.filename) > 0) { + rc =3D net_try_direct_tftp_load(&fn_ip); + } + if (rc <=3D 0) { + rc =3D net_try_pxelinux_cfgs(&fn_ip); + } =20 net_uninit(&fn_ip); =20 --=20 1.8.3.1 From nobody Mon Apr 29 12:18:26 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 1524055079813243.8567462543648; Wed, 18 Apr 2018 05:37:59 -0700 (PDT) Received: from localhost ([::1]:54092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8mLX-0004of-06 for importer@patchew.org; Wed, 18 Apr 2018 08:37:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8mFj-0000k5-7g for qemu-devel@nongnu.org; Wed, 18 Apr 2018 08:32:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8mFi-0003KB-1E for qemu-devel@nongnu.org; Wed, 18 Apr 2018 08:31:59 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34642 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 1f8mFh-0003Jp-U4; Wed, 18 Apr 2018 08:31:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F97B8DC34; Wed, 18 Apr 2018 12:31:57 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2EE210F1BEA; Wed, 18 Apr 2018 12:31:55 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Wed, 18 Apr 2018 14:31:47 +0200 Message-Id: <1524054707-20663-5-git-send-email-thuth@redhat.com> In-Reply-To: <1524054707-20663-1-git-send-email-thuth@redhat.com> References: <1524054707-20663-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 18 Apr 2018 12:31:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 18 Apr 2018 12:31:57 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v1 for-2.13 4/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: 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 fa62bfe..e52e17d 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -441,6 +441,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; @@ -455,6 +504,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