From 550a9e7902ce2a6103d97d70a22bad64e4fab7fd Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 28 Jul 2020 19:41:14 -0600 Subject: cmd: Update the memory-search command Add various fixes and improvements to this command that were missed in the original version. Unfortunately I forgot to send v2. - Fix Kconfig name - Use a separate variable for the remaining search length - Correct a minor bug - Move into a separate test suite - Add -q flag to the 'quiet' test to test operation when console is enabled - Enable the feature for sandbox Signed-off-by: Simon Glass --- cmd/Kconfig | 2 +- cmd/mem.c | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index e11176451b1..6ac274e620e 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -724,7 +724,7 @@ config CMD_MEMORY base - print or set address offset loop - initialize loop on address range -config MEM_SEARCH +config CMD_MEM_SEARCH bool "ms - Memory search" help Memory-search command diff --git a/cmd/mem.c b/cmd/mem.c index 575893c18df..190e2b94a7d 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -53,7 +53,8 @@ static ulong dp_last_length = 0x40; static ulong mm_last_addr, mm_last_size; static ulong base_address = 0; -#ifdef CONFIG_MEM_SEARCH +#ifdef CONFIG_CMD_MEM_SEARCH +static ulong dp_last_ms_length; static u8 search_buf[64]; static uint search_len; #endif @@ -367,7 +368,7 @@ static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } -#ifdef CONFIG_MEM_SEARCH +#ifdef CONFIG_CMD_MEM_SEARCH static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -377,6 +378,7 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, ulong last_pos; /* Offset of last match in 'size' units*/ ulong last_addr; /* Address of last displayed line */ int limit = 10; + int used_len; int count; int size; int i; @@ -384,12 +386,12 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, /* We use the last specified parameters, unless new ones are entered */ addr = dp_last_addr; size = dp_last_size; - length = dp_last_length; + length = dp_last_ms_length; if (argc < 3) return CMD_RET_USAGE; - if ((!flag & CMD_FLAG_REPEAT)) { + if (!(flag & CMD_FLAG_REPEAT)) { /* * Check for a size specification. * Defaults to long if no or incorrect specification. @@ -398,7 +400,8 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, if (size < 0 && size != -2 /* string */) return 1; - argc--; argv++; + argc--; + argv++; while (argc && *argv[0] == '-') { int ch = argv[0][1]; @@ -408,7 +411,8 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, limit = simple_strtoul(argv[0] + 2, NULL, 16); else return CMD_RET_USAGE; - argc--; argv++; + argc--; + argv++; } /* Address is specified since argc > 1 */ @@ -421,7 +425,7 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, /* Read the bytes to search for */ end = search_buf + sizeof(search_buf); for (i = 2, ptr = search_buf; i < argc && ptr < end; i++) { - if (SUPPORT_64BIT_DATA && size == 8) { + if (MEM_SUPPORT_64BIT_DATA && size == 8) { u64 val = simple_strtoull(argv[i], NULL, 16); *(u64 *)ptr = val; @@ -460,7 +464,8 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, last_pos = 0; last_addr = 0; count = 0; - for (offset = 0; offset <= bytes - search_len && count < limit; + for (offset = 0; + offset < bytes && offset <= bytes - search_len && count < limit; offset += size) { void *ptr = buf + offset; @@ -495,9 +500,10 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, unmap_sysmem(buf); - dp_last_addr = addr + offset / size; + used_len = offset / size; + dp_last_addr = addr + used_len; dp_last_size = size; - dp_last_length = length - offset / size; + dp_last_ms_length = length < used_len ? 0 : length - used_len; return count ? 0 : CMD_RET_FAILURE; } @@ -1337,13 +1343,13 @@ U_BOOT_CMD( "[.b, .w, .l" HELP_Q "] addr1 addr2 count" ); -#ifdef CONFIG_MEM_SEARCH +#ifdef CONFIG_CMD_MEM_SEARCH /**************************************************/ U_BOOT_CMD( ms, 255, 1, do_mem_search, "memory search", "[.b, .w, .l" HELP_Q ", .s] [-q | -] address #-of-objects ..." - " -q = quiet, -l = match limit" : + " -q = quiet, -l = match limit" ); #endif -- cgit v1.3.1 From bba604b65e58f8e540ee60b57b9f9c78dcc83f04 Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Thu, 30 Jul 2020 15:33:48 +0200 Subject: fs/squashfs: add filesystem commands Add 'ls' and 'load' commands. Signed-off-by: Joao Marcos Costa --- MAINTAINERS | 1 + cmd/Kconfig | 6 ++++++ cmd/Makefile | 1 + cmd/sqfs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 cmd/sqfs.c (limited to 'cmd') diff --git a/MAINTAINERS b/MAINTAINERS index c2501e82f6a..8ec6c5db810 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -974,6 +974,7 @@ M: Joao Marcos Costa S: Maintained F: fs/squashfs/ F: include/sqfs.h +F: cmd/sqfs.c TARGET_BCMNS3 M: Bharat Gooty diff --git a/cmd/Kconfig b/cmd/Kconfig index 6ac274e620e..23d7e27dc8d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2090,6 +2090,12 @@ config CMD_FAT help Support for the FAT fs +config CMD_SQUASHFS + bool "SquashFS command support" + select FS_SQUASHFS + help + Enables SquashFS filesystem commands (e.g. load, ls). + config CMD_FS_GENERIC bool "filesystem commands" help diff --git a/cmd/Makefile b/cmd/Makefile index 70750375d12..ef2a22f9b12 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -63,6 +63,7 @@ obj-$(CONFIG_CMD_EXT4) += ext4.o obj-$(CONFIG_CMD_EXT2) += ext2.o obj-$(CONFIG_CMD_FAT) += fat.o obj-$(CONFIG_CMD_FDT) += fdt.o +obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o obj-$(CONFIG_CMD_FLASH) += flash.o obj-$(CONFIG_CMD_FPGA) += fpga.o obj-$(CONFIG_CMD_FPGAD) += fpgad.o diff --git a/cmd/sqfs.c b/cmd/sqfs.c new file mode 100644 index 00000000000..107038c4cf2 --- /dev/null +++ b/cmd/sqfs.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Bootlin + * + * Author: Joao Marcos Costa + * + * squashfs.c: implements SquashFS related commands + */ + +#include +#include +#include + +static int do_sqfs_ls(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SQUASHFS); +} + +U_BOOT_CMD(sqfsls, 4, 1, do_sqfs_ls, + "List files in directory. Default: root (/).", + " [] [directory]\n" + " - list files from 'dev' on 'interface' in 'directory'\n" +); + +static int do_sqfs_load(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + return do_load(cmdtp, flag, argc, argv, FS_TYPE_SQUASHFS); +} + +U_BOOT_CMD(sqfsload, 7, 0, do_sqfs_load, + "load binary file from a SquashFS filesystem", + " [ [ [ [bytes [pos]]]]]\n" + " - Load binary file 'filename' from 'dev' on 'interface'\n" + " to address 'addr' from SquashFS filesystem.\n" + " 'pos' gives the file position to start loading from.\n" + " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n" + " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n" + " the load stops on end of file.\n" + " If either 'pos' or 'bytes' are not aligned to\n" + " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n" + " be printed and performance will suffer for the load." +); -- cgit v1.3.1