From patchwork Wed Dec 8 15:11:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 1565254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1OLNi/uk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=axis.com header.i=@axis.com header.a=rsa-sha256 header.s=axis-central1 header.b=cpqvQoxj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J8LH60C82z9tk5 for ; Thu, 9 Dec 2021 02:11:46 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sJZltJnopqsKs7dZ3ETgEGzDL53Cc6ASIXDthnVQW0U=; b=1OLNi/ukswPsBd vFHBni2hDI2fEx1Trl/6IXkQ0LccBCL76FQEzmdaENVTnHvJ0XljHJjna5D/cw6BmzB29rbBAd5CG ZkhhGely/vvb64ZhDe2IAzjTUjK90ws5Gpb0OgzbOGQuYNp4LvnRUlpeBfbAiHeyinsCKbAZ5xjY9 sPu4w1Tlneb5RU9vMrKfLBx+Iuraf+N0Qc6UOvzflS2NCGk6UO1jgOOOX9sxImpaVtRtkrMquAbY2 Uj0OmK9rizTAL2c2ui7XQ3sjNr/VTQ5eAd0fKC5kjtvpSpnR+sMM7135pt9IGDMFlxopx0se00Itm ykTcgLB71oMjaJWZs2gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muybX-00D6wd-1B; Wed, 08 Dec 2021 15:11:35 +0000 Received: from smtp2.axis.com ([195.60.68.18]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1muybT-00D6ta-Hj for linux-um@lists.infradead.org; Wed, 08 Dec 2021 15:11:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1638976291; x=1670512291; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VrsMtFlyBxgWCf0bvKnofWFvEDY3FGaJ9B55+Jf6Fi0=; b=cpqvQoxjWdW0+cuVGbJ2w0LKZzMENKd2noKfVwvIUB0LoaFdL4/sw7dS 7MUgTubVRHz1Ll7o0DdD5QihXgiaqcDCP0Vxd0z85YfKKtL54q5VddE+9 za0EyAbjmCWha1ly6FbZ1Svxns9tS619oGOKox79uREhxNlnsU7Zy2HCB o2hYI6vS1FySKTwZUM42Htt9QawnM/v3Tsvpypv0aDdpZynZM8wgWDzEa Api1/bF/2WHFhV5jsDdWAuOEVjSnixDZLwP6ovo1btnH3TdHNfudDViaT 9mB2g31ty7esSycK9OTjWzAdzPnli1E95tCiU5zU8D+k0oGCbUEMijR13 Q==; From: Vincent Whitchurch To: , , CC: , , , , Vincent Whitchurch Subject: [PATCH 2/2] um: Add devicetree support Date: Wed, 8 Dec 2021 16:11:23 +0100 Message-ID: <20211208151123.29313-3-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211208151123.29313-1-vincent.whitchurch@axis.com> References: <20211208151123.29313-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211208_071131_970080_DABFF60B X-CRM114-Status: GOOD ( 15.22 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a dtb= option to boot UML with a devicetree blob. This can be used for testing driver code using UML. Signed-off-by: Vincent Whitchurch --- arch/um/Kconfig | 1 + arch/um/kernel/Makefile | 1 + arch/um/kernel/dtb.c | 41 ++++++++++++++++++++++++++++++++++++++++ arch/um/kerne [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [195.60.68.18 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a dtb= option to boot UML with a devicetree blob. This can be used for testing driver code using UML. Signed-off-by: Vincent Whitchurch --- arch/um/Kconfig | 1 + arch/um/kernel/Makefile | 1 + arch/um/kernel/dtb.c | 41 ++++++++++++++++++++++++++++++++++++++++ arch/um/kernel/um_arch.c | 3 +++ arch/um/kernel/um_arch.h | 6 ++++++ 5 files changed, 52 insertions(+) create mode 100644 arch/um/kernel/dtb.c diff --git a/arch/um/Kconfig b/arch/um/Kconfig index c18b45f75d41..1cf7ef3a2b81 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -18,6 +18,7 @@ config UML select HAVE_DEBUG_KMEMLEAK select HAVE_DEBUG_BUGVERBOSE select NO_DMA if !UML_DMA_EMULATION + select OF_EARLY_FLATTREE select GENERIC_IRQ_SHOW select GENERIC_CPU_DEVICES select HAVE_GCC_PLUGINS diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index 92692bfef7ae..ebd0cca3ff26 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -22,6 +22,7 @@ obj-y += load_file.o obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o obj-$(CONFIG_GPROF) += gprof_syms.o +obj-$(CONFIG_OF) += dtb.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_GENERIC_PCI_IOMAP) += ioport.o diff --git a/arch/um/kernel/dtb.c b/arch/um/kernel/dtb.c new file mode 100644 index 000000000000..ca69d72025f3 --- /dev/null +++ b/arch/um/kernel/dtb.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include + +#include "um_arch.h" + +static char *dtb __initdata; + +void uml_dtb_init(void) +{ + long long size; + void *area; + + area = uml_load_file(dtb, &size); + if (!area) + return; + + if (!early_init_dt_scan(area)) { + pr_err("invalid DTB %s\n", dtb); + memblock_free(area, size); + return; + } + + unflatten_device_tree(); + early_init_fdt_scan_reserved_mem(); +} + +static int __init uml_dtb_setup(char *line, int *add) +{ + dtb = line; + return 0; +} + +__uml_setup("dtb=", uml_dtb_setup, +"dtb=\n" +" Boot the kernel with the devicetree blob from the specified file.\n" +); diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index 54447690de11..abceeabe29b9 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -29,6 +29,8 @@ #include #include +#include "um_arch.h" + #define DEFAULT_COMMAND_LINE_ROOT "root=98:0" #define DEFAULT_COMMAND_LINE_CONSOLE "console=tty" @@ -407,6 +409,7 @@ void __init setup_arch(char **cmdline_p) stack_protections((unsigned long) &init_thread_info); setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem); mem_total_pages(physmem_size, iomem_size, highmem); + uml_dtb_init(); read_initrd(); paging_init(); diff --git a/arch/um/kernel/um_arch.h b/arch/um/kernel/um_arch.h index b195df3a09a0..1e07fb7ee35e 100644 --- a/arch/um/kernel/um_arch.h +++ b/arch/um/kernel/um_arch.h @@ -5,4 +5,10 @@ extern void * __init uml_load_file(const char *filename, unsigned long long *size); +#ifdef CONFIG_OF +extern void __init uml_dtb_init(void); +#else +static inline void uml_dtb_init(void) { } +#endif + #endif