From patchwork Wed Nov 12 16:59:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 40694 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 CCCBF24493 for ; Wed, 12 Nov 2014 21:20:52 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id c41sf8636738eek.0 for ; Wed, 12 Nov 2014 13:20:52 -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=bwFt0d6Lvv/C/+FybgirGmWXaIVJuA+RpSNbDeQlWWU=; b=VZsi+tQR1uTZs/vzQ0fA9Hxqy8jl0xD76m5NfGUrW53Yrv3PuGOFaMTeYjUghm7Gv7 aFB1Tko8ZokQzWusm79/uYgNul1T3f6mm41Kv7SgZKC64dWRcuEcI0X+zYBWr+Hm6xxl J+EAYfUQOEh/S/htrTdcti8Go5GQTcmsQxyc7/JUiDV1fuQuciOzk4eGkEU1mDaPaLia SJelxMRKYR5t7mzmprxd/9IoNElvY3wsIxublIbmqkjXvkcSlRZ5ahnOxaLzyRJTsrvU L8L8TWs7mC0sDNhp5HHDDlJHM3N7qteJzSuXcRHXKAcfz7hqnWLEK1c5+ECyMKqMmenO bu6g== X-Gm-Message-State: ALoCoQmM43C1RvsiGcFC7UzAp3OOGeh0CdCrlvb3CoRTaaE+NeGiaT3IpxXNvNJpvGjOIl9Enqmv X-Received: by 10.152.30.66 with SMTP id q2mr8391277lah.2.1415827251939; Wed, 12 Nov 2014 13:20:51 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.39 with SMTP id b7ls635958lae.38.gmail; Wed, 12 Nov 2014 13:20:51 -0800 (PST) X-Received: by 10.152.1.130 with SMTP id 2mr4446105lam.89.1415827251690; Wed, 12 Nov 2014 13:20:51 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id 9si36258098law.76.2014.11.12.13.20.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 13:20:51 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id q1so12020433lam.24 for ; Wed, 12 Nov 2014 13:20:51 -0800 (PST) X-Received: by 10.152.116.102 with SMTP id jv6mr24614515lab.40.1415827251576; Wed, 12 Nov 2014 13:20:51 -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 ew9csp495068lbc; Wed, 12 Nov 2014 13:20:50 -0800 (PST) X-Received: by 10.68.68.240 with SMTP id z16mr50141992pbt.70.1415827249743; Wed, 12 Nov 2014 13:20:49 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id aj3si23711279pbd.198.2014.11.12.13.20.49 for ; Wed, 12 Nov 2014 13:20:49 -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 S1753422AbaKLVUr (ORCPT + 4 others); Wed, 12 Nov 2014 16:20:47 -0500 Received: from mail-wi0-f178.google.com ([209.85.212.178]:54158 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753309AbaKLVUq (ORCPT ); Wed, 12 Nov 2014 16:20:46 -0500 Received: by mail-wi0-f178.google.com with SMTP id bs8so6247091wib.17 for ; Wed, 12 Nov 2014 13:20:45 -0800 (PST) X-Received: by 10.180.107.35 with SMTP id gz3mr54346544wib.38.1415827245193; Wed, 12 Nov 2014 13:20:45 -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 ft8sm9991551wjb.17.2014.11.12.13.20.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Nov 2014 13:20:44 -0800 (PST) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 689CCC41BAB; Wed, 12 Nov 2014 16:59:35 +0000 (GMT) From: Grant Likely Subject: Re: [PATCH v4] 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: <1415795308-14639-1-git-send-email-ard.biesheuvel@linaro.org> References: <1415795308-14639-1-git-send-email-ard.biesheuvel@linaro.org> Date: Wed, 12 Nov 2014 16:59:35 +0000 Message-Id: <20141112165935.689CCC41BAB@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.215.51 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 Wed, 12 Nov 2014 13:28:28 +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 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 Actually, I made a couple of changes when I merged it. I removed the older debugfs interface since it overlaps, and I added tests for initial_boot_params to make sure it doesn't try to run on an invalid FDT: g. --- 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..fbe8f8d418f7 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 83a8e1154602..c7997e87b4b5 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,7 @@ bool __init early_init_dt_verify(void *params) /* Setup flat device-tree pointer */ initial_boot_params = params; + of_fdt_crc32 = of_fdt_get_crc32(initial_boot_params); return true; } @@ -1080,27 +1092,31 @@ void __init unflatten_and_copy_device_tree(void) unflatten_device_tree(); } -#if defined(CONFIG_DEBUG_FS) && defined(DEBUG) -static struct debugfs_blob_wrapper flat_dt_blob; - -static int __init of_flat_dt_debugfs_export_fdt(void) +#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) { - struct dentry *d = debugfs_create_dir("device-tree", NULL); - - if (!d) - return -ENOENT; + memcpy(buf, initial_boot_params + off, count); + return count; +} - flat_dt_blob.data = initial_boot_params; - flat_dt_blob.size = fdt_totalsize(initial_boot_params); +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); - d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, - d, &flat_dt_blob); - if (!d) - return -ENOENT; + if (!initial_boot_params || fdt_check_header(initial_boot_params)) + return 0; - return 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); } -module_init(of_flat_dt_debugfs_export_fdt); +late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */