aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/of/Kconfig1
-rw-r--r--drivers/of/fdt.c43
2 files changed, 28 insertions, 16 deletions
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
23 bool 23 bool
24 select DTC 24 select DTC
25 select LIBFDT 25 select LIBFDT
26 select CRC32
26 27
27config OF_EARLY_FLATTREE 28config OF_EARLY_FLATTREE
28 bool 29 bool
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 83a8e1154602..cb19adfb3933 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -9,6 +9,7 @@
9 * version 2 as published by the Free Software Foundation. 9 * version 2 as published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/crc32.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/initrd.h> 14#include <linux/initrd.h>
14#include <linux/memblock.h> 15#include <linux/memblock.h>
@@ -22,6 +23,7 @@
22#include <linux/libfdt.h> 23#include <linux/libfdt.h>
23#include <linux/debugfs.h> 24#include <linux/debugfs.h>
24#include <linux/serial_core.h> 25#include <linux/serial_core.h>
26#include <linux/sysfs.h>
25 27
26#include <asm/setup.h> /* for COMMAND_LINE_SIZE */ 28#include <asm/setup.h> /* for COMMAND_LINE_SIZE */
27#include <asm/page.h> 29#include <asm/page.h>
@@ -423,6 +425,8 @@ void *initial_boot_params;
423 425
424#ifdef CONFIG_OF_EARLY_FLATTREE 426#ifdef CONFIG_OF_EARLY_FLATTREE
425 427
428static u32 of_fdt_crc32;
429
426/** 430/**
427 * res_mem_reserve_reg() - reserve all memory described in 'reg' property 431 * res_mem_reserve_reg() - reserve all memory described in 'reg' property
428 */ 432 */
@@ -1003,6 +1007,8 @@ bool __init early_init_dt_verify(void *params)
1003 1007
1004 /* Setup flat device-tree pointer */ 1008 /* Setup flat device-tree pointer */
1005 initial_boot_params = params; 1009 initial_boot_params = params;
1010 of_fdt_crc32 = crc32_be(~0, initial_boot_params,
1011 fdt_totalsize(initial_boot_params));
1006 return true; 1012 return true;
1007} 1013}
1008 1014
@@ -1080,27 +1086,32 @@ void __init unflatten_and_copy_device_tree(void)
1080 unflatten_device_tree(); 1086 unflatten_device_tree();
1081} 1087}
1082 1088
1083#if defined(CONFIG_DEBUG_FS) && defined(DEBUG) 1089#ifdef CONFIG_SYSFS
1084static struct debugfs_blob_wrapper flat_dt_blob; 1090static ssize_t of_fdt_raw_read(struct file *filp, struct kobject *kobj,
1085 1091 struct bin_attribute *bin_attr,
1086static int __init of_flat_dt_debugfs_export_fdt(void) 1092 char *buf, loff_t off, size_t count)
1087{ 1093{
1088 struct dentry *d = debugfs_create_dir("device-tree", NULL); 1094 memcpy(buf, initial_boot_params + off, count);
1089 1095 return count;
1090 if (!d) 1096}
1091 return -ENOENT;
1092 1097
1093 flat_dt_blob.data = initial_boot_params; 1098static int __init of_fdt_raw_init(void)
1094 flat_dt_blob.size = fdt_totalsize(initial_boot_params); 1099{
1100 static struct bin_attribute of_fdt_raw_attr =
1101 __BIN_ATTR(fdt, S_IRUSR, of_fdt_raw_read, NULL, 0);
1095 1102
1096 d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, 1103 if (!initial_boot_params)
1097 d, &flat_dt_blob); 1104 return 0;
1098 if (!d)
1099 return -ENOENT;
1100 1105
1101 return 0; 1106 if (of_fdt_crc32 != crc32_be(~0, initial_boot_params,
1107 fdt_totalsize(initial_boot_params))) {
1108 pr_warn("fdt: not creating '/sys/firmware/fdt': CRC check failed\n");
1109 return 0;
1110 }
1111 of_fdt_raw_attr.size = fdt_totalsize(initial_boot_params);
1112 return sysfs_create_bin_file(firmware_kobj, &of_fdt_raw_attr);
1102} 1113}
1103module_init(of_flat_dt_debugfs_export_fdt); 1114late_initcall(of_fdt_raw_init);
1104#endif 1115#endif
1105 1116
1106#endif /* CONFIG_OF_EARLY_FLATTREE */ 1117#endif /* CONFIG_OF_EARLY_FLATTREE */