summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2022-10-11 17:35:42 -0400
committerTom Rini <[email protected]>2022-10-11 17:35:42 -0400
commit8db1fa5a0da78c1a9a16882f2e49beac3ccf5308 (patch)
tree917986046cbdb4c39576bb1d733a33523fe44ca8 /cmd
parent300077cf8cfe6875f3f0a919ec1d0dd32c42b178 (diff)
parentc68e73b65fb9101e3234586db29c3a04e9b37534 (diff)
Merge branch '2022-10-11-assorted-fixes-and-updates'
- Assorted code cleanups and fixes, along with two new commands.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig16
-rw-r--r--cmd/Makefile3
-rw-r--r--cmd/cat.c85
-rw-r--r--cmd/temperature.c85
-rw-r--r--cmd/xxd.c85
5 files changed, 274 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6f00bd93075..49247a41c00 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -469,6 +469,11 @@ config CMD_XIMG
help
Extract a part of a multi-image.
+config CMD_XXD
+ bool "xxd"
+ help
+ Print file as hexdump to standard output
+
config CMD_SPL
bool "spl export - Export boot information for Falcon boot"
depends on SPL
@@ -1449,6 +1454,12 @@ config DEFAULT_SPI_MODE
depends on CMD_SPI
default 0
+config CMD_TEMPERATURE
+ bool "temperature - display the temperature from thermal sensors"
+ depends on DM_THERMAL
+ help
+ Provides a way to list thermal sensors and to get their readings.
+
config CMD_TSI148
bool "tsi148 - Command to access tsi148 device"
help
@@ -1533,6 +1544,11 @@ endmenu
menu "Shell scripting commands"
+config CMD_CAT
+ bool "cat"
+ help
+ Print file to standard output
+
config CMD_ECHO
bool "echo"
default y
diff --git a/cmd/Makefile b/cmd/Makefile
index cf6ce1bd6fd..c95e09d0580 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_CMD_BOOTZ) += bootz.o
obj-$(CONFIG_CMD_BOOTI) += booti.o
obj-$(CONFIG_CMD_BTRFS) += btrfs.o
obj-$(CONFIG_CMD_BUTTON) += button.o
+obj-$(CONFIG_CMD_CAT) += cat.o
obj-$(CONFIG_CMD_CACHE) += cache.o
obj-$(CONFIG_CMD_CBFS) += cbfs.o
obj-$(CONFIG_CMD_CLK) += clk.o
@@ -155,6 +156,7 @@ obj-$(CONFIG_CMD_STRINGS) += strings.o
obj-$(CONFIG_CMD_SMC) += smccc.o
obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o
obj-$(CONFIG_CMD_STACKPROTECTOR_TEST) += stackprot_test.o
+obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
obj-$(CONFIG_CMD_TERMINAL) += terminal.o
obj-$(CONFIG_CMD_TIME) += time.o
obj-$(CONFIG_CMD_TIMER) += timer.o
@@ -184,6 +186,7 @@ obj-$(CONFIG_CMD_USB_SDP) += usb_gadget_sdp.o
obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o
obj-$(CONFIG_CMD_VBE) += vbe.o
obj-$(CONFIG_CMD_XIMG) += ximg.o
+obj-$(CONFIG_CMD_XXD) += xxd.o
obj-$(CONFIG_CMD_YAFFS2) += yaffs2.o
obj-$(CONFIG_CMD_SPL) += spl.o
obj-$(CONFIG_CMD_W1) += w1.o
diff --git a/cmd/cat.c b/cmd/cat.c
new file mode 100644
index 00000000000..1273a26b145
--- /dev/null
+++ b/cmd/cat.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022
+ * Roger Knecht <[email protected]>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+#include <malloc.h>
+#include <mapmem.h>
+
+static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ char *ifname;
+ char *dev;
+ char *file;
+ char *buffer;
+ phys_addr_t addr;
+ loff_t file_size;
+
+ if (argc < 4)
+ return CMD_RET_USAGE;
+
+ ifname = argv[1];
+ dev = argv[2];
+ file = argv[3];
+
+ // check file exists
+ if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+ return CMD_RET_FAILURE;
+
+ if (!fs_exists(file)) {
+ log_err("File does not exist: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+ return CMD_RET_FAILURE;
+ }
+
+ // get file size
+ if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+ return CMD_RET_FAILURE;
+
+ if (fs_size(file, &file_size)) {
+ log_err("Cannot read file size: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+ return CMD_RET_FAILURE;
+ }
+
+ // allocate memory for file content
+ buffer = calloc(sizeof(char), file_size + 1);
+ if (!buffer) {
+ log_err("Out of memory\n");
+ return CMD_RET_FAILURE;
+ }
+
+ // map pointer to system memory
+ addr = map_to_sysmem(buffer);
+
+ // read file to memory
+ if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+ return CMD_RET_FAILURE;
+
+ if (fs_read(file, addr, 0, 0, &file_size)) {
+ log_err("Cannot read file: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+ return CMD_RET_FAILURE;
+ }
+
+ // print file content
+ buffer[file_size] = '\0';
+ puts(buffer);
+
+ free(buffer);
+
+ return 0;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char cat_help_text[] =
+ "<interface> <dev[:part]> <file>\n"
+ " - Print file from 'dev' on 'interface' to standard output\n";
+#endif
+
+U_BOOT_CMD(cat, 4, 1, do_cat,
+ "Print file to standard output",
+ cat_help_text
+);
diff --git a/cmd/temperature.c b/cmd/temperature.c
new file mode 100644
index 00000000000..420965de143
--- /dev/null
+++ b/cmd/temperature.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/*
+ * Copyright (c) 2022 Sartura Ltd.
+ * Written by Robert Marko <[email protected]>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <thermal.h>
+
+#define LIMIT_DEVNAME 30
+
+static int do_get(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct udevice *dev;
+ int ret, temp;
+
+ if (argc < 2) {
+ printf("thermal device not selected\n");
+ return CMD_RET_FAILURE;
+ }
+
+ ret = uclass_get_device_by_name(UCLASS_THERMAL, argv[1], &dev);
+ if (ret) {
+ printf("thermal device not found\n");
+ return CMD_RET_FAILURE;
+ }
+
+ ret = thermal_get_temp(dev, &temp);
+ if (ret)
+ return CMD_RET_FAILURE;
+
+ printf("%s: %d C\n", dev->name, temp);
+
+ return CMD_RET_SUCCESS;
+}
+
+static int do_list(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct udevice *dev;
+
+ printf("| %-*.*s| %-*.*s| %s\n",
+ LIMIT_DEVNAME, LIMIT_DEVNAME, "Device",
+ LIMIT_DEVNAME, LIMIT_DEVNAME, "Driver",
+ "Parent");
+
+ uclass_foreach_dev_probe(UCLASS_THERMAL, dev) {
+ printf("| %-*.*s| %-*.*s| %s\n",
+ LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name,
+ LIMIT_DEVNAME, LIMIT_DEVNAME, dev->driver->name,
+ dev->parent->name);
+ }
+
+ return CMD_RET_SUCCESS;
+}
+
+static struct cmd_tbl temperature_subcmd[] = {
+ U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""),
+ U_BOOT_CMD_MKENT(get, 2, 1, do_get, "", ""),
+};
+
+static int do_temperature(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct cmd_tbl *cmd;
+
+ argc--;
+ argv++;
+
+ cmd = find_cmd_tbl(argv[0], temperature_subcmd, ARRAY_SIZE(temperature_subcmd));
+ if (!cmd || argc > cmd->maxargs)
+ return CMD_RET_USAGE;
+
+ return cmd->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(temperature, CONFIG_SYS_MAXARGS, 1, do_temperature,
+ "thermal sensor temperature",
+ "list\t\tshow list of temperature sensors\n"
+ "get [thermal device name]\tprint temperature in degrees C"
+);
diff --git a/cmd/xxd.c b/cmd/xxd.c
new file mode 100644
index 00000000000..742a85c7a93
--- /dev/null
+++ b/cmd/xxd.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022
+ * Roger Knecht <[email protected]>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <display_options.h>
+#include <fs.h>
+#include <malloc.h>
+#include <mapmem.h>
+
+static int do_xxd(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ char *ifname;
+ char *dev;
+ char *file;
+ char *buffer;
+ phys_addr_t addr;
+ loff_t file_size;
+
+ if (argc < 4)
+ return CMD_RET_USAGE;
+
+ ifname = argv[1];
+ dev = argv[2];
+ file = argv[3];
+
+ // check file exists
+ if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+ return CMD_RET_FAILURE;
+
+ if (!fs_exists(file)) {
+ log_err("File does not exist: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+ return CMD_RET_FAILURE;
+ }
+
+ // get file size
+ if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+ return CMD_RET_FAILURE;
+
+ if (fs_size(file, &file_size)) {
+ log_err("Cannot read file size: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+ return CMD_RET_FAILURE;
+ }
+
+ // allocate memory for file content
+ buffer = calloc(sizeof(char), file_size);
+ if (!buffer) {
+ log_err("Out of memory\n");
+ return CMD_RET_FAILURE;
+ }
+
+ // map pointer to system memory
+ addr = map_to_sysmem(buffer);
+
+ // read file to memory
+ if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+ return CMD_RET_FAILURE;
+
+ if (fs_read(file, addr, 0, 0, &file_size)) {
+ log_err("Cannot read file: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+ return CMD_RET_FAILURE;
+ }
+
+ // print file content
+ print_buffer(0, buffer, sizeof(char), file_size, 0);
+
+ free(buffer);
+
+ return 0;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char xxd_help_text[] =
+ "<interface> <dev[:part]> <file>\n"
+ " - Print file from 'dev' on 'interface' as hexdump to standard output\n";
+#endif
+
+U_BOOT_CMD(xxd, 4, 1, do_xxd,
+ "Print file as hexdump to standard output",
+ xxd_help_text
+);