From patchwork Mon Jul 10 15:32:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 9833281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6721760350 for ; Mon, 10 Jul 2017 15:39:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56A071FEBB for ; Mon, 10 Jul 2017 15:39:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 499E822B26; Mon, 10 Jul 2017 15:39:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6CE471FEBB for ; Mon, 10 Jul 2017 15:39:48 +0000 (UTC) Received: from localhost ([::1]:41439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUamp-00015B-LR for patchwork-qemu-devel@patchwork.kernel.org; Mon, 10 Jul 2017 11:39:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55241) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUagV-0005Ag-N4 for qemu-devel@nongnu.org; Mon, 10 Jul 2017 11:33:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUagU-000371-Bc for qemu-devel@nongnu.org; Mon, 10 Jul 2017 11:33:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUagU-00035Y-2s for qemu-devel@nongnu.org; Mon, 10 Jul 2017 11:33:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2AB180481; Mon, 10 Jul 2017 15:33:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E2AB180481 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=thuth@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E2AB180481 Received: from thh440s.str.redhat.com (reserved-198-123.str.redhat.com [10.33.198.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E49C182DA; Mon, 10 Jul 2017 15:33:10 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Christian Borntraeger , Cornelia Huck Date: Mon, 10 Jul 2017 17:32:38 +0200 Message-Id: <1499700760-4777-9-git-send-email-thuth@redhat.com> In-Reply-To: <1499700760-4777-1-git-send-email-thuth@redhat.com> References: <1499700760-4777-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 10 Jul 2017 15:33:13 +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] [PATCH v3 08/10] 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: Alexey Kardashevskiy , Viktor Mihajlovski , Farhan Ali , Alexander Graf , David Hildenbrand Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 82b41ef..cbae745 100644 --- a/pc-bios/s390-ccw/Makefile +++ b/pc-bios/s390-ccw/Makefile @@ -16,7 +16,7 @@ QEMU_CFLAGS += -march=z900 -fPIE -fno-strict-aliasing QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector) LDFLAGS += -Wl,-pie -nostdlib -build-all: s390-ccw.img +build-all: s390-ccw.img s390-netboot.img s390-ccw.elf: $(OBJECTS) $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $(OBJECTS),"BUILD","$(TARGET_DIR)$@") @@ -28,5 +28,12 @@ s390-ccw.img: s390-ccw.elf $(OBJECTS): Makefile +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 := $(SRC_PATH)/roms/SLOF + +NETOBJS := start.o sclp.o virtio.o netmain.o sbrk.o libc.a + +LIBC_INC := -I$(SLOF_DIR)/lib/libc/include +LIBNET_INC := -I$(SLOF_DIR)/lib/libnet + +NETLDFLAGS := $(LDFLAGS) -Ttext=0x7800000 + +$(NETOBJS): CFLAGS += $(LIBC_INC) $(LIBNET_INC) + +s390-netboot.elf: $(NETOBJS) + $(call quiet-command,$(CC) $(NETLDFLAGS) -o $@ $(NETOBJS),"BUILD","$(TARGET_DIR)$@") + +s390-netboot.img: s390-netboot.elf + $(call quiet-command,$(STRIP) --strip-unneeded $< -o $@,"STRIP","$(TARGET_DIR)$@") + + +LIBCCMNDIR = $(SLOF_DIR)/lib/libc +STRINGCMNDIR = $(LIBCCMNDIR)/string +CTYPECMNDIR = $(LIBCCMNDIR)/ctype +STDLIBCMNDIR = $(LIBCCMNDIR)/stdlib +STDIOCMNDIR = $(LIBCCMNDIR)/stdio + +include $(STRINGCMNDIR)/Makefile.inc +include $(CTYPECMNDIR)/Makefile.inc +include $(STDLIBCMNDIR)/Makefile.inc +include $(STDIOCMNDIR)/Makefile.inc + +STDIO_OBJS = sprintf.o vfprintf.o vsnprintf.o vsprintf.o fprintf.o \ + printf.o putc.o puts.o putchar.o stdchnls.o fileno.o + +LIBCOBJS := $(STRING_OBJS) $(CTYPE_OBJS) $(STDLIB_OBJS) $(STDIO_OBJS) +$(LIBCOBJS): CFLAGS += $(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 = { .one = 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 = 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 = 0; i < 0x10000; i++) { + blk_schid.sch_no = i; + r = stsch_err(blk_schid, schib); + if (r == 3 || r == -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() == VIRTIO_ID_NET && dev_no < 0) { + continue; + } + if (dev_no < 0 || schib->pmcw.dev == dev_no) { + return true; + } + } + + return false; +} + +static void virtio_setup(void) +{ + Schib schib; + int ssid; + bool found = 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 == S390_IPL_TYPE_CCW, "IPL_TYPE_CCW expected"); + dev_no = iplb.ccw.devno; + debug_print_int("device no. ", dev_no); + blk_schid.ssid = iplb.ccw.ssid & 0x3; + debug_print_int("ssid ", blk_schid.ssid); + found = find_dev(&schib, dev_no); + } else { + for (ssid = 0; ssid < 0x3; ssid++) { + blk_schid.ssid = ssid; + found = find_dev(&schib, -1); + if (found) { + break; + } + } + } + + IPL_assert(found && virtio_get_device_type() == 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"); +}