Andrew Walbran | 679cdf4 | 2018-09-18 15:36:17 +0100 | [diff] [blame] | 1 | extern "C" { |
| 2 | #include "hf/fdt_handler.h" |
| 3 | |
Andrew Walbran | 0ea8ced | 2018-10-03 14:56:58 +0100 | [diff] [blame^] | 4 | #include "hf/alloc.h" |
Andrew Walbran | 679cdf4 | 2018-09-18 15:36:17 +0100 | [diff] [blame] | 5 | #include "hf/boot_params.h" |
| 6 | } |
| 7 | |
Andrew Walbran | 0ea8ced | 2018-10-03 14:56:58 +0100 | [diff] [blame^] | 8 | #include <memory> |
| 9 | |
Andrew Walbran | 679cdf4 | 2018-09-18 15:36:17 +0100 | [diff] [blame] | 10 | #include <gmock/gmock.h> |
| 11 | |
| 12 | using ::testing::Eq; |
| 13 | |
Andrew Walbran | 0ea8ced | 2018-10-03 14:56:58 +0100 | [diff] [blame^] | 14 | static constexpr size_t TEST_HEAP_SIZE = PAGE_SIZE * 10; |
| 15 | |
Andrew Walbran | 679cdf4 | 2018-09-18 15:36:17 +0100 | [diff] [blame] | 16 | /* |
| 17 | * /dts-v1/; |
| 18 | * |
| 19 | * / { |
| 20 | * #address-cells = <2>; |
| 21 | * #size-cells = <2>; |
| 22 | * |
| 23 | * memory@0 { |
| 24 | * device_type = "memory"; |
| 25 | * reg = <0x00000000 0x00000000 0x00000000 0x20000000 |
| 26 | * 0x00000000 0x30000000 0x00000000 0x00010000>; |
| 27 | * }; |
| 28 | * memory@1 { |
| 29 | * device_type = "memory"; |
| 30 | * reg = <0x00000000 0x30020000 0x00000000 0x00010000>; |
| 31 | * }; |
| 32 | * |
| 33 | * chosen { |
| 34 | * linux,initrd-start = <0x00000000>; |
| 35 | * linux,initrd-end = <0x00000000>; |
| 36 | * }; |
| 37 | * }; |
| 38 | * |
| 39 | * $ dtc --boot-cpu 0 --in-format dts --out-format dtb --out-version 17 test.dts |
| 40 | * | xxd -i |
| 41 | */ |
| 42 | |
Andrew Walbran | 0ea8ced | 2018-10-03 14:56:58 +0100 | [diff] [blame^] | 43 | static constexpr uint8_t test_dtb[] = { |
Andrew Walbran | 679cdf4 | 2018-09-18 15:36:17 +0100 | [diff] [blame] | 44 | 0xd0, 0x0d, 0xfe, 0xed, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x00, 0x38, |
| 45 | 0x00, 0x00, 0x01, 0x30, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11, |
| 46 | 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, |
| 47 | 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, |
| 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, |
| 51 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x02, |
| 52 | 0x00, 0x00, 0x00, 0x01, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x40, 0x30, |
| 53 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, |
| 54 | 0x00, 0x00, 0x00, 0x1b, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x00, 0x00, |
| 55 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x27, |
| 56 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 57 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, |
| 58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, |
| 59 | 0x00, 0x00, 0x00, 0x01, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x40, 0x31, |
| 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, |
| 61 | 0x00, 0x00, 0x00, 0x1b, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x00, 0x00, |
| 62 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x27, |
| 63 | 0x00, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 64 | 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, |
| 65 | 0x63, 0x68, 0x6f, 0x73, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, |
| 66 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, |
| 67 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3e, |
| 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, |
| 69 | 0x00, 0x00, 0x00, 0x09, 0x23, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, |
| 70 | 0x2d, 0x63, 0x65, 0x6c, 0x6c, 0x73, 0x00, 0x23, 0x73, 0x69, 0x7a, 0x65, |
| 71 | 0x2d, 0x63, 0x65, 0x6c, 0x6c, 0x73, 0x00, 0x64, 0x65, 0x76, 0x69, 0x63, |
| 72 | 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x00, 0x72, 0x65, 0x67, 0x00, 0x6c, |
| 73 | 0x69, 0x6e, 0x75, 0x78, 0x2c, 0x69, 0x6e, 0x69, 0x74, 0x72, 0x64, 0x2d, |
| 74 | 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x6c, 0x69, 0x6e, 0x75, 0x78, 0x2c, |
| 75 | 0x69, 0x6e, 0x69, 0x74, 0x72, 0x64, 0x2d, 0x65, 0x6e, 0x64, 0x00}; |
| 76 | |
| 77 | TEST(fdt, get_boot_params) |
| 78 | { |
Andrew Walbran | 0ea8ced | 2018-10-03 14:56:58 +0100 | [diff] [blame^] | 79 | std::unique_ptr<uint8_t[]> test_heap(new uint8_t[TEST_HEAP_SIZE]); |
| 80 | halloc_init((size_t)test_heap.get(), TEST_HEAP_SIZE); |
| 81 | ASSERT_TRUE(mm_init()); |
| 82 | |
| 83 | struct boot_params params = {}; |
Andrew Walbran | 679cdf4 | 2018-09-18 15:36:17 +0100 | [diff] [blame] | 84 | EXPECT_TRUE( |
| 85 | fdt_get_boot_params(pa_init((uintpaddr_t)&test_dtb), ¶ms)); |
| 86 | EXPECT_THAT(params.mem_ranges_count, Eq(3)); |
| 87 | EXPECT_THAT(pa_addr(params.mem_ranges[0].begin), Eq(0x00000000)); |
| 88 | EXPECT_THAT(pa_addr(params.mem_ranges[0].end), Eq(0x20000000)); |
| 89 | EXPECT_THAT(pa_addr(params.mem_ranges[1].begin), Eq(0x30000000)); |
| 90 | EXPECT_THAT(pa_addr(params.mem_ranges[1].end), Eq(0x30010000)); |
| 91 | EXPECT_THAT(pa_addr(params.mem_ranges[2].begin), Eq(0x30020000)); |
| 92 | EXPECT_THAT(pa_addr(params.mem_ranges[2].end), Eq(0x30030000)); |
| 93 | } |