From patchwork Wed Nov 12 12:28:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 40665 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 255D024493 for ; Wed, 12 Nov 2014 12:28:36 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id c41sf8023149eek.8 for ; Wed, 12 Nov 2014 04:28:35 -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:to:cc:subject :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=qN3U8EGfd0VTmQgHHxg0hshJRs8l+Je98U3e9+j5Lls=; b=hl5VYDQv3qm4ESNVVUx1C0ygjQkwuzrESS6oSjy74Zr9s5czOrPGS4GtRC4m/ahJxV 1UX+nNeq+12B8oyZUzztN2GDAgCCSxNQ1CBNIq0j71RcrOtvQUghf567XEd+ptr8kQe4 ahdaCYFQf9sm3FskCPe/RfW1qlsds3ptIwUK1M+x+/1IO8eb8+pJatG4MmNOxcTfNSc2 KS8XgYEmxJPj37Q/cPlwvT16LtExROx2p1KG8NFeLKx/vhrNB5Tk9gR/lXR93TdRovDu 6YOsjJ+eRloYBOBm8J/vCm/MRPNFAiNFIXD7WZgfU+r12MoNxFSDg+u5Tczx5jN1Ai0D q5tQ== X-Gm-Message-State: ALoCoQnN26iTa+iimC2HlHi+XQk9uxX9m+wBgM9PI1732McYhCY9MTFvUxFGIqcdd7EdoSvtFMWs X-Received: by 10.152.6.4 with SMTP id w4mr337566law.7.1415795315285; Wed, 12 Nov 2014 04:28:35 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.228.140 with SMTP id si12ls668685lac.25.gmail; Wed, 12 Nov 2014 04:28:34 -0800 (PST) X-Received: by 10.152.28.227 with SMTP id e3mr42493129lah.54.1415795314894; Wed, 12 Nov 2014 04:28:34 -0800 (PST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id xc4si34711826lbb.82.2014.11.12.04.28.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 04:28:34 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id 10so9055710lbg.7 for ; Wed, 12 Nov 2014 04:28:34 -0800 (PST) X-Received: by 10.112.202.104 with SMTP id kh8mr42209134lbc.46.1415795314430; Wed, 12 Nov 2014 04:28:34 -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 ew9csp413991lbc; Wed, 12 Nov 2014 04:28:33 -0800 (PST) X-Received: by 10.70.31.2 with SMTP id w2mr19359993pdh.128.1415795312460; Wed, 12 Nov 2014 04:28:32 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pq10si22743634pdb.99.2014.11.12.04.28.31 for ; Wed, 12 Nov 2014 04:28:32 -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 S1752005AbaKLM2b (ORCPT + 4 others); Wed, 12 Nov 2014 07:28:31 -0500 Received: from mail-wg0-f51.google.com ([74.125.82.51]:59477 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751507AbaKLM2a (ORCPT ); Wed, 12 Nov 2014 07:28:30 -0500 Received: by mail-wg0-f51.google.com with SMTP id l18so13887436wgh.38 for ; Wed, 12 Nov 2014 04:28:29 -0800 (PST) X-Received: by 10.194.89.129 with SMTP id bo1mr11334621wjb.29.1415795309422; Wed, 12 Nov 2014 04:28:29 -0800 (PST) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id ce16sm12447201wjb.34.2014.11.12.04.28.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 04:28:28 -0800 (PST) From: Ard Biesheuvel To: grant.likely@linaro.org, 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 Subject: [PATCH v4] of/fdt: export fdt blob as /sys/firmware/fdt Date: Wed, 12 Nov 2014 13:28:28 +0100 Message-Id: <1415795308-14639-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 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: ard.biesheuvel@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.176 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: , 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 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. A CRC32 checksum is calculated over the entire FDT blob, and verified at late_initcall time. The sysfs entry is instantiated only if the checksum is valid, i.e., if the FDT blob has not been modified in the mean time. Otherwise, a warning is printed. Signed-off-by: Ard Biesheuvel --- v4: use pr_warn() instead of WARN() v3: keep checksum instead of copying the entire blob, and WARN on mismatch drivers/of/Kconfig | 1 + drivers/of/fdt.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 1a13f5b722c5..0348c208343c 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -23,6 +23,7 @@ config OF_FLATTREE bool select DTC select LIBFDT + select CRC32 config OF_EARLY_FLATTREE bool diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d1ffca8b34ea..0004871ebccf 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -9,6 +9,7 @@ * version 2 as published by the Free Software Foundation. */ +#include #include #include #include @@ -22,10 +23,20 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include +static u32 of_fdt_crc32; + +static u32 of_fdt_get_crc32(void *fdt) +{ + static u32 const OF_FDT_CRC32_SEED = 0x04c11db7; + + return crc32_be(OF_FDT_CRC32_SEED, fdt, fdt_totalsize(fdt)); +} + /* * of_fdt_limit_memory - limit the number of regions in the /memory node * @limit: maximum entries @@ -1003,6 +1014,8 @@ bool __init early_init_dt_verify(void *params) return false; } + of_fdt_crc32 = of_fdt_get_crc32(initial_boot_params); + return true; } @@ -1103,4 +1116,28 @@ static int __init of_flat_dt_debugfs_export_fdt(void) module_init(of_flat_dt_debugfs_export_fdt); #endif +#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, initial_boot_params + 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 (of_fdt_crc32 != of_fdt_get_crc32(initial_boot_params)) { + pr_warn("fdt: not creating '/sys/firmware/fdt': CRC check failed"); + return 0; + } + of_fdt_raw_attr.size = fdt_totalsize(initial_boot_params); + return sysfs_create_bin_file(firmware_kobj, &of_fdt_raw_attr); +} +late_initcall(of_fdt_raw_init); +#endif + #endif /* CONFIG_OF_EARLY_FLATTREE */