Laurentiu Tudor | 62070e0 | 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 | |
| 12 | static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts) |
| 13 | { |
| 14 | struct fdt_memory resv; |
| 15 | void *blob; |
| 16 | const fdt32_t *prop; |
| 17 | int blob_sz, len, offset; |
| 18 | |
| 19 | blob_sz = fdt_totalsize(gd->fdt_blob) + 4096; |
| 20 | blob = malloc(blob_sz); |
| 21 | ut_assertnonnull(blob); |
| 22 | |
| 23 | /* Make a writtable copy of the fdt blob */ |
| 24 | ut_assertok(fdt_open_into(gd->fdt_blob, blob, blob_sz)); |
| 25 | |
| 26 | resv.start = 0x1000; |
| 27 | resv.end = 0x2000; |
| 28 | ut_assertok(fdtdec_set_carveout(blob, "/a-test", |
| 29 | "memory-region", 2, "test_resv1", |
| 30 | &resv)); |
| 31 | |
| 32 | resv.start = 0x10000; |
| 33 | resv.end = 0x20000; |
| 34 | ut_assertok(fdtdec_set_carveout(blob, "/a-test", |
| 35 | "memory-region", 1, "test_resv2", |
| 36 | &resv)); |
| 37 | |
| 38 | resv.start = 0x100000; |
| 39 | resv.end = 0x200000; |
| 40 | ut_assertok(fdtdec_set_carveout(blob, "/a-test", |
| 41 | "memory-region", 0, "test_resv3", |
| 42 | &resv)); |
| 43 | |
| 44 | offset = fdt_path_offset(blob, "/a-test"); |
| 45 | ut_assert(offset > 0); |
| 46 | prop = fdt_getprop(blob, offset, "memory-region", &len); |
| 47 | ut_assertnonnull(prop); |
| 48 | |
| 49 | ut_asserteq(len, 12); |
| 50 | ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[0])) > 0); |
| 51 | ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[1])) > 0); |
| 52 | ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[2])) > 0); |
| 53 | |
| 54 | free(blob); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | DM_TEST(dm_test_fdtdec_set_carveout, |
| 59 | DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); |