1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Test for VBE device tree fix-ups
4  *
5  * Copyright 2022 Google LLC
6  * Written by Simon Glass <sjg@chromium.org>
7  */
8 
9 #include <common.h>
10 #include <dm/ofnode.h>
11 #include <linux/libfdt.h>
12 #include <test/test.h>
13 #include <test/ut.h>
14 #include "bootstd_common.h"
15 
16 /*
17  * Basic test of reading nvdata and updating a fwupd node in the device tree
18  * This test works when called from test_vbe.py and it must use the flat tree,
19  * since device tree fix-ups do not yet support live tree.
20  */
vbe_test_fixup_norun(struct unit_test_state * uts)21 static int vbe_test_fixup_norun(struct unit_test_state *uts)
22 {
23 	ofnode chosen, node;
24 	const char *data;
25 	oftree tree;
26 	int size;
27 
28 	tree = oftree_from_fdt(working_fdt);
29 	ut_assert(oftree_valid(tree));
30 
31 	chosen = oftree_path(tree, "/chosen");
32 	ut_assert(ofnode_valid(chosen));
33 
34 	/* check the things set up for the FIT in test_vbe.py */
35 	node = ofnode_find_subnode(chosen, "random");
36 
37 	/* ignore if this test is run on its own */
38 	if (!ofnode_valid(node))
39 		return 0;
40 	data = ofnode_read_prop(node, "data", &size);
41 	ut_asserteq(0x40, size);
42 
43 	node = ofnode_find_subnode(chosen, "aslr2");
44 	ut_assert(ofnode_valid(node));
45 	data = ofnode_read_prop(node, "data", &size);
46 	ut_asserteq(4, size);
47 
48 	node = ofnode_find_subnode(chosen, "efi-runtime");
49 	ut_assert(ofnode_valid(node));
50 	data = ofnode_read_prop(node, "data", &size);
51 	ut_asserteq(4, size);
52 
53 	return 0;
54 }
55 BOOTSTD_TEST(vbe_test_fixup_norun, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
56 	     UT_TESTF_FLAT_TREE | UT_TESTF_MANUAL);
57