-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added flattened device tree (FDT) support. Setting required FDT field…
…s per ePAPR 1.1.
- Loading branch information
Showing
8 changed files
with
853 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* fdt.h | ||
* | ||
* Functions to help with flattened device tree (DTB) parsing | ||
* | ||
* | ||
* Copyright (C) 2023 wolfSSL Inc. | ||
* | ||
* This file is part of wolfBoot. | ||
* | ||
* wolfBoot 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. | ||
* | ||
* wolfBoot 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA | ||
*/ | ||
|
||
/* Based on work from "libfdt" by David Gibson */ | ||
|
||
#ifndef FDT_H | ||
#define FDT_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
#ifdef BIG_ENDIAN_ORDER | ||
#define FDT_MAGIC 0xD00DFEEDUL | ||
#else | ||
#define FDT_MAGIC 0xEDFE0DD0UL | ||
#endif | ||
#define FDT_SW_MAGIC (~FDT_MAGIC) | ||
|
||
struct fdt_header { | ||
uint32_t magic; | ||
uint32_t totalsize; | ||
uint32_t off_dt_struct; | ||
uint32_t off_dt_strings; | ||
uint32_t off_mem_rsvmap; | ||
uint32_t version; | ||
uint32_t last_comp_version; | ||
uint32_t boot_cpuid_phys; | ||
uint32_t size_dt_strings; | ||
uint32_t size_dt_struct; | ||
}; | ||
|
||
struct fdt_reserve_entry { | ||
uint64_t address; | ||
uint64_t size; | ||
}; | ||
|
||
struct fdt_prop { | ||
uint32_t len; | ||
uint32_t nameoff; | ||
}; | ||
|
||
struct fdt_node_header { | ||
uint32_t tag; | ||
char name[0]; | ||
}; | ||
|
||
struct fdt_property { | ||
uint32_t tag; | ||
uint32_t len; | ||
uint32_t nameoff; | ||
char data[0]; | ||
}; | ||
|
||
#define FDT_TAGSIZE sizeof(uint32_t) | ||
#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) | ||
#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) | ||
|
||
#define FDT_BEGIN_NODE 0x00000001UL | ||
#define FDT_END_NODE 0x00000002UL | ||
#define FDT_PROP 0x00000003UL | ||
#define FDT_NOP 0x00000004UL | ||
#define FDT_END 0x00000009UL | ||
|
||
#define FDT_ERR_NOTFOUND 1 | ||
#define FDT_ERR_NOSPACE 3 | ||
#define FDT_ERR_BADOFFSET 4 | ||
#define FDT_ERR_TRUNCATED 8 | ||
#define FDT_ERR_BADVERSION 10 | ||
#define FDT_ERR_BADSTRUCTURE 11 | ||
#define FDT_ERR_INTERNAL 13 | ||
|
||
|
||
uint32_t cpu_to_fdt32(uint32_t x); | ||
uint64_t cpu_to_fdt64(uint64_t x); | ||
uint32_t fdt32_to_cpu(uint32_t x); | ||
uint64_t fdt64_to_cpu(uint64_t x); | ||
|
||
int fdt_next_node(const void *fdt, int offset, int *depth); | ||
const void *fdt_getprop(const void *fdt, int nodeoffset, const char *name, int *lenp); | ||
int fdt_setprop(void *fdt, int nodeoffset, const char *name, const void *val, int len); | ||
|
||
int fdt_fixup_str(void* fdt, int off, const char* node, const char* name, const char* str); | ||
int fdt_fixup_val(void* fdt, int off, const char* node, const char* name, uint32_t val); | ||
int fdt_find_devtype(void* fdt, int startoff, const char* node); | ||
|
||
#define fdt_get_header(fdt, field) (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field)) | ||
#define fdt_magic(fdt) (fdt_get_header(fdt, magic)) | ||
#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) | ||
#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) | ||
#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) | ||
#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) | ||
#define fdt_version(fdt) (fdt_get_header(fdt, version)) | ||
#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) | ||
#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) | ||
#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) | ||
#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) | ||
|
||
#define fdt_set_header(fdt, field, val) (((struct fdt_header *)fdt)->field = cpu_to_fdt32(val)) | ||
#define fdt_set_magic(fdt, val) (fdt_set_header(fdt, magic, (val))) | ||
#define fdt_set_totalsize(fdt, val) (fdt_set_header(fdt, totalsize, (val))) | ||
#define fdt_set_off_dt_struct(fdt, val) (fdt_set_header(fdt, off_dt_struct, (val))) | ||
#define fdt_set_off_dt_strings(fdt, val) (fdt_set_header(fdt, off_dt_strings, (val))) | ||
#define fdt_set_off_mem_rsvmap(fdt, val) (fdt_set_header(fdt, off_mem_rsvmap, (val))) | ||
#define fdt_set_version(fdt, val) (fdt_set_header(fdt, version, (val))) | ||
#define fdt_set_last_comp_version(fdt, val) (fdt_set_header(fdt, last_comp_version, (val))) | ||
#define fdt_set_boot_cpuid_phys(fdt, val) (fdt_set_header(fdt, boot_cpuid_phys, (val))) | ||
#define fdt_set_size_dt_strings(fdt, val) (fdt_set_header(fdt, size_dt_strings, (val))) | ||
#define fdt_set_size_dt_struct(fdt, val) (fdt_set_header(fdt, size_dt_struct, (val))) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* !FDT_H */ |
Oops, something went wrong.