From patchwork Tue Nov 11 14:42:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 5275101 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CF8AA9F387 for ; Tue, 11 Nov 2014 14:44:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D04F520142 for ; Tue, 11 Nov 2014 14:44:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF5C72013A for ; Tue, 11 Nov 2014 14:44:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XoCeh-0007A1-Ij; Tue, 11 Nov 2014 14:42:51 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XoCed-00071d-FF for linux-arm-kernel@lists.infradead.org; Tue, 11 Nov 2014 14:42:48 +0000 Received: by mail-wg0-f49.google.com with SMTP id x13so11629770wgg.22 for ; Tue, 11 Nov 2014 06:42:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:subject:to:cc:in-reply-to:references :date:message-id; bh=bGbz+/Ona05MUgaqK7ics7GgV1geF9n2tsqRsZKCATs=; b=ZJOizfBn6T9rZKhugjoksOQ8unj//35mScCibxoSpc92CyTMs92KMDIYc0yjm6v9Lz MqX7Cz7yC3UBXb2waEDJih3zN/BlA96xcTpxEUmiofWddV7T9XZ7IYA4ztJ7SReCAs0f 2tfLDjUlFhPfntgU32L2T9iiJ5jcCKqXJhzZAVaFLRfl44ZmtxB+OSePoKBDEKnpawZZ Ofyz+a1bGo/LQnBRkrE/+U6ZPahb+Sb8b3EjyLnUVxHDoNiuyzmZ4QHp5q3TyZYbwCMy H7bSnk10E8HexlbT9sq/1NK2O92hFOw+2lTTCAX58MA42aNts0o/EoSB9/3TEnReVR29 Vmaw== X-Gm-Message-State: ALoCoQnjsdSK8qiG4jxo5eOrVHccELvLoV+rJcZR/j4DLFW6imStVWFrmQijoygoJjvtOEkqtfzp X-Received: by 10.194.158.193 with SMTP id ww1mr29415828wjb.65.1415716944793; Tue, 11 Nov 2014 06:42:24 -0800 (PST) Received: from trevor.secretlab.ca (host86-166-83-112.range86-166.btcentralplus.com. [86.166.83.112]) by mx.google.com with ESMTPSA id bl9sm17718855wib.24.2014.11.11.06.42.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Nov 2014 06:42:23 -0800 (PST) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 5FCDAC416AF; Tue, 11 Nov 2014 14:42:21 +0000 (GMT) From: Grant Likely Subject: Re: [PATCH v2 1/2] of/fdt: export fdt blob as /sys/firmware/fdt To: Ard Biesheuvel , leif.lindholm@linaro.org, geoff.levand@linaro.org, mark.rutland@arm.com, rob.herring@linaro.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org In-Reply-To: <1415645222-14909-2-git-send-email-ard.biesheuvel@linaro.org> References: <1415645222-14909-1-git-send-email-ard.biesheuvel@linaro.org> <1415645222-14909-2-git-send-email-ard.biesheuvel@linaro.org> Date: Tue, 11 Nov 2014 14:42:21 +0000 Message-Id: <20141111144221.5FCDAC416AF@trevor.secretlab.ca> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141111_064247_816079_4237167D X-CRM114-Status: GOOD ( 19.06 ) X-Spam-Score: -0.7 (/) Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 10 Nov 2014 19:47:01 +0100 , Ard Biesheuvel wrote: > Create a new /sys entry '/sys/firmware/fdt' to export the FDT blob > that was passed to the kernel by the bootloader. This allows userland > applications such as kexec to access the raw binary. The blob needs to > be preserved as early as possible by calling preserve_fdt(). > > The fact that this node does not reside under /sys/firmware/device-tree > is deliberate: FDT is also used on arm64 UEFI/ACPI systems to > communicate just the UEFI and ACPI entry points, but the FDT is never > unflattened and used to configure the system. > > Signed-off-by: Ard Biesheuvel On further thought, nak. I want tree modifications to be treated as bugs. Do a checksum CRC32 or check. It's simpler and it can be extended to us an in-blob CRC when the file format gets upreved to include one. g. --- > --- > drivers/of/fdt.c | 34 ++++++++++++++++++++++++++++++++++ > include/linux/of_fdt.h | 2 ++ > 2 files changed, 36 insertions(+) > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index d1ffca8b34ea..e9ee3d5f7ea4 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -22,6 +22,7 @@ > #include > #include > #include > +#include > > #include /* for COMMAND_LINE_SIZE */ > #include > @@ -1103,4 +1104,37 @@ static int __init of_flat_dt_debugfs_export_fdt(void) > module_init(of_flat_dt_debugfs_export_fdt); > #endif > > +static u8 *raw_fdt_copy; > + > +void __init preserve_fdt(void) > +{ > + u32 fdt_size; > + > + fdt_size = fdt_totalsize(initial_boot_params); > + raw_fdt_copy = memcpy(__va(memblock_alloc(fdt_size, PAGE_SIZE)), > + initial_boot_params, fdt_size); > +} > + > +#ifdef CONFIG_SYSFS > +static ssize_t of_fdt_raw_read(struct file *filp, struct kobject *kobj, > + struct bin_attribute *bin_attr, > + char *buf, loff_t off, size_t count) > +{ > + memcpy(buf, raw_fdt_copy + off, count); > + return count; > +} > + > +static int __init of_fdt_raw_init(void) > +{ > + static struct bin_attribute of_fdt_raw_attr = > + __BIN_ATTR(fdt, S_IRUSR, of_fdt_raw_read, NULL, 0); > + > + if (!raw_fdt_copy) > + return 0; > + of_fdt_raw_attr.size = fdt_totalsize(raw_fdt_copy); > + return sysfs_create_bin_file(firmware_kobj, &of_fdt_raw_attr); > +} > +module_init(of_fdt_raw_init); > +#endif > + > #endif /* CONFIG_OF_EARLY_FLATTREE */ > diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h > index 0ff360d5b3b3..7672a26305a5 100644 > --- a/include/linux/of_fdt.h > +++ b/include/linux/of_fdt.h > @@ -83,6 +83,7 @@ extern const void *of_flat_dt_match_machine(const void *default_match, > /* Other Prototypes */ > extern void unflatten_device_tree(void); > extern void unflatten_and_copy_device_tree(void); > +extern void preserve_fdt(void); > extern void early_init_devtree(void *); > extern void early_get_first_memblock_info(void *, phys_addr_t *); > extern u64 fdt_translate_address(const void *blob, int node_offset); > @@ -92,6 +93,7 @@ static inline void early_init_fdt_scan_reserved_mem(void) {} > static inline const char *of_flat_dt_get_machine_name(void) { return NULL; } > static inline void unflatten_device_tree(void) {} > static inline void unflatten_and_copy_device_tree(void) {} > +static inline void preserve_fdt(void) {} > #endif /* CONFIG_OF_FLATTREE */ > > #endif /* __ASSEMBLY__ */ > -- > 1.8.3.2 > diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index be16ce2ffd69..adda0a16934f 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -23,6 +23,7 @@ config OF_FLATTREE bool select DTC select LIBFDT + select CRC config OF_EARLY_FLATTREE bool diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 83a8e1154602..80db46a2eab9 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -420,6 +421,7 @@ int __initdata dt_root_addr_cells; int __initdata dt_root_size_cells; void *initial_boot_params; +u32 initial_boot_params_crc; #ifdef CONFIG_OF_EARLY_FLATTREE @@ -1003,6 +1005,9 @@ bool __init early_init_dt_verify(void *params) /* Setup flat device-tree pointer */ initial_boot_params = params; + initial_boot_params_crc = crc32_be(0, params, fdt_totalsize(params)); + pr_info("FDT CRC: %x\n", initial_boot_params_crc); + return true; }