43 lines
1,021 B
C
43 lines
1,021 B
C
#include <endian.h>
|
|
#include <log.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#define ARM_DTB_PTR32 0x000000f8
|
|
|
|
struct __attribute__((packed)) header {
|
|
uint32_t magic;
|
|
#define DTB_MAGIC 0xd00dfeed
|
|
uint32_t total_size;
|
|
#define DTB_MAX_SIZE 0x100000
|
|
uint32_t off_dt_strt;
|
|
uint32_t off_dt_strs;
|
|
uint32_t off_mem_rsvmap;
|
|
uint32_t version;
|
|
#define DTB_VERSION 17
|
|
uint32_t last_comp_version;
|
|
#define DTB_LAST_COMP_VERSION 16
|
|
uint32_t boot_cpuid_phys;
|
|
uint32_t size_dt_strs;
|
|
uint32_t size_dt_strt;
|
|
};
|
|
|
|
static const struct header *hdr = 0;
|
|
|
|
bool gilbraltar_dtb_init(void) {
|
|
uint32_t *volatile ptr = (uint32_t *volatile)ARM_DTB_PTR32;
|
|
|
|
const void *dtb = (const void *)(uintptr_t)*ptr;
|
|
hdr = (const struct header *)dtb;
|
|
|
|
if (be32toh(hdr->magic) != DTB_MAGIC ||
|
|
be32toh(hdr->last_comp_version) != DTB_LAST_COMP_VERSION)
|
|
return false;
|
|
|
|
uint32_t total_size = be32toh(hdr->total_size);
|
|
|
|
if (total_size < sizeof(struct header) || total_size > DTB_MAX_SIZE)
|
|
return false;
|
|
|
|
return true;
|
|
}
|