Laurentiu Tudor | 528d6b3 | 2020-04-03 13:43:04 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2020 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <dm/of_extra.h> |
| 9 | #include <dm/test.h> |
| 10 | #include <test/ut.h> |
| 11 | |
Bin Meng | c9a1df0 | 2020-06-22 22:55:47 -0700 | [diff] [blame^] | 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Laurentiu Tudor | 528d6b3 | 2020-04-03 13:43:04 +0300 | [diff] [blame] | 14 | static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts) |
| 15 | { |
| 16 | struct fdt_memory resv; |
| 17 | void *blob; |
| 18 | const fdt32_t *prop; |
| 19 | int blob_sz, len, offset; |
| 20 | |
| 21 | blob_sz = fdt_totalsize(gd->fdt_blob) + 4096; |
| 22 | blob = malloc(blob_sz); |
| 23 | ut_assertnonnull(blob); |
| 24 | |
| 25 | /* Make a writtable copy of the fdt blob */ |
| 26 | ut_assertok(fdt_open_into(gd->fdt_blob, blob, blob_sz)); |
| 27 | |
| 28 | resv.start = 0x1000; |
| 29 | resv.end = 0x2000; |
| 30 | ut_assertok(fdtdec_set_carveout(blob, "/a-test", |
| 31 | "memory-region", 2, "test_resv1", |
| 32 | &resv)); |
| 33 | |
| 34 | resv.start = 0x10000; |
| 35 | resv.end = 0x20000; |
| 36 | ut_assertok(fdtdec_set_carveout(blob, "/a-test", |
| 37 | "memory-region", 1, "test_resv2", |
| 38 | &resv)); |
| 39 | |
| 40 | resv.start = 0x100000; |
| 41 | resv.end = 0x200000; |
| 42 | ut_assertok(fdtdec_set_carveout(blob, "/a-test", |
| 43 | "memory-region", 0, "test_resv3", |
| 44 | &resv)); |
| 45 | |
| 46 | offset = fdt_path_offset(blob, "/a-test"); |
| 47 | ut_assert(offset > 0); |
| 48 | prop = fdt_getprop(blob, offset, "memory-region", &len); |
| 49 | ut_assertnonnull(prop); |
| 50 | |
| 51 | ut_asserteq(len, 12); |
| 52 | ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[0])) > 0); |
| 53 | ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[1])) > 0); |
| 54 | ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[2])) > 0); |
| 55 | |
| 56 | free(blob); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | DM_TEST(dm_test_fdtdec_set_carveout, |
| 61 | DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); |