1 // SPDX-License-Identifier: GPL-2.0+
3 * Commands for UPL handoff generation
5 * Copyright 2024 Google LLC
9 #define LOG_CATEGORY UCLASS_BOOTSTD
14 #include <display_options.h>
18 #include <dm/ofnode.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 static int do_upl_info(struct cmd_tbl *cmdtp, int flag, int argc,
26 const struct upl *upl = gd_upl();
28 printf("UPL state: %sactive\n", upl ? "" : "in");
31 if (argc > 1 && !strcmp("-v", argv[1])) {
34 printf("fit %lx\n", upl->fit);
35 printf("conf_offset %x\n", upl->conf_offset);
36 for (i = 0; i < upl->image.count; i++) {
37 const struct upl_image *img =
38 alist_get(&upl->image, i, struct upl_image);
40 printf("image %d: load %lx size %lx offset %x: %s\n", i,
41 img->load, img->size, img->offset,
49 static int do_upl_write(struct cmd_tbl *cmdtp, int flag, int argc,
52 struct upl s_upl, *upl = &s_upl;
53 struct unit_test_state uts;
59 upl_get_test_data(&uts, upl);
61 log_debug("Writing UPL\n");
62 ret = upl_create_handoff_tree(upl, &tree);
64 log_err("Failed to write (err=%dE)\n", ret);
65 return CMD_RET_FAILURE;
68 log_debug("Flattening\n");
69 ret = oftree_to_fdt(tree, &buf);
71 log_err("Failed to write (err=%dE)\n", ret);
72 return CMD_RET_FAILURE;
74 addr = map_to_sysmem(abuf_data(&buf));
75 printf("UPL handoff written to %lx size %lx\n", addr, abuf_size(&buf));
76 if (env_set_hex("upladdr", addr) ||
77 env_set_hex("uplsize", abuf_size(&buf))) {
78 printf("Cannot set env var\n");
79 return CMD_RET_FAILURE;
87 static int do_upl_read(struct cmd_tbl *cmdtp, int flag, int argc,
90 struct upl s_upl, *upl = &s_upl;
97 addr = hextoul(argv[1], NULL);
99 printf("Reading UPL at %lx\n", addr);
100 tree = oftree_from_fdt(map_sysmem(addr, 0));
101 ret = upl_read_handoff(upl, tree);
103 log_err("Failed to read (err=%dE)\n", ret);
104 return CMD_RET_FAILURE;
111 "info [-v] - Check UPL status\n"
112 "upl read <addr> - Read handoff information\n"
113 "upl write - Write handoff information");
115 U_BOOT_CMD_WITH_SUBCMDS(upl, "Universal Payload support", upl_help_text,
116 U_BOOT_SUBCMD_MKENT(info, 2, 1, do_upl_info),
117 U_BOOT_SUBCMD_MKENT(read, 2, 1, do_upl_read),
118 U_BOOT_SUBCMD_MKENT(write, 1, 1, do_upl_write));