/* * This program 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 2 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef FT_BUILD_H #define FT_BUILD_H #include typedef unsigned short u16; typedef unsigned int u32; typedef unsigned long long u64; static inline u16 swab16(u16 x) { return (((u16)(x) & (u16)0x00ffU) << 8) | (((u16)(x) & (u16)0xff00U) >> 8); } static inline u32 swab32(u32 x) { return (((u32)(x) & (u32)0x000000ffUL) << 24) | (((u32)(x) & (u32)0x0000ff00UL) << 8) | (((u32)(x) & (u32)0x00ff0000UL) >> 8) | (((u32)(x) & (u32)0xff000000UL) >> 24); } static inline u64 swab64(u64 x) { return (u64)(((u64)(x) & (u64)0x00000000000000ffULL) << 56) | (u64)(((u64)(x) & (u64)0x000000000000ff00ULL) << 40) | (u64)(((u64)(x) & (u64)0x0000000000ff0000ULL) << 24) | (u64)(((u64)(x) & (u64)0x00000000ff000000ULL) << 8) | (u64)(((u64)(x) & (u64)0x000000ff00000000ULL) >> 8) | (u64)(((u64)(x) & (u64)0x0000ff0000000000ULL) >> 24) | (u64)(((u64)(x) & (u64)0x00ff000000000000ULL) >> 40) | (u64)(((u64)(x) & (u64)0xff00000000000000ULL) >> 56); } #if __BYTE_ORDER == __LITTLE_ENDIAN #define cpu_to_be16(x) swab16(x) #define be16_to_cpu(x) swab16(x) #define cpu_to_be32(x) swab32(x) #define be32_to_cpu(x) swab32(x) #define cpu_to_be64(x) swab64(x) #define be64_to_cpu(x) swab64(x) #else #define cpu_to_be16(x) (x) #define be16_to_cpu(x) (x) #define cpu_to_be32(x) (x) #define be32_to_cpu(x) (x) #define cpu_to_be64(x) (x) #define be64_to_cpu(x) (x) #endif /* Definitions used by the flattened device tree */ #define OF_DT_HEADER 0xd00dfeed /* marker */ #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ #define OF_DT_END_NODE 0x2 /* End node */ #define OF_DT_PROP 0x3 /* Property: name off, size, content */ #define OF_DT_NOP 0x4 /* nop */ #define OF_DT_END 0x9 #define OF_DT_VERSION 0x10 struct boot_param_header { u32 magic; /* magic word OF_DT_HEADER */ u32 totalsize; /* total size of DT block */ u32 off_dt_struct; /* offset to structure */ u32 off_dt_strings; /* offset to strings */ u32 off_mem_rsvmap; /* offset to memory reserve map */ u32 version; /* format version */ u32 last_comp_version; /* last compatible version */ /* version 2 fields below */ u32 boot_cpuid_phys; /* Physical CPU id we're booting on */ /* version 3 fields below */ u32 dt_strings_size; /* size of the DT strings block */ }; struct ft_cxt { struct boot_param_header *bph; int max_size; /* maximum size of tree */ int overflow; /* set when this happens */ char *p, *pstr, *pres; /* running pointers */ char *p_begin, *pstr_begin, *pres_begin; /* starting pointers */ char *p_anchor; /* start of constructed area */ int struct_size, strings_size, res_size; }; void ft_begin_node(struct ft_cxt *cxt, const char *name); void ft_end_node(struct ft_cxt *cxt); void ft_begin_tree(struct ft_cxt *cxt); int ft_end_tree(struct ft_cxt *cxt); void ft_nop(struct ft_cxt *cxt); void ft_prop(struct ft_cxt *cxt, const char *name, const void *data, int sz); void ft_prop_str(struct ft_cxt *cxt, const char *name, const char *str); void ft_prop_int(struct ft_cxt *cxt, const char *name, int val); void ft_begin(struct ft_cxt *cxt, void *blob, int max_size); void ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size); void ft_dump_blob(const void *bphp); void ft_merge_blob(struct ft_cxt *cxt, void *blob); void *ft_get_prop(void *bphp, const char *propname, int *szp); void ft_set_prop(void *bphp, const char *propname, void *val, int len); #endif