From patchwork Mon Nov 10 18:47:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 40524 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C9F95203C0 for ; Mon, 10 Nov 2014 18:47:23 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id ex7sf4396744wid.4 for ; Mon, 10 Nov 2014 10:47:23 -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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=GoFYiQjkNlVNZvieHnr05NsBfYCwPGMtua2KUYnXot8=; b=MhC1U5njEhEL2fCDmNVZxVHzLw57oBym1KXUW086vx9gffUVDcxCciKI/3Mv8fDgS5 nq9nRohyHsogOiF5r9u3ROXCGjFMrnNcGuRLOeBYX6+xsjFI/7DyFLAkGKtiEtJynnkG RVTPE99ccyHNqQ2hXkCAj1zqu24Pw+W1fo1quNHVr+iRU10I2y8zp+t8jFsmsBIhm+Js t08c/hKkjdX6Yaucik82n71N/vFpWTjYblsbgjTgF8CLkHXcbyTjbiTcHqyXaUrNoATj cEhU7p9Am9jjc7kkj4emdL/BCEdhwnRKwvcnCnq/ZpBjkrf1b/qIWuaYdxBo5OmApsjt iy4Q== X-Gm-Message-State: ALoCoQmDSqA26qv7OpHNUYnSP+NaO5CnjLY/oBcjZ7zjPtAmcmxxH2Z8eaeuLeXNd0SNfemjWSL8 X-Received: by 10.112.147.131 with SMTP id tk3mr5721973lbb.2.1415645243017; Mon, 10 Nov 2014 10:47:23 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.227 with SMTP id e3ls501432laa.69.gmail; Mon, 10 Nov 2014 10:47:22 -0800 (PST) X-Received: by 10.112.171.225 with SMTP id ax1mr31361022lbc.40.1415645242514; Mon, 10 Nov 2014 10:47:22 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id oh2si28236541lbb.107.2014.11.10.10.47.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 10:47:22 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id p9so3159778lbv.29 for ; Mon, 10 Nov 2014 10:47:22 -0800 (PST) X-Received: by 10.152.42.226 with SMTP id r2mr31391383lal.29.1415645242426; Mon, 10 Nov 2014 10:47:22 -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 ew9csp142573lbc; Mon, 10 Nov 2014 10:47:21 -0800 (PST) X-Received: by 10.70.136.164 with SMTP id qb4mr34228964pdb.36.1415645240541; Mon, 10 Nov 2014 10:47:20 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qn7si17411839pbc.63.2014.11.10.10.47.19 for ; Mon, 10 Nov 2014 10:47:20 -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 S1751579AbaKJSrT (ORCPT + 4 others); Mon, 10 Nov 2014 13:47:19 -0500 Received: from mail-wg0-f48.google.com ([74.125.82.48]:42313 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751385AbaKJSrS (ORCPT ); Mon, 10 Nov 2014 13:47:18 -0500 Received: by mail-wg0-f48.google.com with SMTP id m15so9889229wgh.7 for ; Mon, 10 Nov 2014 10:47:17 -0800 (PST) X-Received: by 10.195.13.14 with SMTP id eu14mr44459016wjd.31.1415645237118; Mon, 10 Nov 2014 10:47:17 -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 l10sm14416085wif.20.2014.11.10.10.47.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 10:47:16 -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 v2 1/2] of/fdt: export fdt blob as /sys/firmware/fdt Date: Mon, 10 Nov 2014 19:47:01 +0100 Message-Id: <1415645222-14909-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415645222-14909-1-git-send-email-ard.biesheuvel@linaro.org> References: <1415645222-14909-1-git-send-email-ard.biesheuvel@linaro.org> 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.170 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 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 --- 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__ */