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