Skip to content

Commit

Permalink
of/fdt: use libfdt accessors for header data
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Rob Herring committed Apr 30, 2014
1 parent e6a6928 commit c972de1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
26 changes: 12 additions & 14 deletions drivers/of/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* On match, returns a non-zero value with smaller values returned for more
* specific compatible values.
*/
int of_fdt_is_compatible(struct boot_param_header *blob,
int of_fdt_is_compatible(const void *blob,
unsigned long node, const char *compat)
{
const char *cp;
Expand All @@ -59,7 +59,7 @@ int of_fdt_is_compatible(struct boot_param_header *blob,
/**
* of_fdt_match - Return true if node matches a list of compatible values
*/
int of_fdt_match(struct boot_param_header *blob, unsigned long node,
int of_fdt_match(const void *blob, unsigned long node,
const char *const *compat)
{
unsigned int tmp, score = 0;
Expand Down Expand Up @@ -98,7 +98,7 @@ static void *unflatten_dt_alloc(void **mem, unsigned long size,
* @allnextpp: pointer to ->allnext from last allocated device_node
* @fpsize: Size of the node path up at the current depth.
*/
static void * unflatten_dt_node(struct boot_param_header *blob,
static void * unflatten_dt_node(void *blob,
void *mem,
int *poffset,
struct device_node *dad,
Expand Down Expand Up @@ -295,7 +295,7 @@ static void * unflatten_dt_node(struct boot_param_header *blob,
* @dt_alloc: An allocator that provides a virtual address to memory
* for the resulting tree
*/
static void __unflatten_device_tree(struct boot_param_header *blob,
static void __unflatten_device_tree(void *blob,
struct device_node **mynodes,
void * (*dt_alloc)(u64 size, u64 align))
{
Expand All @@ -312,11 +312,11 @@ static void __unflatten_device_tree(struct boot_param_header *blob,
}

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

if (be32_to_cpu(blob->magic) != OF_DT_HEADER) {
if (fdt_check_header(blob)) {
pr_err("Invalid device tree blob header\n");
return;
}
Expand Down Expand Up @@ -363,9 +363,7 @@ static void *kernel_tree_alloc(u64 size, u64 align)
void of_fdt_unflatten_tree(unsigned long *blob,
struct device_node **mynodes)
{
struct boot_param_header *device_tree =
(struct boot_param_header *)blob;
__unflatten_device_tree(device_tree, mynodes, &kernel_tree_alloc);
__unflatten_device_tree(blob, mynodes, &kernel_tree_alloc);
}
EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree);

Expand Down Expand Up @@ -852,7 +850,7 @@ bool __init early_init_dt_scan(void *params)
initial_boot_params = params;

/* check device tree validity */
if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
if (fdt_check_header(params)) {
initial_boot_params = NULL;
return false;
}
Expand Down Expand Up @@ -907,9 +905,9 @@ void __init unflatten_and_copy_device_tree(void)
return;
}

size = __be32_to_cpu(initial_boot_params->totalsize);
size = fdt_totalsize(initial_boot_params);
dt = early_init_dt_alloc_memory_arch(size,
__alignof__(struct boot_param_header));
roundup_pow_of_two(FDT_V17_SIZE));

if (dt) {
memcpy(dt, initial_boot_params, size);
Expand Down
8 changes: 4 additions & 4 deletions include/linux/of_fdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ struct boot_param_header {
struct device_node;

/* For scanning an arbitrary device-tree at any time */
extern char *of_fdt_get_string(struct boot_param_header *blob, u32 offset);
extern void *of_fdt_get_property(struct boot_param_header *blob,
extern char *of_fdt_get_string(const void *blob, u32 offset);
extern void *of_fdt_get_property(const void *blob,
unsigned long node,
const char *name,
int *size);
extern int of_fdt_is_compatible(struct boot_param_header *blob,
extern int of_fdt_is_compatible(const void *blob,
unsigned long node,
const char *compat);
extern int of_fdt_match(struct boot_param_header *blob, unsigned long node,
extern int of_fdt_match(const void *blob, unsigned long node,
const char *const *compat);
extern void of_fdt_unflatten_tree(unsigned long *blob,
struct device_node **mynodes);
Expand Down

0 comments on commit c972de1

Please sign in to comment.