From nobody Wed Nov 5 09:21:28 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499423657837976.2578148873229; Fri, 7 Jul 2017 03:34:17 -0700 (PDT) Received: from localhost ([::1]:55501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTQaW-0000Fq-9z for importer@patchew.org; Fri, 07 Jul 2017 06:34:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTQTs-0002iy-J9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 06:27:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTQTq-0001se-Uq for qemu-devel@nongnu.org; Fri, 07 Jul 2017 06:27:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60470) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTQTq-0001sB-LB for qemu-devel@nongnu.org; Fri, 07 Jul 2017 06:27:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E8F1267C9; Fri, 7 Jul 2017 10:27:21 +0000 (UTC) Received: from thh440s.str.redhat.com (dhcp-200-180.str.redhat.com [10.33.200.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 671AF5F912; Fri, 7 Jul 2017 10:27:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9E8F1267C9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=thuth@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9E8F1267C9 From: Thomas Huth To: qemu-devel@nongnu.org, Christian Borntraeger Date: Fri, 7 Jul 2017 12:27:02 +0200 Message-Id: <1499423224-23060-7-git-send-email-thuth@redhat.com> In-Reply-To: <1499423224-23060-1-git-send-email-thuth@redhat.com> References: <1499423224-23060-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 10:27:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH v2 6/8] pc-bios/s390-ccw: Add core files for the network bootloading program 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: Cornelia Huck , Viktor Mihajlovski , Farhan Ali , Alexander Graf , David Hildenbrand 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" This is just a preparation for the next steps: Add a makefile and a stripped down copy of pc-bios/s390-ccw/main.c as a basis for the network bootloader program, linked against the libc from SLOF already (which we will need for SLOF's libnet). The networking code is not included yet. Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/Makefile | 11 +++- pc-bios/s390-ccw/netboot.mak | 41 +++++++++++++ pc-bios/s390-ccw/netmain.c | 140 +++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 pc-bios/s390-ccw/netboot.mak create mode 100644 pc-bios/s390-ccw/netmain.c diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile index 4abe7d3..4e11026 100644 --- a/pc-bios/s390-ccw/Makefile +++ b/pc-bios/s390-ccw/Makefile @@ -16,7 +16,7 @@ QEMU_CFLAGS +=3D -march=3Dz900 -fPIE -fno-strict-aliasing QEMU_CFLAGS +=3D $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector) LDFLAGS +=3D -Wl,-pie -nostdlib =20 -build-all: s390-ccw.img +build-all: s390-ccw.img s390-netboot.img =20 s390-ccw.elf: $(OBJECTS) $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $(OBJECTS),"BUILD","$(TARGET_= DIR)$@") @@ -28,5 +28,12 @@ s390-ccw.img: s390-ccw.elf =20 $(OBJECTS): Makefile =20 +ifneq ($(wildcard $(SRC_PATH)/roms/SLOF/lib/libnet),) +include $(SRC_PATH)/pc-bios/s390-ccw/netboot.mak +else +s390-netboot.img: + @echo "s390-netboot.img not built since roms/SLOF/ is not available." +endif + clean: - rm -f *.o *.d *.img *.elf *~ + $(RM) *.o *.d *.img *.elf *~ *.a diff --git a/pc-bios/s390-ccw/netboot.mak b/pc-bios/s390-ccw/netboot.mak new file mode 100644 index 0000000..1eaa0d8 --- /dev/null +++ b/pc-bios/s390-ccw/netboot.mak @@ -0,0 +1,41 @@ + +SLOF_DIR :=3D $(SRC_PATH)/roms/SLOF + +NETOBJS :=3D start.o sclp.o virtio.o netmain.o sbrk.o libc.a + +LIBC_INC :=3D -I$(SLOF_DIR)/lib/libc/include +LIBNET_INC :=3D -I$(SLOF_DIR)/lib/libnet + +NETLDFLAGS :=3D $(LDFLAGS) -Ttext=3D0x7800000 + +$(NETOBJS): CFLAGS +=3D $(LIBC_INC) $(LIBNET_INC) + +s390-netboot.elf: $(NETOBJS) + $(call quiet-command,$(CC) $(NETLDFLAGS) -o $@ $(NETOBJS),"BUILD","$(TARG= ET_DIR)$@") + +s390-netboot.img: s390-netboot.elf + $(call quiet-command,$(STRIP) --strip-unneeded $< -o $@,"STRIP","$(TARGET= _DIR)$@") + + +LIBCCMNDIR =3D $(SLOF_DIR)/lib/libc +STRINGCMNDIR =3D $(LIBCCMNDIR)/string +CTYPECMNDIR =3D $(LIBCCMNDIR)/ctype +STDLIBCMNDIR =3D $(LIBCCMNDIR)/stdlib +STDIOCMNDIR =3D $(LIBCCMNDIR)/stdio + +include $(STRINGCMNDIR)/Makefile.inc +include $(CTYPECMNDIR)/Makefile.inc +include $(STDLIBCMNDIR)/Makefile.inc +include $(STDIOCMNDIR)/Makefile.inc + +STDIO_OBJS =3D sprintf.o vfprintf.o vsnprintf.o vsprintf.o fprintf.o \ + printf.o putc.o puts.o putchar.o stdchnls.o fileno.o + +LIBCOBJS :=3D $(STRING_OBJS) $(CTYPE_OBJS) $(STDLIB_OBJS) $(STDIO_OBJS) +$(LIBCOBJS): CFLAGS +=3D $(LIBC_INC) $(QEMU_CFLAGS) + +libc.a: $(LIBCOBJS) + $(call quiet-command,$(AR) -rc $@ $^,"AR","$(TARGET_DIR)$@") + +sbrk.o: $(SLOF_DIR)/slof/sbrk.c + $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(LIBC_INC) -c -o $@ $<,"CC","$= (TARGET_DIR)$@") diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c new file mode 100644 index 0000000..fcdd7a1 --- /dev/null +++ b/pc-bios/s390-ccw/netmain.c @@ -0,0 +1,140 @@ +/* + * S390 virtio-ccw network boot loading program + * + * Copyright 2017 Thomas Huth, Red Hat Inc. + * + * Based on the S390 virtio-ccw loading program (main.c) + * Copyright (c) 2013 Alexander Graf + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "s390-ccw.h" +#include "virtio.h" + +extern char _start[]; + +char stack[PAGE_SIZE * 8] __attribute__((aligned(PAGE_SIZE))); +IplParameterBlock iplb __attribute__((aligned(PAGE_SIZE))); + +static SubChannelId blk_schid =3D { .one =3D 1 }; +static uint64_t dest_timer; + +static uint64_t get_timer_ms(void) +{ + uint64_t clk; + + asm volatile(" stck %0 " : : "Q"(clk) : "memory"); + + /* Bit 51 is incrememented each microsecond */ + return (clk >> (63 - 51)) / 1000; +} + +void set_timer(int val) +{ + dest_timer =3D get_timer_ms() + val; +} + +int get_timer(void) +{ + return dest_timer - get_timer_ms(); +} + +int get_sec_ticks(void) +{ + return 1000; /* number of ticks in 1 second */ +} + +void panic(const char *string) +{ + sclp_print(string); + for (;;) { + disabled_wait(); + } +} + +static bool find_dev(Schib *schib, int dev_no) +{ + int i, r; + + for (i =3D 0; i < 0x10000; i++) { + blk_schid.sch_no =3D i; + r =3D stsch_err(blk_schid, schib); + if (r =3D=3D 3 || r =3D=3D -EIO) { + break; + } + if (!schib->pmcw.dnv) { + continue; + } + if (!virtio_is_supported(blk_schid)) { + continue; + } + /* Skip net devices since no IPLB is created and therefore no + * no network bootloader has been loaded + */ + if (virtio_get_device_type() =3D=3D VIRTIO_ID_NET && dev_no < 0) { + continue; + } + if (dev_no < 0 || schib->pmcw.dev =3D=3D dev_no) { + return true; + } + } + + return false; +} + +static void virtio_setup(void) +{ + Schib schib; + int ssid; + bool found =3D false; + uint16_t dev_no; + + /* + * We unconditionally enable mss support. In every sane configuration, + * this will succeed; and even if it doesn't, stsch_err() can deal + * with the consequences. + */ + enable_mss_facility(); + + if (store_iplb(&iplb)) { + IPL_assert(iplb.pbt =3D=3D S390_IPL_TYPE_CCW, "IPL_TYPE_CCW expect= ed"); + dev_no =3D iplb.ccw.devno; + debug_print_int("device no. ", dev_no); + blk_schid.ssid =3D iplb.ccw.ssid & 0x3; + debug_print_int("ssid ", blk_schid.ssid); + found =3D find_dev(&schib, dev_no); + } else { + for (ssid =3D 0; ssid < 0x3; ssid++) { + blk_schid.ssid =3D ssid; + found =3D find_dev(&schib, -1); + if (found) { + break; + } + } + } + + IPL_assert(found && virtio_get_device_type() =3D=3D VIRTIO_ID_NET, + "No virtio net device found"); +} + +void main(void) +{ + sclp_setup(); + sclp_print("Network boot starting...\n"); + + virtio_setup(); + + panic("Failed to load OS from network\n"); +} --=20 1.8.3.1