From 35821a25c1ca06b71fbf6f46442cc9d93b31fb7d Mon Sep 17 00:00:00 2001 From: Edoardo Tomelleri Date: Wed, 21 Sep 2022 15:26:33 +0200 Subject: [PATCH 01/13] cmd: pxe: add alias devicetree-overlay for fdtoverlays This adds keyword devicetree-overlay as an alias for fdtoverlays in extlinux (sysboot) and pxe to better follow the Boot Loader Specification [1], improves documentation around them by adding an example for both fdtoverlays and devicetree-overlay and the environment variable required for this feature. The link for the spec is updated to the current one. [1] https://systemd.io/BOOT_LOADER_SPECIFICATION/ Signed-off-by: Edoardo Tomelleri Reviewed-by: Neil Armstrong Reviewed-by: Ramon Fried --- boot/pxe_utils.c | 2 ++ doc/README.pxe | 12 ++++++++++++ doc/develop/distro.rst | 32 +++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index a364fa8bb5..d5c215ae2c 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -380,6 +380,7 @@ err: /** * label_boot_fdtoverlay() - Loads fdt overlays specified in 'fdtoverlays' + * or 'devicetree-overlay' * * @ctx: PXE context * @label: Label to process @@ -809,6 +810,7 @@ static const struct token keywords[] = { {"devicetreedir", T_FDTDIR}, {"fdtdir", T_FDTDIR}, {"fdtoverlays", T_FDTOVERLAYS}, + {"devicetree-overlay", T_FDTOVERLAYS}, {"ontimeout", T_ONTIMEOUT,}, {"ipappend", T_IPAPPEND,}, {"background", T_BACKGROUND,}, diff --git a/doc/README.pxe b/doc/README.pxe index 75caa01c4a..d14d2bdcc9 100644 --- a/doc/README.pxe +++ b/doc/README.pxe @@ -163,6 +163,13 @@ fdtoverlays [...] - if this label is chosen, use tftp to retrieve the DT and then applied in the load order to the fdt blob stored at the address indicated in the fdt_addr_r environment variable. +devicetree-overlay [...] - if this label is chosen, use tftp to retrieve the DT + overlay(s) at . it will be temporarily stored at the + address indicated in the fdtoverlay_addr_r environment variable, + and then applied in the load order to the fdt blob stored at the + address indicated in the fdt_addr_r environment variable. + Alias for fdtoverlays. + kaslrseed - set this label to request random number from hwrng as kaslr seed. append - use as the kernel command line when booting this @@ -178,6 +185,11 @@ fdt - if this label is chosen, use tftp to retrieve the fdt blob the fdt_addr_r environment variable, and that address will be passed to bootm. +devicetree - if this label is chosen, use tftp to retrieve the fdt blob + at . it will be stored at the address indicated in + the fdt_addr_r environment variable, and that address will + be passed to bootm. Alias for fdt. + fdtdir - if this label is chosen, use tftp to retrieve a fdt blob relative to . If the fdtfile environment variable is set, / is retrieved. Otherwise, the diff --git a/doc/develop/distro.rst b/doc/develop/distro.rst index 3ee3dac6a2..bc72aa951e 100644 --- a/doc/develop/distro.rst +++ b/doc/develop/distro.rst @@ -68,10 +68,10 @@ Boot Configuration Files The standard format for boot configuration files is that of extlinux.conf, as handled by U-Boot's "syslinux" (disk) or "pxe boot" (network). This is roughly -as specified at BootLoaderSpec_: +as specified at `Boot Loader Specification`_: -... with the exceptions that the BootLoaderSpec document: +... with the exceptions that the Boot Loader Specification document: * Prescribes a separate configuration per boot menu option, whereas U-Boot lumps all options into a single extlinux.conf file. Hence, U-Boot searches @@ -81,6 +81,8 @@ as specified at BootLoaderSpec_: * Does not document the fdtdir option, which automatically selects the DTB to pass to the kernel. +See also doc/README.pxe under 'pxe file format'. + One example extlinux.conf generated by the Fedora installer is:: # extlinux.conf generated by anaconda @@ -115,6 +117,25 @@ One example extlinux.conf generated by the Fedora installer is:: fdtdir /boot/dtb-3.16.0-0.rc6.git1.1.fc22.armv7hl+lpae +One example of hand-crafted extlinux.conf:: + + menu title Select kernel + timeout 100 + + label Arch with uart devicetree overlay + kernel /arch/Image.gz + initrd /arch/initramfs-linux.img + fdt /dtbs/arch/board.dtb + fdtoverlays /dtbs/arch/overlay/uart0-gpio0-1.dtbo + append console=ttyS0,115200 console=tty1 rw root=UUID=fc0d0284-ca84-4194-bf8a-4b9da8d66908 + + label Arch with uart devicetree overlay but with Boot Loader Specification keys + kernel /arch/Image.gz + initrd /arch/initramfs-linux.img + devicetree /dtbs/arch/board.dtb + devicetree-overlay /dtbs/arch/overlay/uart0-gpio0-1.dtbo + append console=ttyS0,115200 console=tty1 rw root=UUID=fc0d0284-ca84-4194-bf8a-4b9da8d66908 + Another hand-crafted network boot configuration file is:: TIMEOUT 100 @@ -214,6 +235,11 @@ fdt_addr_r: A size of 1MB for the FDT/DTB seems reasonable. +fdtoverlay_addr_r: + Mandatory. The location in RAM where DTB overlays will be temporarily + stored and then applied in the load order to the fdt blob stored at the + address indicated in the fdt_addr_r environment variable. + fdtfile: Mandatory. the name of the DTB file for the specific board for instance the espressobin v5 board the value is "marvell/armada-3720-espressobin.dtb" @@ -408,7 +434,7 @@ way in future u-boot versions. In particular the _boot variables (e.g. mmc_boot, usb_boot) are a strictly internal implementation detail and must not be used as a public interface. -.. _BootLoaderSpec: http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/ +.. _`Boot Loader Specification`: https://systemd.io/BOOT_LOADER_SPECIFICATION/ .. sectionauthor:: (C) Copyright 2014 Red Hat Inc. .. sectionauthor:: Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved. From 36ecaa2ce84ec48ed7dc90723455ae4468df0423 Mon Sep 17 00:00:00 2001 From: Oleksandr Suvorov Date: Mon, 19 Sep 2022 12:14:49 +0300 Subject: [PATCH 02/13] lib: crypt: fix selecting a non-existent option The option SHA256_ALGO does not exist. Remove selecting it. Fixes: 26dd9936574 ("lib: add crypt subsystem") Signed-off-by: Oleksandr Suvorov --- lib/crypt/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/crypt/Kconfig b/lib/crypt/Kconfig index a59d5c7d1d..22af6834d9 100644 --- a/lib/crypt/Kconfig +++ b/lib/crypt/Kconfig @@ -12,7 +12,6 @@ if CRYPT_PW config CRYPT_PW_SHA256 bool "Provide sha256crypt" select SHA256 - select SHA256_ALGO help Enables support for the sha256crypt password-hashing algorithm. The prefix is "$5$". From bda5f3e7d678ef34ca512cc5321b73e39320b147 Mon Sep 17 00:00:00 2001 From: Philip Oberfichtner Date: Mon, 19 Sep 2022 10:11:00 +0200 Subject: [PATCH 03/13] bootcount: pmic: Correct misleading comment Fix a copy-paste error I did when inserting the comment. Signed-off-by: Philip Oberfichtner Reviewed-by: Jaehoon Chung --- drivers/bootcount/Kconfig | 2 +- drivers/bootcount/pmic_pfuze100.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig index e918f74694..8d6424c9da 100644 --- a/drivers/bootcount/Kconfig +++ b/drivers/bootcount/Kconfig @@ -132,7 +132,7 @@ config DM_BOOTCOUNT_PMIC_PFUZE100 depends on DM_PMIC_PFUZE100 help Enable support for the bootcounter using PMIC PFUZE100 registers. - This works only, if the PMIC is not connected. + This works only, if the PMIC is not connected to a battery. config DM_BOOTCOUNT_SPI_FLASH bool "Support SPI flash devices as a backing store for bootcount" diff --git a/drivers/bootcount/pmic_pfuze100.c b/drivers/bootcount/pmic_pfuze100.c index ad3bc03829..df046f1b0a 100644 --- a/drivers/bootcount/pmic_pfuze100.c +++ b/drivers/bootcount/pmic_pfuze100.c @@ -5,7 +5,7 @@ * Philip Oberfichtner * * A bootcount driver using the registers MEMA - MEMD on the PFUZE100. - * This works only, if the PMIC is not connected. + * This works only, if the PMIC is not connected to a battery. */ #include From 7c5eeb8309a19c662efe6d7695c256975f6da0d4 Mon Sep 17 00:00:00 2001 From: Steven Lawrance Date: Wed, 14 Sep 2022 20:57:27 +0200 Subject: [PATCH 04/13] image-pre-load: Move macros/definitions to image.h Putting these definitions in a header will allow signatures to be validated independently of bootm. Signed-off-by: Steven Lawrance Reviewed-by: Simon Glass --- boot/image-pre-load.c | 43 ------------------------------------------- include/image.h | 43 +++++++++++++++++++++++++++++++++++++++++++ tools/image-host.c | 2 -- 3 files changed, 43 insertions(+), 45 deletions(-) diff --git a/boot/image-pre-load.c b/boot/image-pre-load.c index 5ab9ae1874..01b60030fc 100644 --- a/boot/image-pre-load.c +++ b/boot/image-pre-load.c @@ -11,49 +11,6 @@ DECLARE_GLOBAL_DATA_PTR; #include -#define IMAGE_PRE_LOAD_SIG_MAGIC 0x55425348 -#define IMAGE_PRE_LOAD_SIG_OFFSET_MAGIC 0 -#define IMAGE_PRE_LOAD_SIG_OFFSET_IMG_LEN 4 -#define IMAGE_PRE_LOAD_SIG_OFFSET_SIG 8 - -#define IMAGE_PRE_LOAD_PATH "/image/pre-load/sig" -#define IMAGE_PRE_LOAD_PROP_ALGO_NAME "algo-name" -#define IMAGE_PRE_LOAD_PROP_PADDING_NAME "padding-name" -#define IMAGE_PRE_LOAD_PROP_SIG_SIZE "signature-size" -#define IMAGE_PRE_LOAD_PROP_PUBLIC_KEY "public-key" -#define IMAGE_PRE_LOAD_PROP_MANDATORY "mandatory" - -/* - * Information in the device-tree about the signature in the header - */ -struct image_sig_info { - char *algo_name; /* Name of the algo (eg: sha256,rsa2048) */ - char *padding_name; /* Name of the padding */ - u8 *key; /* Public signature key */ - int key_len; /* Length of the public key */ - u32 sig_size; /* size of the signature (in the header) */ - int mandatory; /* Set if the signature is mandatory */ - - struct image_sign_info sig_info; /* Signature info */ -}; - -/* - * Header of the signature header - */ -struct sig_header_s { - u32 magic; - u32 version; - u32 header_size; - u32 image_size; - u32 offset_img_sig; - u32 flags; - u32 reserved0; - u32 reserved1; - u8 sha256_img_sig[SHA256_SUM_LEN]; -}; - -#define SIG_HEADER_LEN (sizeof(struct sig_header_s)) - /* * Offset of the image * diff --git a/include/image.h b/include/image.h index eb2513c5b7..d7d6a3fe5b 100644 --- a/include/image.h +++ b/include/image.h @@ -1421,6 +1421,49 @@ struct crypto_algo *image_get_crypto_algo(const char *full_name); */ struct padding_algo *image_get_padding_algo(const char *name); +#define IMAGE_PRE_LOAD_SIG_MAGIC 0x55425348 +#define IMAGE_PRE_LOAD_SIG_OFFSET_MAGIC 0 +#define IMAGE_PRE_LOAD_SIG_OFFSET_IMG_LEN 4 +#define IMAGE_PRE_LOAD_SIG_OFFSET_SIG 8 + +#define IMAGE_PRE_LOAD_PATH "/image/pre-load/sig" +#define IMAGE_PRE_LOAD_PROP_ALGO_NAME "algo-name" +#define IMAGE_PRE_LOAD_PROP_PADDING_NAME "padding-name" +#define IMAGE_PRE_LOAD_PROP_SIG_SIZE "signature-size" +#define IMAGE_PRE_LOAD_PROP_PUBLIC_KEY "public-key" +#define IMAGE_PRE_LOAD_PROP_MANDATORY "mandatory" + +/* + * Information in the device-tree about the signature in the header + */ +struct image_sig_info { + char *algo_name; /* Name of the algo (eg: sha256,rsa2048) */ + char *padding_name; /* Name of the padding */ + uint8_t *key; /* Public signature key */ + int key_len; /* Length of the public key */ + uint32_t sig_size; /* size of the signature (in the header) */ + int mandatory; /* Set if the signature is mandatory */ + + struct image_sign_info sig_info; /* Signature info */ +}; + +/* + * Header of the signature header + */ +struct sig_header_s { + uint32_t magic; + uint32_t version; + uint32_t header_size; + uint32_t image_size; + uint32_t offset_img_sig; + uint32_t flags; + uint32_t reserved0; + uint32_t reserved1; + uint8_t sha256_img_sig[SHA256_SUM_LEN]; +}; + +#define SIG_HEADER_LEN (sizeof(struct sig_header_s)) + /** * image_pre_load() - Manage pre load header * diff --git a/tools/image-host.c b/tools/image-host.c index 698adfb3e1..0bf18df50e 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -17,8 +17,6 @@ #include #include -#define IMAGE_PRE_LOAD_PATH "/image/pre-load/sig" - /** * fit_set_hash_value - set hash value in requested has node * @fit: pointer to the FIT format image header From 05b0f241f271415d9a26416a5bec316f29a2583f Mon Sep 17 00:00:00 2001 From: Steven Lawrance Date: Wed, 14 Sep 2022 20:57:28 +0200 Subject: [PATCH 05/13] boot: image-pre-load: Check environment for location of signature info Setting an alternative signature info node in "pre_load_sig_info_path" allows verification of an image using the bootm pre-load mechanism with a different key, e.g.: setenv pre_load_sig_info_path "/alt/sig" ; bootm preload [addr] Signed-off-by: Steven Lawrance Reviewed-by: Simon Glass --- boot/image-pre-load.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/boot/image-pre-load.c b/boot/image-pre-load.c index 01b60030fc..b504ab42a5 100644 --- a/boot/image-pre-load.c +++ b/boot/image-pre-load.c @@ -33,6 +33,7 @@ static int image_pre_load_sig_setup(struct image_sig_info *info) const u32 *sig_size; int key_len; int node, ret = 0; + char *sig_info_path = NULL; if (!info) { log_err("ERROR: info is NULL for image pre-load sig check\n"); @@ -42,7 +43,11 @@ static int image_pre_load_sig_setup(struct image_sig_info *info) memset(info, 0, sizeof(*info)); - node = fdt_path_offset(gd_fdt_blob(), IMAGE_PRE_LOAD_PATH); + sig_info_path = env_get("pre_load_sig_info_path"); + if (!sig_info_path) + sig_info_path = IMAGE_PRE_LOAD_PATH; + + node = fdt_path_offset(gd_fdt_blob(), sig_info_path); if (node < 0) { log_info("INFO: no info for image pre-load sig check\n"); ret = 1; From 45455e8ff5634e77aede803f9a772dba08b9674f Mon Sep 17 00:00:00 2001 From: Jim Liu Date: Tue, 13 Sep 2022 14:23:15 +0800 Subject: [PATCH 06/13] pinctrl: nuvoton: fix set persist error CA9C is cortex A9 watchdog reset control bit. if device set persist mode, it shouldn't set this bit. Signed-off-by: Jim Liu --- drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c b/drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c index f6e20415e2..31678f5537 100644 --- a/drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +++ b/drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c @@ -1388,10 +1388,10 @@ static int npcm7xx_gpio_reset_persist(struct udevice *dev, unsigned int banknum, dev_dbg(dev, "set gpio persist, bank %d, enable %d\n", banknum, enable); if (enable) { - regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_WD0RCR, BIT(num) | CA9C_RESET, 0); - regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_WD1RCR, BIT(num) | CA9C_RESET, 0); - regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_WD2RCR, BIT(num) | CA9C_RESET, 0); - regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_CORSTC, BIT(num) | CA9C_RESET, 0); + regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_WD0RCR, BIT(num), 0); + regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_WD1RCR, BIT(num), 0); + regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_WD2RCR, BIT(num), 0); + regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_CORSTC, BIT(num), 0); } else { regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_WD0RCR, BIT(num) | CA9C_RESET, BIT(num) | CA9C_RESET); regmap_update_bits(priv->rst_regmap, NPCM7XX_RST_WD1RCR, BIT(num) | CA9C_RESET, BIT(num) | CA9C_RESET); From 7eda1a95331d1ccd17e5af6fb18bf5577f81a451 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Wed, 7 Sep 2022 12:11:42 +0100 Subject: [PATCH 07/13] pinctrl: fix buffer size for pinctrl_generic_set_state_prefix() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This buffer has the concatenated prefix and name written into it, so it must be large enough to cover both strings plus the terminating NUL. Fixes: 92c4a95ec7 ("pinctrl: Add new function pinctrl_generic_set_state_prefix()") Signed-off-by: John Keeping Reviewed-by: Pali Rohár Reviewed-by: Simon Glass --- drivers/pinctrl/pinctrl-generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pinctrl/pinctrl-generic.c b/drivers/pinctrl/pinctrl-generic.c index ec21d4ff83..8909b57810 100644 --- a/drivers/pinctrl/pinctrl-generic.c +++ b/drivers/pinctrl/pinctrl-generic.c @@ -237,7 +237,7 @@ enum pinmux_subnode_type { static const char *alloc_name_with_prefix(const char *name, const char *prefix) { if (prefix) { - char *name_with_prefix = malloc(strlen(prefix) + sizeof("pins")); + char *name_with_prefix = malloc(strlen(prefix) + strlen(name) + 1); if (name_with_prefix) sprintf(name_with_prefix, "%s%s", prefix, name); return name_with_prefix; From 690a1d694899c55c7cc6a168c54984f765ff761e Mon Sep 17 00:00:00 2001 From: Roger Knecht Date: Sat, 3 Sep 2022 11:34:53 +0000 Subject: [PATCH 08/13] cmd: cat: add new command Add cat command to print file content to standard out Reviewed-by: Simon Glass Signed-off-by: Roger Knecht --- MAINTAINERS | 5 ++ cmd/Kconfig | 5 ++ cmd/Makefile | 1 + cmd/cat.c | 85 ++++++++++++++++++++++++++++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + doc/usage/cmd/cat.rst | 49 +++++++++++++++++ doc/usage/index.rst | 1 + test/py/tests/test_cat/conftest.py | 35 ++++++++++++ test/py/tests/test_cat/test_cat.py | 20 +++++++ 10 files changed, 203 insertions(+) create mode 100644 cmd/cat.c create mode 100644 doc/usage/cmd/cat.rst create mode 100644 test/py/tests/test_cat/conftest.py create mode 100644 test/py/tests/test_cat/test_cat.py diff --git a/MAINTAINERS b/MAINTAINERS index 3377866849..1c9939e331 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -786,6 +786,11 @@ M: Simon Glass S: Maintained F: tools/buildman/ +CAT +M: Roger Knecht +S: Maintained +F: cmd/cat.c + CFI FLASH M: Stefan Roese S: Maintained diff --git a/cmd/Kconfig b/cmd/Kconfig index 6f00bd9307..3267811b25 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1533,6 +1533,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 cf6ce1bd6f..4bd52bb257 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 diff --git a/cmd/cat.c b/cmd/cat.c new file mode 100644 index 0000000000..1273a26b14 --- /dev/null +++ b/cmd/cat.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2022 + * Roger Knecht + */ + +#include +#include +#include +#include +#include + +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[] = + " \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/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index b20b181ab1..0926e9213e 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -22,6 +22,7 @@ CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_PRE_CONSOLE_BUFFER=y CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_CMD_CAT=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index df6a28ef24..e1832295dc 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -36,6 +36,7 @@ CONFIG_LOG_DEFAULT_LEVEL=6 CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y +CONFIG_CMD_CAT=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTM_PRE_LOAD=y diff --git a/doc/usage/cmd/cat.rst b/doc/usage/cmd/cat.rst new file mode 100644 index 0000000000..5ef4731fe3 --- /dev/null +++ b/doc/usage/cmd/cat.rst @@ -0,0 +1,49 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +cat command +=============== + +Synopsis +-------- + +:: + + cat + +Description +----------- + +The cat command prints the file content to standard out. + +interface + interface for accessing the block device (mmc, sata, scsi, usb, ....) + +dev + device number + +part + partition number, defaults to 1 + +file + path to file + +Example +------- + +Here is the output for a example text file: + +:: + + => cat mmc 0:1 hello + hello world + => + +Configuration +------------- + +The cat command is only available if CONFIG_CMD_CAT=y. + +Return value +------------ + +The return value $? is set to 0 (true) if the file is readable, otherwise it returns a non-zero error code. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index d0641105ae..a05aa42485 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -31,6 +31,7 @@ Shell commands cmd/bootmeth cmd/button cmd/bootz + cmd/cat cmd/cbsysinfo cmd/cls cmd/conitrace diff --git a/test/py/tests/test_cat/conftest.py b/test/py/tests/test_cat/conftest.py new file mode 100644 index 0000000000..058fe52352 --- /dev/null +++ b/test/py/tests/test_cat/conftest.py @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0+ + +"""Fixture for cat command test +""" + +import os +import shutil +from subprocess import check_call, CalledProcessError +import pytest + +@pytest.fixture(scope='session') +def cat_data(u_boot_config): + """Set up a file system to be used in cat tests + + Args: + u_boot_config -- U-boot configuration. + """ + mnt_point = u_boot_config.persistent_data_dir + '/test_cat' + image_path = u_boot_config.persistent_data_dir + '/cat.img' + + try: + os.mkdir(mnt_point, mode = 0o755) + + with open(mnt_point + '/hello', 'w', encoding = 'ascii') as file: + file.write('hello world\n') + + check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', + shell=True) + + yield image_path + except CalledProcessError: + pytest.skip('Setup failed') + finally: + shutil.rmtree(mnt_point) + os.remove(image_path) diff --git a/test/py/tests/test_cat/test_cat.py b/test/py/tests/test_cat/test_cat.py new file mode 100644 index 0000000000..132527bd4c --- /dev/null +++ b/test/py/tests/test_cat/test_cat.py @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0+ + +""" Unit test for cat command +""" + +import pytest + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_cat') +def test_cat(u_boot_console, cat_data): + """ Unit test for cat + + Args: + u_boot_console -- U-Boot console + cat_data -- Path to the disk image used for testing. + """ + response = u_boot_console.run_command_list([ + f'host bind 0 {cat_data}', + 'cat host 0 hello']) + assert 'hello world' in response From 23c0df6e7cd3f220a81151b662f0280bba0054b9 Mon Sep 17 00:00:00 2001 From: Roger Knecht Date: Sat, 3 Sep 2022 13:15:04 +0000 Subject: [PATCH 09/13] cmd: xxd: add new command Add xxd command to print file content as hexdump to standard out Reviewed-by: Simon Glass Signed-off-by: Roger Knecht --- MAINTAINERS | 7 +++ cmd/Kconfig | 5 ++ cmd/Makefile | 1 + cmd/xxd.c | 85 ++++++++++++++++++++++++++++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + doc/usage/cmd/xxd.rst | 50 ++++++++++++++++++ doc/usage/index.rst | 1 + test/py/tests/test_xxd/conftest.py | 35 ++++++++++++ test/py/tests/test_xxd/test_xxd.py | 23 ++++++++ 10 files changed, 209 insertions(+) create mode 100644 cmd/xxd.c create mode 100644 doc/usage/cmd/xxd.rst create mode 100644 test/py/tests/test_xxd/conftest.py create mode 100644 test/py/tests/test_xxd/test_xxd.py diff --git a/MAINTAINERS b/MAINTAINERS index 1c9939e331..cb4d44584d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1519,6 +1519,13 @@ M: Max Filippov S: Maintained F: arch/xtensa/ +XXD +M: Roger Knecht +S: Maintained +F: cmd/xxd.c +F: doc/usage/cmd/xxd.rst +F: test/py/tests/test_xxd/ + THE REST M: Tom Rini L: u-boot@lists.denx.de diff --git a/cmd/Kconfig b/cmd/Kconfig index 3267811b25..8eeb7ea081 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 diff --git a/cmd/Makefile b/cmd/Makefile index 4bd52bb257..d9bbd0b9fd 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -185,6 +185,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/xxd.c b/cmd/xxd.c new file mode 100644 index 0000000000..742a85c7a9 --- /dev/null +++ b/cmd/xxd.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2022 + * Roger Knecht + */ + +#include +#include +#include +#include +#include +#include + +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[] = + " \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 +); diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index 0926e9213e..ade1505439 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -55,6 +55,7 @@ CONFIG_CMD_READ=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y +CONFIG_CMD_XXD=y CONFIG_BOOTP_DNS2=y CONFIG_CMD_TFTPPUT=y CONFIG_CMD_TFTPSRV=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index e1832295dc..195271463b 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -61,6 +61,7 @@ CONFIG_CMD_MEM_SEARCH=y CONFIG_CMD_MX_CYCLIC=y CONFIG_CMD_MEMTEST=y CONFIG_CMD_UNZIP=y +CONFIG_CMD_XXD=y CONFIG_CMD_BIND=y CONFIG_CMD_DEMO=y CONFIG_CMD_GPIO=y diff --git a/doc/usage/cmd/xxd.rst b/doc/usage/cmd/xxd.rst new file mode 100644 index 0000000000..0de1223dce --- /dev/null +++ b/doc/usage/cmd/xxd.rst @@ -0,0 +1,50 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +xxd command +=============== + +Synopsis +-------- + +:: + + xxd + +Description +----------- + +The xxd command prints the file content as hexdump to standard out. + +interface + interface for accessing the block device (mmc, sata, scsi, usb, ....) + +dev + device number + +part + partition number, defaults to 1 + +file + path to file + +Example +------- + +Here is the output for a example text file: + +:: + + => xxd mmc 0:1 hello + 00000000: 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 01 02 03 hello world..... + 00000010: 04 05 .. + => + +Configuration +------------- + +The xxd command is only available if CONFIG_CMD_XXD=y. + +Return value +------------ + +The return value $? is set to 0 (true) if the file is readable, otherwise it returns a non-zero error code. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index a05aa42485..64a265879d 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -72,6 +72,7 @@ Shell commands cmd/true cmd/ums cmd/wdt + cmd/xxd Booting OS ---------- diff --git a/test/py/tests/test_xxd/conftest.py b/test/py/tests/test_xxd/conftest.py new file mode 100644 index 0000000000..59285aadf4 --- /dev/null +++ b/test/py/tests/test_xxd/conftest.py @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0+ + +"""Fixture for xxd command test +""" + +import os +import shutil +from subprocess import check_call, CalledProcessError +import pytest + +@pytest.fixture(scope='session') +def xxd_data(u_boot_config): + """Set up a file system to be used in xxd tests + + Args: + u_boot_config -- U-boot configuration. + """ + mnt_point = u_boot_config.persistent_data_dir + '/test_xxd' + image_path = u_boot_config.persistent_data_dir + '/xxd.img' + + try: + os.mkdir(mnt_point, mode = 0o755) + + with open(mnt_point + '/hello', 'w', encoding = 'ascii') as file: + file.write('hello world\n\x00\x01\x02\x03\x04\x05') + + check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', + shell=True) + + yield image_path + except CalledProcessError: + pytest.skip('Setup failed') + finally: + shutil.rmtree(mnt_point) + os.remove(image_path) diff --git a/test/py/tests/test_xxd/test_xxd.py b/test/py/tests/test_xxd/test_xxd.py new file mode 100644 index 0000000000..06b9cfc000 --- /dev/null +++ b/test/py/tests/test_xxd/test_xxd.py @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: GPL-2.0+ + +""" Unit test for xxd command +""" + +import pytest + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_xxd') +def test_xxd(u_boot_console, xxd_data): + """ Unit test for xxd + + Args: + u_boot_console -- U-Boot console + xxd_data -- Path to the disk image used for testing. + """ + response = u_boot_console.run_command_list([ + f'host bind 0 {xxd_data}', + 'xxd host 0 hello']) + + assert '00000000: 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 01 02 03 hello world.....\r\r\n' + \ + '00000010: 04 05 ..' \ + in response From 7f673bb8f52894eec641b287d9bb19fa603142c6 Mon Sep 17 00:00:00 2001 From: Robert Marko Date: Tue, 6 Sep 2022 13:30:33 +0200 Subject: [PATCH 10/13] cmd: add temperature command Currently, there is no way for users to check the readings from thermal sensors from U-boot console, only some boards print it during boot. So, lets add a simple "temperature" command that allows listing thermal uclass devices and getting their value. Note that the thermal devices are intenionally probed if list is used as almost always they will not get probed otherwise and there is no way for users to manually call probe on a certain device from console. Assumption is made that temperature is returned in degrees C and not milidegrees like in Linux as this is what most drivers seem to return. Signed-off-by: Robert Marko Reviewed-by: Simon Glass --- cmd/Kconfig | 6 ++++ cmd/Makefile | 1 + cmd/temperature.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 cmd/temperature.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 8eeb7ea081..49247a41c0 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1454,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 diff --git a/cmd/Makefile b/cmd/Makefile index d9bbd0b9fd..c95e09d058 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -156,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 diff --git a/cmd/temperature.c b/cmd/temperature.c new file mode 100644 index 0000000000..420965de14 --- /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 + */ + +#include +#include +#include +#include + +#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" +); From 0995e81e10c10fda32c6dec350d14473d6d1d23e Mon Sep 17 00:00:00 2001 From: Robert Marko Date: Tue, 6 Sep 2022 13:30:34 +0200 Subject: [PATCH 11/13] doc: cmd: temperature: add documentation Add documentation for the temperature command. Signed-off-by: Robert Marko Reviewed-by: Simon Glass --- doc/usage/cmd/temperature.rst | 50 +++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 51 insertions(+) create mode 100644 doc/usage/cmd/temperature.rst diff --git a/doc/usage/cmd/temperature.rst b/doc/usage/cmd/temperature.rst new file mode 100644 index 0000000000..a5144ec50f --- /dev/null +++ b/doc/usage/cmd/temperature.rst @@ -0,0 +1,50 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +temperature command +=================== + +Synopsis +-------- + +:: + + temperature list + temperature get [thermal device name] + +Description +----------- + +The *temperature* command is used to list thermal sensors and get their +readings. + +The 'temperature list' command diplays the available thermal devices. + +The 'temperature get' command is used to get the reading in degrees C from +the desired device which is selected by passing its device name. + + thermal device name + device name of thermal sensor to select + +Example +------- + +:: + + + => temperature list + | Device | Driver | Parent + | tmon@610508110 | sparx5-temp | axi@600000000 + => + => temperature get tmon@610508110 + tmon@610508110: 42 C + +Configuration +------------- + +The *temperature* command is only available if CONFIG_CMD_TEMPERATURE=y. + +Return value +------------ + +The return value $? is set to 0 (true) if the command succeeded and to 1 (false) +otherwise. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 64a265879d..90221015ee 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -68,6 +68,7 @@ Shell commands cmd/scp03 cmd/setexpr cmd/size + cmd/temperature cmd/tftpput cmd/true cmd/ums From 1fad2cb852581ff34c2f115ec07b1bba9eef8342 Mon Sep 17 00:00:00 2001 From: Robert Marko Date: Tue, 6 Sep 2022 13:30:35 +0200 Subject: [PATCH 12/13] thermal: add sandbox driver Provide a simple sandbox driver for the thermal uclass. It simply registers and returns 100 degrees C if requested. Signed-off-by: Robert Marko Reviewed-by: Simon Glass --- arch/sandbox/dts/sandbox.dtsi | 4 ++++ arch/sandbox/dts/test.dts | 4 ++++ configs/sandbox_defconfig | 2 ++ configs/sandbox_flattree_defconfig | 2 ++ configs/sandbox_noinst_defconfig | 2 ++ configs/sandbox_spl_defconfig | 2 ++ configs/sandbox_vpl_defconfig | 2 ++ drivers/thermal/Makefile | 1 + drivers/thermal/thermal_sandbox.c | 36 ++++++++++++++++++++++++++++++ 9 files changed, 55 insertions(+) create mode 100644 drivers/thermal/thermal_sandbox.c diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index de7a218f45..d2db1ea522 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -443,6 +443,10 @@ sandbox_tee { compatible = "sandbox,tee"; }; + + thermal { + compatible = "sandbox,thermal"; + }; }; &cros_ec { diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index a7b49f315b..b853e13f92 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -1694,6 +1694,10 @@ compatible = "sandbox,regmap_test"; }; }; + + thermal { + compatible = "sandbox,thermal"; + }; }; #include "sandbox_pmic.dtsi" diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 195271463b..1f821cd472 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -79,6 +79,7 @@ CONFIG_CMD_PCI=y CONFIG_CMD_READ=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SPI=y +CONFIG_CMD_TEMPERATURE=y CONFIG_CMD_USB=y CONFIG_CMD_AXI=y CONFIG_CMD_SETEXPR_FMT=y @@ -281,6 +282,7 @@ CONFIG_SYSINFO=y CONFIG_SYSINFO_SANDBOX=y CONFIG_SYSINFO_GPIO=y CONFIG_SYSRESET=y +CONFIG_DM_THERMAL=y CONFIG_TIMER=y CONFIG_TIMER_EARLY=y CONFIG_SANDBOX_TIMER=y diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index a2eb7afcf9..fdd7b35118 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -45,6 +45,7 @@ CONFIG_CMD_OSD=y CONFIG_CMD_PCI=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SPI=y +CONFIG_CMD_TEMPERATURE=y CONFIG_CMD_USB=y CONFIG_BOOTP_DNS2=y CONFIG_CMD_TFTPPUT=y @@ -186,6 +187,7 @@ CONFIG_SYSINFO=y CONFIG_SYSINFO_SANDBOX=y CONFIG_SYSINFO_GPIO=y CONFIG_SYSRESET=y +CONFIG_DM_THERMAL=y CONFIG_TIMER=y CONFIG_TIMER_EARLY=y CONFIG_SANDBOX_TIMER=y diff --git a/configs/sandbox_noinst_defconfig b/configs/sandbox_noinst_defconfig index 8bf10bb3ee..8e69f084ed 100644 --- a/configs/sandbox_noinst_defconfig +++ b/configs/sandbox_noinst_defconfig @@ -62,6 +62,7 @@ CONFIG_CMD_OSD=y CONFIG_CMD_PCI=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SPI=y +CONFIG_CMD_TEMPERATURE=y CONFIG_CMD_USB=y CONFIG_BOOTP_DNS2=y CONFIG_CMD_TFTPPUT=y @@ -213,6 +214,7 @@ CONFIG_SYSINFO_SANDBOX=y CONFIG_SYSINFO_GPIO=y CONFIG_SYSRESET=y CONFIG_SPL_SYSRESET=y +CONFIG_DM_THERMAL=y CONFIG_TIMER=y CONFIG_TIMER_EARLY=y CONFIG_SANDBOX_TIMER=y diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index c33f17186d..af5092b5ca 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -62,6 +62,7 @@ CONFIG_CMD_OSD=y CONFIG_CMD_PCI=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SPI=y +CONFIG_CMD_TEMPERATURE=y CONFIG_CMD_USB=y CONFIG_BOOTP_DNS2=y CONFIG_CMD_TFTPPUT=y @@ -216,6 +217,7 @@ CONFIG_SYSINFO_SANDBOX=y CONFIG_SYSINFO_GPIO=y CONFIG_SYSRESET=y CONFIG_SPL_SYSRESET=y +CONFIG_DM_THERMAL=y CONFIG_TIMER=y CONFIG_TIMER_EARLY=y CONFIG_SANDBOX_TIMER=y diff --git a/configs/sandbox_vpl_defconfig b/configs/sandbox_vpl_defconfig index be8186ead3..c31adbbcf7 100644 --- a/configs/sandbox_vpl_defconfig +++ b/configs/sandbox_vpl_defconfig @@ -74,6 +74,7 @@ CONFIG_CMD_OSD=y CONFIG_CMD_PCI=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SPI=y +CONFIG_CMD_TEMPERATURE=y CONFIG_CMD_USB=y CONFIG_BOOTP_DNS2=y CONFIG_CMD_TFTPPUT=y @@ -223,6 +224,7 @@ CONFIG_SYSINFO_GPIO=y CONFIG_SYSRESET=y CONFIG_SPL_SYSRESET=y CONFIG_TPL_SYSRESET=y +CONFIG_DM_THERMAL=y CONFIG_TIMER=y CONFIG_TIMER_EARLY=y CONFIG_SANDBOX_TIMER=y diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 15fe847d9f..8acc7d20cb 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -4,6 +4,7 @@ # Author: Nitin Garg obj-$(CONFIG_DM_THERMAL) += thermal-uclass.o +obj-$(CONFIG_SANDBOX) += thermal_sandbox.o obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o obj-$(CONFIG_IMX_SCU_THERMAL) += imx_scu_thermal.o obj-$(CONFIG_TI_DRA7_THERMAL) += ti-bandgap.o diff --git a/drivers/thermal/thermal_sandbox.c b/drivers/thermal/thermal_sandbox.c new file mode 100644 index 0000000000..acc364feb0 --- /dev/null +++ b/drivers/thermal/thermal_sandbox.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Sartura Ltd. + * Written by Robert Marko + * + * Sandbox driver for the thermal uclass. + */ + +#include +#include +#include + +int sandbox_thermal_get_temp(struct udevice *dev, int *temp) +{ + /* Simply return 100°C */ + *temp = 100; + + return 0; +} + +static const struct dm_thermal_ops sandbox_thermal_ops = { + .get_temp = sandbox_thermal_get_temp, +}; + +static const struct udevice_id sandbox_thermal_ids[] = { + { .compatible = "sandbox,thermal" }, + { } +}; + +U_BOOT_DRIVER(thermal_sandbox) = { + .name = "thermal-sandbox", + .id = UCLASS_THERMAL, + .of_match = sandbox_thermal_ids, + .ops = &sandbox_thermal_ops, + .flags = DM_FLAG_PRE_RELOC, +}; From c68e73b65fb9101e3234586db29c3a04e9b37534 Mon Sep 17 00:00:00 2001 From: Robert Marko Date: Tue, 6 Sep 2022 13:30:36 +0200 Subject: [PATCH 13/13] test: cmd: add test for temperature command Add simple test for the temperature command. Signed-off-by: Robert Marko Reviewed-by: Simon Glass --- test/cmd/Makefile | 1 + test/cmd/temperature.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/cmd/temperature.c diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 1bb02d93a2..b7b9bd43f6 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -16,3 +16,4 @@ obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o obj-$(CONFIG_CMD_PINMUX) += pinmux.o obj-$(CONFIG_CMD_PWM) += pwm.o obj-$(CONFIG_CMD_SETEXPR) += setexpr.o +obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o diff --git a/test/cmd/temperature.c b/test/cmd/temperature.c new file mode 100644 index 0000000000..2a1ea0611d --- /dev/null +++ b/test/cmd/temperature.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Executes tests for temperature command + * + * Copyright (C) 2022 Sartura Ltd. + */ + +#include +#include +#include +#include +#include +#include + +static int dm_test_cmd_temperature(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device(UCLASS_THERMAL, 0, &dev)); + ut_assertnonnull(dev); + + ut_assertok(console_record_reset_enable()); + + /* Test that "temperature list" shows the sandbox device */ + ut_assertok(run_command("temperature list", 0)); + ut_assert_nextline("| Device | Driver | Parent"); + ut_assert_nextline("| thermal | thermal-sandbox | root_driver"); + ut_assert_console_end(); + + /* Test that "temperature get thermal" returns expected value */ + console_record_reset(); + ut_assertok(run_command("temperature get thermal", 0)); + ut_assert_nextline("thermal: 100 C"); + ut_assert_console_end(); + + return 0; +} + +DM_TEST(dm_test_cmd_temperature, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);