Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8bfe9b5c authored by Grant Likely's avatar Grant Likely
Browse files

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: default avatarGrant Likely <grant.likely@secretlab.ca>
parent cf32eb89
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -556,6 +556,21 @@ void __init unflatten_device_tree(void)


	pr_debug(" -> unflatten_device_tree()\n");
	pr_debug(" -> unflatten_device_tree()\n");


	if (!initial_boot_params) {
		pr_debug("No device tree pointer\n");
		return;
	}

	pr_debug("Unflattening device tree:\n");
	pr_debug("magic: %08x\n", be32_to_cpu(initial_boot_params->magic));
	pr_debug("size: %08x\n", be32_to_cpu(initial_boot_params->totalsize));
	pr_debug("version: %08x\n", be32_to_cpu(initial_boot_params->version));

	if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
		pr_err("Invalid device tree blob header\n");
		return;
	}

	/* First pass, scan for size */
	/* First pass, scan for size */
	start = ((unsigned long)initial_boot_params) +
	start = ((unsigned long)initial_boot_params) +
		be32_to_cpu(initial_boot_params->off_dt_struct);
		be32_to_cpu(initial_boot_params->off_dt_struct);
+2 −0
Original line number Original line Diff line number Diff line
@@ -99,6 +99,8 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,
/* Other Prototypes */
/* Other Prototypes */
extern void unflatten_device_tree(void);
extern void unflatten_device_tree(void);
extern void early_init_devtree(void *);
extern void early_init_devtree(void *);
#else /* CONFIG_OF_FLATTREE */
static inline void unflatten_device_tree(void) {}
#endif /* CONFIG_OF_FLATTREE */
#endif /* CONFIG_OF_FLATTREE */


#endif /* __ASSEMBLY__ */
#endif /* __ASSEMBLY__ */