/*
* VasEBoot -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* VasEBoot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VasEBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VasEBoot. If not, see .
*/
#ifndef VasEBoot_FDT_HEADER
#define VasEBoot_FDT_HEADER 1
#include
#define FDT_MAGIC 0xD00DFEED
typedef struct {
VasEBoot_uint32_t magic;
VasEBoot_uint32_t totalsize;
VasEBoot_uint32_t off_dt_struct;
VasEBoot_uint32_t off_dt_strings;
VasEBoot_uint32_t off_mem_rsvmap;
VasEBoot_uint32_t version;
VasEBoot_uint32_t last_comp_version;
VasEBoot_uint32_t boot_cpuid_phys;
VasEBoot_uint32_t size_dt_strings;
VasEBoot_uint32_t size_dt_struct;
} VasEBoot_fdt_header_t;
struct VasEBoot_fdt_empty_tree {
VasEBoot_fdt_header_t header;
VasEBoot_uint64_t empty_rsvmap[2];
struct {
VasEBoot_uint32_t node_start;
VasEBoot_uint8_t name[1];
VasEBoot_uint32_t node_end;
VasEBoot_uint32_t tree_end;
} empty_node;
};
#define VasEBoot_FDT_EMPTY_TREE_SZ sizeof (struct VasEBoot_fdt_empty_tree)
#define VasEBoot_fdt_get_header(fdt, field) \
VasEBoot_be_to_cpu32(((const VasEBoot_fdt_header_t *)(fdt))->field)
#define VasEBoot_fdt_set_header(fdt, field, value) \
((VasEBoot_fdt_header_t *)(fdt))->field = VasEBoot_cpu_to_be32(value)
#define VasEBoot_fdt_get_magic(fdt) \
VasEBoot_fdt_get_header(fdt, magic)
#define VasEBoot_fdt_set_magic(fdt, value) \
VasEBoot_fdt_set_header(fdt, magic, value)
#define VasEBoot_fdt_get_totalsize(fdt) \
VasEBoot_fdt_get_header(fdt, totalsize)
#define VasEBoot_fdt_set_totalsize(fdt, value) \
VasEBoot_fdt_set_header(fdt, totalsize, value)
#define VasEBoot_fdt_get_off_dt_struct(fdt) \
VasEBoot_fdt_get_header(fdt, off_dt_struct)
#define VasEBoot_fdt_set_off_dt_struct(fdt, value) \
VasEBoot_fdt_set_header(fdt, off_dt_struct, value)
#define VasEBoot_fdt_get_off_dt_strings(fdt) \
VasEBoot_fdt_get_header(fdt, off_dt_strings)
#define VasEBoot_fdt_set_off_dt_strings(fdt, value) \
VasEBoot_fdt_set_header(fdt, off_dt_strings, value)
#define VasEBoot_fdt_get_off_mem_rsvmap(fdt) \
VasEBoot_fdt_get_header(fdt, off_mem_rsvmap)
#define VasEBoot_fdt_set_off_mem_rsvmap(fdt, value) \
VasEBoot_fdt_set_header(fdt, off_mem_rsvmap, value)
#define VasEBoot_fdt_get_version(fdt) \
VasEBoot_fdt_get_header(fdt, version)
#define VasEBoot_fdt_set_version(fdt, value) \
VasEBoot_fdt_set_header(fdt, version, value)
#define VasEBoot_fdt_get_last_comp_version(fdt) \
VasEBoot_fdt_get_header(fdt, last_comp_version)
#define VasEBoot_fdt_set_last_comp_version(fdt, value) \
VasEBoot_fdt_set_header(fdt, last_comp_version, value)
#define VasEBoot_fdt_get_boot_cpuid_phys(fdt) \
VasEBoot_fdt_get_header(fdt, boot_cpuid_phys)
#define VasEBoot_fdt_set_boot_cpuid_phys(fdt, value) \
VasEBoot_fdt_set_header(fdt, boot_cpuid_phys, value)
#define VasEBoot_fdt_get_size_dt_strings(fdt) \
VasEBoot_fdt_get_header(fdt, size_dt_strings)
#define VasEBoot_fdt_set_size_dt_strings(fdt, value) \
VasEBoot_fdt_set_header(fdt, size_dt_strings, value)
#define VasEBoot_fdt_get_size_dt_struct(fdt) \
VasEBoot_fdt_get_header(fdt, size_dt_struct)
#define VasEBoot_fdt_set_size_dt_struct(fdt, value) \
VasEBoot_fdt_set_header(fdt, size_dt_struct, value)
int VasEBoot_fdt_create_empty_tree (void *fdt, unsigned int size);
int VasEBoot_fdt_check_header (void *fdt, unsigned int size);
int VasEBoot_fdt_check_header_nosize (void *fdt);
int VasEBoot_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
const char *name);
int VasEBoot_fdt_add_subnode (void *fdt, unsigned int parentoffset,
const char *name);
int VasEBoot_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
const void *val, VasEBoot_uint32_t len);
#define VasEBoot_fdt_set_prop32(fdt, nodeoffset, name, val) \
({ \
VasEBoot_uint32_t _val = VasEBoot_cpu_to_be32(val); \
VasEBoot_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 4); \
})
#define VasEBoot_fdt_set_prop64(fdt, nodeoffset, name, val) \
({ \
VasEBoot_uint64_t _val = VasEBoot_cpu_to_be64(val); \
VasEBoot_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 8); \
})
/* Setup "reg" property for
* #address-cells = <0x2>
* #size-cells = <0x2>
*/
#define VasEBoot_fdt_set_reg64(fdt, nodeoffset, addr, size) \
({ \
VasEBoot_uint64_t reg_64[2]; \
reg_64[0] = VasEBoot_cpu_to_be64(addr); \
reg_64[1] = VasEBoot_cpu_to_be64(size); \
VasEBoot_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \
})
#endif /* ! VasEBoot_FDT_HEADER */