blob: 1b488e25ab6a1b287759a0c124c52edd943c1a33 [file] [log] [blame]
Simon Glassae0bf222022-10-11 09:47:20 -06001// 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/* Basic test of reading nvdata and updating a fwupd node in the device tree */
17static int vbe_test_fixup(struct unit_test_state *uts)
18{
19 ofnode chosen, node;
20 const char *data;
21 oftree tree;
22 int size;
23
24 /*
25 * This test works when called from test_vbe.py and it must use the
26 * flat tree, since device tree fix-ups do not yet support live tree.
27 */
28 if (!working_fdt)
29 return 0;
30
31 tree = oftree_from_fdt(working_fdt);
32 ut_assert(oftree_valid(tree));
33
34 chosen = oftree_path(tree, "/chosen");
35 ut_assert(ofnode_valid(chosen));
36
37 /* check the things set up for the FIT in test_vbe.py */
38 node = ofnode_find_subnode(chosen, "random");
39
40 /* ignore if this test is run on its own */
41 if (!ofnode_valid(node))
42 return 0;
43 data = ofnode_read_prop(node, "data", &size);
44 ut_asserteq(0x40, size);
45
46 node = ofnode_find_subnode(chosen, "aslr2");
47 ut_assert(ofnode_valid(node));
48 data = ofnode_read_prop(node, "data", &size);
49 ut_asserteq(4, size);
50
51 node = ofnode_find_subnode(chosen, "efi-runtime");
52 ut_assert(ofnode_valid(node));
53 data = ofnode_read_prop(node, "data", &size);
54 ut_asserteq(4, size);
55
56 return 0;
57}
58BOOTSTD_TEST(vbe_test_fixup,
59 UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);