vbe_simple.c 2.5 KB

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