diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2010-04-13 19:12:26 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-04-28 20:20:29 -0400 |
commit | 8bfe9b5c3a684fe39eb58a65e466c103d1c32c9a (patch) | |
tree | eb7709a314b7ec5ba3eef1dcd60018f41d512a45 | |
parent | cf32eb89cb4e674f88e4af5025839d85d02485c6 (diff) |
of/flattree: Make unflatten_device_tree() safe to call from any arch
This patch makes unflatten_device_tree() safe to call from any arch
setup code with the following changes:
- Make sure initial_boot_params actually points to a device tree blob
before unflattening
- Make sure the initial_boot_params->magic field is correct
- If CONFIG_OF_FLATTREE is not set, then make unflatten_device_tree()
an empty static inline function.
This patch also adds some additional debug output to the top of
unflatten_device_tree().
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
-rw-r--r-- | drivers/of/fdt.c | 15 | ||||
-rw-r--r-- | include/linux/of_fdt.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index dee4fb56b094..b6987bba8556 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c | |||
@@ -556,6 +556,21 @@ void __init unflatten_device_tree(void) | |||
556 | 556 | ||
557 | pr_debug(" -> unflatten_device_tree()\n"); | 557 | pr_debug(" -> unflatten_device_tree()\n"); |
558 | 558 | ||
559 | if (!initial_boot_params) { | ||
560 | pr_debug("No device tree pointer\n"); | ||
561 | return; | ||
562 | } | ||
563 | |||
564 | pr_debug("Unflattening device tree:\n"); | ||
565 | pr_debug("magic: %08x\n", be32_to_cpu(initial_boot_params->magic)); | ||
566 | pr_debug("size: %08x\n", be32_to_cpu(initial_boot_params->totalsize)); | ||
567 | pr_debug("version: %08x\n", be32_to_cpu(initial_boot_params->version)); | ||
568 | |||
569 | if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) { | ||
570 | pr_err("Invalid device tree blob header\n"); | ||
571 | return; | ||
572 | } | ||
573 | |||
559 | /* First pass, scan for size */ | 574 | /* First pass, scan for size */ |
560 | start = ((unsigned long)initial_boot_params) + | 575 | start = ((unsigned long)initial_boot_params) + |
561 | be32_to_cpu(initial_boot_params->off_dt_struct); | 576 | be32_to_cpu(initial_boot_params->off_dt_struct); |
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index f0fdd1f43688..71e1a916d3fa 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h | |||
@@ -99,6 +99,8 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname, | |||
99 | /* Other Prototypes */ | 99 | /* Other Prototypes */ |
100 | extern void unflatten_device_tree(void); | 100 | extern void unflatten_device_tree(void); |
101 | extern void early_init_devtree(void *); | 101 | extern void early_init_devtree(void *); |
102 | #else /* CONFIG_OF_FLATTREE */ | ||
103 | static inline void unflatten_device_tree(void) {} | ||
102 | #endif /* CONFIG_OF_FLATTREE */ | 104 | #endif /* CONFIG_OF_FLATTREE */ |
103 | 105 | ||
104 | #endif /* __ASSEMBLY__ */ | 106 | #endif /* __ASSEMBLY__ */ |