X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/6942ebae59c3904674dce6b67cd07c43a3bbe00d..7e13988c1113d38bec17bd79b71757d78d977e76:/lunaix-os/tests/units/device-tree/load.c?ds=sidebyside diff --git a/lunaix-os/tests/units/device-tree/load.c b/lunaix-os/tests/units/device-tree/load.c new file mode 100644 index 0000000..f97765e --- /dev/null +++ b/lunaix-os/tests/units/device-tree/load.c @@ -0,0 +1,46 @@ +#include "common.h" + +#include +#include +#include +#include +#include + +#define MAX_DTB_SZ (2 * 1024 * 1024) + +#ifndef TEST_DTBFILE +#warning "no test dtb file given" +#define TEST_DTBFILE "" +#endif + +extern void init_export___init_devtree(); + +ptr_t +load_fdt() +{ + int fd = open(TEST_DTBFILE, O_RDONLY); + if (fd == -1) { + printf("fail to open: %s, %s\n", TEST_DTBFILE, strerror(errno)); + return false; + } + + ptr_t dtb = (ptr_t)mmap(0, + MAX_DTB_SZ, + PROT_READ | PROT_WRITE | MAP_POPULATE, + MAP_PRIVATE, fd, 0); + + if (dtb == (ptr_t)-1) { + printf("fail to map dtb: %s\n", strerror(errno)); + _exit(1); + } + + close(fd); + return dtb; +} + +bool +my_load_dtb() +{ + init_export___init_devtree(); + return dt_load(load_fdt()); +} \ No newline at end of file