Skip to content

Commit c972de1

Browse files
committed
of/fdt: use libfdt accessors for header data
With libfdt support, we can take advantage of helper accessors in libfdt for accessing the FDT header data. This makes the code more readable and makes the FDT blob structure more opaque to the kernel. This also prepares for removing struct boot_param_header completely. Signed-off-by: Rob Herring <robh@kernel.org> Cc: Max Filippov <jcmvbkbc@gmail.com> Tested-by: Michal Simek <michal.simek@xilinx.com> Tested-by: Grant Likely <grant.likely@linaro.org> Tested-by: Stephen Chivers <schivers@csc.com>
1 parent e6a6928 commit c972de1

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

‎drivers/of/fdt.c‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* On match, returns a non-zero value with smaller values returned for more
3535
* specific compatible values.
3636
*/
37-
int of_fdt_is_compatible(struct boot_param_header *blob,
37+
int of_fdt_is_compatible(const void *blob,
3838
unsigned long node, const char *compat)
3939
{
4040
const char *cp;
@@ -59,7 +59,7 @@ int of_fdt_is_compatible(struct boot_param_header *blob,
5959
/**
6060
* of_fdt_match - Return true if node matches a list of compatible values
6161
*/
62-
int of_fdt_match(struct boot_param_header *blob, unsigned long node,
62+
int of_fdt_match(const void *blob, unsigned long node,
6363
const char *const *compat)
6464
{
6565
unsigned int tmp, score = 0;
@@ -98,7 +98,7 @@ static void *unflatten_dt_alloc(void **mem, unsigned long size,
9898
* @allnextpp: pointer to ->allnext from last allocated device_node
9999
* @fpsize: Size of the node path up at the current depth.
100100
*/
101-
static void * unflatten_dt_node(struct boot_param_header *blob,
101+
static void * unflatten_dt_node(void *blob,
102102
void *mem,
103103
int *poffset,
104104
struct device_node *dad,
@@ -295,7 +295,7 @@ static void * unflatten_dt_node(struct boot_param_header *blob,
295295
* @dt_alloc: An allocator that provides a virtual address to memory
296296
* for the resulting tree
297297
*/
298-
static void __unflatten_device_tree(struct boot_param_header *blob,
298+
static void __unflatten_device_tree(void *blob,
299299
struct device_node **mynodes,
300300
void * (*dt_alloc)(u64 size, u64 align))
301301
{
@@ -312,11 +312,11 @@ static void __unflatten_device_tree(struct boot_param_header *blob,
312312
}
313313

314314
pr_debug("Unflattening device tree:\n");
315-
pr_debug("magic: %08x\n", be32_to_cpu(blob->magic));
316-
pr_debug("size: %08x\n", be32_to_cpu(blob->totalsize));
317-
pr_debug("version: %08x\n", be32_to_cpu(blob->version));
315+
pr_debug("magic: %08x\n", fdt_magic(blob));
316+
pr_debug("size: %08x\n", fdt_totalsize(blob));
317+
pr_debug("version: %08x\n", fdt_version(blob));
318318

319-
if (be32_to_cpu(blob->magic) != OF_DT_HEADER) {
319+
if (fdt_check_header(blob)) {
320320
pr_err("Invalid device tree blob header\n");
321321
return;
322322
}
@@ -363,9 +363,7 @@ static void *kernel_tree_alloc(u64 size, u64 align)
363363
void of_fdt_unflatten_tree(unsigned long *blob,
364364
struct device_node **mynodes)
365365
{
366-
struct boot_param_header *device_tree =
367-
(struct boot_param_header *)blob;
368-
__unflatten_device_tree(device_tree, mynodes, &kernel_tree_alloc);
366+
__unflatten_device_tree(blob, mynodes, &kernel_tree_alloc);
369367
}
370368
EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree);
371369

@@ -852,7 +850,7 @@ bool __init early_init_dt_scan(void *params)
852850
initial_boot_params = params;
853851

854852
/* check device tree validity */
855-
if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
853+
if (fdt_check_header(params)) {
856854
initial_boot_params = NULL;
857855
return false;
858856
}
@@ -907,9 +905,9 @@ void __init unflatten_and_copy_device_tree(void)
907905
return;
908906
}
909907

910-
size = __be32_to_cpu(initial_boot_params->totalsize);
908+
size = fdt_totalsize(initial_boot_params);
911909
dt = early_init_dt_alloc_memory_arch(size,
912-
__alignof__(struct boot_param_header));
910+
roundup_pow_of_two(FDT_V17_SIZE));
913911

914912
if (dt) {
915913
memcpy(dt, initial_boot_params, size);

‎include/linux/of_fdt.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ struct boot_param_header {
6262
struct device_node;
6363

6464
/* For scanning an arbitrary device-tree at any time */
65-
extern char *of_fdt_get_string(struct boot_param_header *blob, u32 offset);
66-
extern void *of_fdt_get_property(struct boot_param_header *blob,
65+
extern char *of_fdt_get_string(const void *blob, u32 offset);
66+
extern void *of_fdt_get_property(const void *blob,
6767
unsigned long node,
6868
const char *name,
6969
int *size);
70-
extern int of_fdt_is_compatible(struct boot_param_header *blob,
70+
extern int of_fdt_is_compatible(const void *blob,
7171
unsigned long node,
7272
const char *compat);
73-
extern int of_fdt_match(struct boot_param_header *blob, unsigned long node,
73+
extern int of_fdt_match(const void *blob, unsigned long node,
7474
const char *const *compat);
7575
extern void of_fdt_unflatten_tree(unsigned long *blob,
7676
struct device_node **mynodes);

0 commit comments

Comments
 (0)