X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/35a7d633d3f16c1e0539af6ca5d8e7482926cd93..9daf4fcdae88f72af60aeb0c7722841af02233d4:/lunaix-os/tests/units/device-tree/load.c 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