From patchwork Tue Nov 11 15:25:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 40581 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6E652241C9 for ; Tue, 11 Nov 2014 15:25:56 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id k14sf5503102wgh.11 for ; Tue, 11 Nov 2014 07:25:55 -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=bq+h12XV5JcEWhIdp2PZmCfgZ+UniqfI5KEeShk55EI=; b=D9UVPcjhi2A4bpb9NAPxJWcswolRcr9/yHdv+r6f7v1ddjPknRFMXMbsFXbSxncuFi 6oPyDGnue2sfo9urjeidirHPrVEbsnjarpjHuS4QXsFrzEG++SNqRQ4H2MnLB9ypd1qY XbCNdHuf6gujwbq4+FCyteAmJHxwtaXmPa2XzeyKcDnr5fAfTPMIkwGPb3ZWeYx7OBMG RsUII4raOHPBjcuclFHYy8fhrULtCc6+yvPaYEgv0girQkuKfcOk/0rGFOBg0+vLwKFG 3vAW4HiRFavzfk+dSbSEnN59V9rsCUuqIUHaTpxhWwB7F2zrjJDxUemqa+0rcCwDwTQF D1Ww== X-Gm-Message-State: ALoCoQmQteHHOc70iM3uSt11u725QKXV47IcmiGcRJ3Fusv8fVav8tJAOW3rlNq8TNUDhT5dyoYm X-Received: by 10.152.6.4 with SMTP id w4mr534995law.7.1415719555691; Tue, 11 Nov 2014 07:25:55 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.165 with SMTP id an5ls616599lac.92.gmail; Tue, 11 Nov 2014 07:25:55 -0800 (PST) X-Received: by 10.112.87.65 with SMTP id v1mr23241102lbz.12.1415719555273; Tue, 11 Nov 2014 07:25:55 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id u1si31754750lbb.79.2014.11.11.07.25.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 07:25:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id b6so7700508lbj.2 for ; Tue, 11 Nov 2014 07:25:55 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr36190087laz.27.1415719555146; Tue, 11 Nov 2014 07:25:55 -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 ew9csp273575lbc; Tue, 11 Nov 2014 07:25:54 -0800 (PST) X-Received: by 10.68.162.161 with SMTP id yb1mr40456076pbb.53.1415719553539; Tue, 11 Nov 2014 07:25:53 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gw4si20200134pbb.172.2014.11.11.07.25.52 for ; Tue, 11 Nov 2014 07:25:53 -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 S1751344AbaKKPZw (ORCPT + 4 others); Tue, 11 Nov 2014 10:25:52 -0500 Received: from mail-wi0-f174.google.com ([209.85.212.174]:47475 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097AbaKKPZv (ORCPT ); Tue, 11 Nov 2014 10:25:51 -0500 Received: by mail-wi0-f174.google.com with SMTP id d1so1995039wiv.7 for ; Tue, 11 Nov 2014 07:25:50 -0800 (PST) X-Received: by 10.194.184.75 with SMTP id es11mr54454733wjc.35.1415719550650; Tue, 11 Nov 2014 07:25:50 -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 gs9sm27650963wjc.47.2014.11.11.07.25.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 07:25:49 -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 v3] of/fdt: export fdt blob as /sys/firmware/fdt Date: Tue, 11 Nov 2014 16:25:46 +0100 Message-Id: <1415719546-14076-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.171 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 --- v3: keep checksum instead of copying the entire blob, and WARN on mismatch drivers/of/Kconfig | 1 + drivers/of/fdt.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 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..6742b6ae1b89 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,27 @@ 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 (WARN(of_fdt_crc32 != of_fdt_get_crc32(initial_boot_params), + "CRC check failed on binary FDT")) + return -EFAULT; + 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 */