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: 40577 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 833B3218DE for ; Tue, 11 Nov 2014 14:42:31 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id n15sf5443302lbi.2 for ; Tue, 11 Nov 2014 06:42:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:subject:to:cc :in-reply-to:references:date:message-id:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Xpv0zfEL7oUO4IIp0dFUcLJwdYKvCHv2q82IrMQrO1w=; b=XfMUIxGtrVQzLTLqjKE0lh6qTwCyaqNH9StdXluoyOPrwgI3FM2QFknY4922vmgOXI 2R5ttc7rubYLUxw6F1Yt2ctmTYNScjLMPqzdm+TgZgWF/pBFphrXROlkDh6oeEw0Wkgq +tpY8LShwS3cKirLfiXt32kQ3wevrE6SZ0vMXhyAfnR9sQGo/AzfzJtq/0yxydlaEZmn wMomn9laHO5s7vAl8T1VIe6yaWcKB7xZA45oEogelweodBEM8XkPnrCS3O8oTnDoSY5f kIzlDKch5VlvIX94PSpGzvH5Wyfqk/fvWEcC/IpcLAbxSleo3txXj+ByNaYH1R5qQEy3 21nQ== X-Gm-Message-State: ALoCoQm0NYcMLd7FRFwbdwK07/enfGQcb7P1hnKtpWwnhKiB1Uz81AmA8A/oO7yP8prM2O98hOvD X-Received: by 10.180.76.168 with SMTP id l8mr2256225wiw.1.1415716950442; Tue, 11 Nov 2014 06:42:30 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.80 with SMTP id be16ls466008lab.97.gmail; Tue, 11 Nov 2014 06:42:30 -0800 (PST) X-Received: by 10.112.137.39 with SMTP id qf7mr36162105lbb.47.1415716950278; Tue, 11 Nov 2014 06:42:30 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id l8si31669451lbj.60.2014.11.11.06.42.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 06:42:30 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id l4so7846983lbv.12 for ; Tue, 11 Nov 2014 06:42:30 -0800 (PST) X-Received: by 10.112.189.10 with SMTP id ge10mr36179941lbc.23.1415716950126; Tue, 11 Nov 2014 06:42:30 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp265686lbc; Tue, 11 Nov 2014 06:42:29 -0800 (PST) X-Received: by 10.69.20.74 with SMTP id ha10mr40430042pbd.122.1415716948258; Tue, 11 Nov 2014 06:42:28 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zj3si1622694pac.64.2014.11.11.06.42.27 for ; Tue, 11 Nov 2014 06:42:28 -0800 (PST) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751633AbaKKOm0 (ORCPT + 4 others); Tue, 11 Nov 2014 09:42:26 -0500 Received: from mail-wg0-f44.google.com ([74.125.82.44]:54210 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751589AbaKKOm0 (ORCPT ); Tue, 11 Nov 2014 09:42:26 -0500 Received: by mail-wg0-f44.google.com with SMTP id x12so11757840wgg.3 for ; Tue, 11 Nov 2014 06:42:24 -0800 (PST) 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 Cc: Ard Biesheuvel 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> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grant.likely@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 > -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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; }