blob: c2f7b9480513cfa250870e406519d59350486e8d [file] [log] [blame]
Laurentiu Tudor528d6b32020-04-03 13:43:04 +03001// 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 Mengc9a1df02020-06-22 22:55:47 -070012DECLARE_GLOBAL_DATA_PTR;
13
Laurentiu Tudor528d6b32020-04-03 13:43:04 +030014static 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}
60DM_TEST(dm_test_fdtdec_set_carveout,
61 DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);