aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig12
-rw-r--r--cmd/Makefile1
-rw-r--r--cmd/extension_board.c167
-rw-r--r--cmd/fdt.c49
4 files changed, 180 insertions, 49 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 9e8b692..f962bb7 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -332,6 +332,18 @@ config CMD_FDT
help
Do FDT related setup before booting into the Operating System.
+config SUPPORT_EXTENSION_SCAN
+ bool
+
+config CMD_EXTENSION
+ bool "Extension board management command"
+ select CMD_FDT
+ depends on SUPPORT_EXTENSION_SCAN
+ help
+ Enables the "extension" command, which allows to detect
+ extension boards connected to the system, and apply
+ corresponding Device Tree overlays.
+
config CMD_GO
bool "go"
default y
diff --git a/cmd/Makefile b/cmd/Makefile
index 4977fa1..9d10e07 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -54,6 +54,7 @@ obj-$(CONFIG_CMD_DIAG) += diag.o
endif
obj-$(CONFIG_CMD_ADTIMG) += adtimg.o
obj-$(CONFIG_CMD_ABOOTIMG) += abootimg.o
+obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
obj-$(CONFIG_CMD_ECHO) += echo.o
obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
obj-$(CONFIG_CMD_EEPROM) += eeprom.o
diff --git a/cmd/extension_board.c b/cmd/extension_board.c
new file mode 100644
index 0000000..6ad9765
--- /dev/null
+++ b/cmd/extension_board.c
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021
+ * Köry Maincent, Bootlin, <kory.maincent@bootlin.com>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <extension_board.h>
+#include <mapmem.h>
+#include <linux/libfdt.h>
+#include <fdt_support.h>
+
+static LIST_HEAD(extension_list);
+
+static int extension_apply(struct extension *extension)
+{
+ char *overlay_cmd;
+ ulong extrasize, overlay_addr;
+ struct fdt_header *blob;
+
+ if (!working_fdt) {
+ printf("No FDT memory address configured. Please configure\n"
+ "the FDT address via \"fdt addr <address>\" command.\n");
+ return CMD_RET_FAILURE;
+ }
+
+ overlay_cmd = env_get("extension_overlay_cmd");
+ if (!overlay_cmd) {
+ printf("Environment extension_overlay_cmd is missing\n");
+ return CMD_RET_FAILURE;
+ }
+
+ overlay_addr = env_get_hex("extension_overlay_addr", 0);
+ if (!overlay_addr) {
+ printf("Environment extension_overlay_addr is missing\n");
+ return CMD_RET_FAILURE;
+ }
+
+ env_set("extension_overlay_name", extension->overlay);
+ if (run_command(overlay_cmd, 0) != 0)
+ return CMD_RET_FAILURE;
+
+ extrasize = env_get_hex("filesize", 0);
+ if (!extrasize)
+ return CMD_RET_FAILURE;
+
+ fdt_shrink_to_minimum(working_fdt, extrasize);
+
+ blob = map_sysmem(overlay_addr, 0);
+ if (!fdt_valid(&blob))
+ return CMD_RET_FAILURE;
+
+ /* apply method prints messages on error */
+ if (fdt_overlay_apply_verbose(working_fdt, blob))
+ return CMD_RET_FAILURE;
+
+ return CMD_RET_SUCCESS;
+}
+
+static int do_extension_list(struct cmd_tbl *cmdtp, int flag,
+ int argc, char *const argv[])
+{
+ int i;
+ struct extension *extension;
+
+ if (list_empty(&extension_list)) {
+ printf("No extension registered - Please run \"extension scan\"\n");
+ return CMD_RET_SUCCESS;
+ }
+
+ list_for_each_entry(extension, &extension_list, list) {
+ printf("Extension %d: %s\n", i++, extension->name);
+ printf("\tManufacturer: \t\t%s\n", extension->owner);
+ printf("\tVersion: \t\t%s\n", extension->version);
+ printf("\tDevicetree overlay: \t%s\n", extension->overlay);
+ printf("\tOther information: \t%s\n", extension->other);
+ }
+ return CMD_RET_SUCCESS;
+}
+
+static int do_extension_scan(struct cmd_tbl *cmdtp, int flag,
+ int argc, char *const argv[])
+{
+ struct extension *extension, *next;
+ int extension_num;
+
+ list_for_each_entry_safe(extension, next, &extension_list, list) {
+ list_del(&extension->list);
+ free(extension);
+ }
+ extension_num = extension_board_scan(&extension_list);
+
+ if (extension_num < 0)
+ return CMD_RET_FAILURE;
+
+ printf("Found %d extension board(s).\n", extension_num);
+
+ return CMD_RET_SUCCESS;
+}
+
+static int do_extension_apply(struct cmd_tbl *cmdtp, int flag,
+ int argc, char *const argv[])
+{
+ struct extension *extension = NULL;
+ struct list_head *entry;
+ int i = 0, extension_id, ret;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ if (strcmp(argv[1], "all") == 0) {
+ list_for_each_entry(extension, &extension_list, list) {
+ ret = extension_apply(extension);
+ if (ret != CMD_RET_SUCCESS)
+ break;
+ }
+ } else {
+ extension_id = simple_strtol(argv[1], NULL, 10);
+ list_for_each(entry, &extension_list) {
+ if (i == extension_id) {
+ extension = list_entry(entry, struct extension, list);
+ break;
+ }
+ i++;
+ }
+
+ if (!extension) {
+ printf("Wrong extension number\n");
+ return CMD_RET_FAILURE;
+ }
+
+ ret = extension_apply(extension);
+ }
+
+ return ret;
+}
+
+static struct cmd_tbl cmd_extension[] = {
+ U_BOOT_CMD_MKENT(scan, 1, 1, do_extension_scan, "", ""),
+ U_BOOT_CMD_MKENT(list, 1, 0, do_extension_list, "", ""),
+ U_BOOT_CMD_MKENT(apply, 2, 0, do_extension_apply, "", ""),
+};
+
+static int do_extensionops(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct cmd_tbl *cp;
+
+ /* Drop the extension command */
+ argc--;
+ argv++;
+
+ cp = find_cmd_tbl(argv[0], cmd_extension, ARRAY_SIZE(cmd_extension));
+ if (cp)
+ return cp->cmd(cmdtp, flag, argc, argv);
+
+ return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(extension, 3, 1, do_extensionops,
+ "Extension board management sub system",
+ "scan - scan plugged extension(s) board(s)\n"
+ "extension list - lists available extension(s) board(s)\n"
+ "extension apply <extension number|all> - applies DT overlays corresponding to extension boards\n"
+);
diff --git a/cmd/fdt.c b/cmd/fdt.c
index 89ab572..f1e2fc2 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -27,7 +27,6 @@
*/
DECLARE_GLOBAL_DATA_PTR;
-static int fdt_valid(struct fdt_header **blobp);
static int fdt_parse_prop(char *const*newval, int count, char *data, int *len);
static int fdt_print(const char *pathp, char *prop, int depth);
static int is_printable_string(const void *data, int len);
@@ -732,54 +731,6 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
/****************************************************************************/
-/**
- * fdt_valid() - Check if an FDT is valid. If not, change it to NULL
- *
- * @blobp: Pointer to FDT pointer
- * @return 1 if OK, 0 if bad (in which case *blobp is set to NULL)
- */
-static int fdt_valid(struct fdt_header **blobp)
-{
- const void *blob = *blobp;
- int err;
-
- if (blob == NULL) {
- printf ("The address of the fdt is invalid (NULL).\n");
- return 0;
- }
-
- err = fdt_check_header(blob);
- if (err == 0)
- return 1; /* valid */
-
- if (err < 0) {
- printf("libfdt fdt_check_header(): %s", fdt_strerror(err));
- /*
- * Be more informative on bad version.
- */
- if (err == -FDT_ERR_BADVERSION) {
- if (fdt_version(blob) <
- FDT_FIRST_SUPPORTED_VERSION) {
- printf (" - too old, fdt %d < %d",
- fdt_version(blob),
- FDT_FIRST_SUPPORTED_VERSION);
- }
- if (fdt_last_comp_version(blob) >
- FDT_LAST_SUPPORTED_VERSION) {
- printf (" - too new, fdt %d > %d",
- fdt_version(blob),
- FDT_LAST_SUPPORTED_VERSION);
- }
- }
- printf("\n");
- *blobp = NULL;
- return 0;
- }
- return 1;
-}
-
-/****************************************************************************/
-
/*
* Parse the user's input, partially heuristic. Valid formats:
* <0x00112233 4 05> - an array of cells. Numbers follow standard