Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Test for vbe-simple bootmeth. All start with 'vbe_simple' |
| 4 | * |
| 5 | * Copyright 2023 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <bootmeth.h> |
| 11 | #include <dm.h> |
| 12 | #include <image.h> |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 13 | #include <of_live.h> |
| 14 | #include <vbe.h> |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 15 | #include <test/suites.h> |
| 16 | #include <test/ut.h> |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 17 | #include "bootstd_common.h" |
| 18 | |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 19 | /* Basic test of reading nvdata and updating a fwupd node in the device tree */ |
| 20 | static int vbe_simple_test_base(struct unit_test_state *uts) |
| 21 | { |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 22 | const char *version, *bl_version; |
| 23 | struct event_ft_fixup fixup; |
Simon Glass | bfdfc5d | 2022-10-11 09:47:13 -0600 | [diff] [blame] | 24 | struct udevice *dev; |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 25 | struct device_node *np; |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 26 | char fdt_buf[0x400]; |
| 27 | char info[100]; |
| 28 | int node_ofs; |
| 29 | ofnode node; |
| 30 | u32 vernum; |
| 31 | |
Simon Glass | bfdfc5d | 2022-10-11 09:47:13 -0600 | [diff] [blame] | 32 | /* Set up the VBE info */ |
| 33 | ut_assertok(bootstd_setup_for_tests()); |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 34 | |
| 35 | /* Read the version back */ |
| 36 | ut_assertok(vbe_find_by_any("firmware0", &dev)); |
| 37 | ut_assertok(bootmeth_get_state_desc(dev, info, sizeof(info))); |
| 38 | ut_asserteq_str("Version: " TEST_VERSION "\nVernum: 1/2", info); |
| 39 | |
| 40 | ut_assertok(fdt_create_empty_tree(fdt_buf, sizeof(fdt_buf))); |
| 41 | node_ofs = fdt_add_subnode(fdt_buf, 0, "chosen"); |
| 42 | ut_assert(node_ofs > 0); |
| 43 | |
| 44 | node_ofs = fdt_add_subnode(fdt_buf, node_ofs, "fwupd"); |
| 45 | ut_assert(node_ofs > 0); |
| 46 | |
| 47 | node_ofs = fdt_add_subnode(fdt_buf, node_ofs, "firmware0"); |
| 48 | ut_assert(node_ofs > 0); |
| 49 | |
Simon Glass | 0d63213 | 2022-09-06 20:27:31 -0600 | [diff] [blame] | 50 | if (of_live_active()) { |
| 51 | ut_assertok(unflatten_device_tree(fdt_buf, &np)); |
| 52 | fixup.tree = oftree_from_np(np); |
| 53 | } else { |
| 54 | fixup.tree = oftree_from_fdt(fdt_buf); |
| 55 | } |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * It would be better to call image_setup_libfdt() here, but that |
| 59 | * function does not allow passing an ofnode. We can pass fdt_buf but |
Simon Glass | 0d63213 | 2022-09-06 20:27:31 -0600 | [diff] [blame] | 60 | * when it comes to send the event, it creates an ofnode that uses the |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 61 | * control FDT, since it has no way of accessing the live tree created |
| 62 | * here. |
| 63 | * |
Simon Glass | 0d63213 | 2022-09-06 20:27:31 -0600 | [diff] [blame] | 64 | * Two fix this we need image_setup_libfdt() is updated to use ofnode |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 65 | */ |
Simon Glass | bfdfc5d | 2022-10-11 09:47:13 -0600 | [diff] [blame] | 66 | fixup.images = NULL; |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 67 | ut_assertok(event_notify(EVT_FT_FIXUP, &fixup, sizeof(fixup))); |
| 68 | |
Simon Glass | b7bd94f | 2022-09-06 20:27:24 -0600 | [diff] [blame] | 69 | node = oftree_path(fixup.tree, "/chosen/fwupd/firmware0"); |
Simon Glass | 5fe76d4 | 2022-07-30 15:52:37 -0600 | [diff] [blame] | 70 | |
| 71 | version = ofnode_read_string(node, "cur-version"); |
| 72 | ut_assertnonnull(version); |
| 73 | ut_asserteq_str(TEST_VERSION, version); |
| 74 | |
| 75 | ut_assertok(ofnode_read_u32(node, "cur-vernum", &vernum)); |
| 76 | ut_asserteq(TEST_VERNUM, vernum); |
| 77 | |
| 78 | bl_version = ofnode_read_string(node, "bootloader-version"); |
| 79 | ut_assertnonnull(bl_version); |
| 80 | ut_asserteq_str(version_string, bl_version); |
| 81 | |
| 82 | return 0; |
| 83 | } |
Simon Glass | 0d63213 | 2022-09-06 20:27:31 -0600 | [diff] [blame] | 84 | BOOTSTD_TEST(vbe_simple_test_base, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |