From a17322329b3b1526b23f8e1f6573a5d4f737c573 Mon Sep 17 00:00:00 2001 From: Yusuke Ashiduka Date: Thu, 20 Feb 2020 20:48:01 +0900 Subject: cmd: Add unlz4 command This command is a new command called "unlz4" that decompresses from memory into memory. Used with the CONFIG_CMD_UNLZ4 optionenabled. Signed-off-by: Yusuke Ashiduka [trini: Use %zd / %zX not %ld / %lX in printf] Signed-off-by: Tom Rini --- cmd/Kconfig | 7 +++++++ cmd/Makefile | 1 + cmd/unlz4.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 cmd/unlz4.c (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index faa133da65..0e2576262d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -770,6 +770,13 @@ config CMD_LZMADEC Support decompressing an LZMA (Lempel-Ziv-Markov chain algorithm) image from memory. +config CMD_UNLZ4 + bool "unlz4" + default y if CMD_BOOTI + select LZ4 + help + Support decompressing an LZ4 image from memory region. + config CMD_UNZIP bool "unzip" default y if CMD_BOOTI diff --git a/cmd/Makefile b/cmd/Makefile index f1dd513a4b..6692ed96c6 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -144,6 +144,7 @@ obj-$(CONFIG_CMD_TSI148) += tsi148.o obj-$(CONFIG_CMD_UBI) += ubi.o obj-$(CONFIG_CMD_UBIFS) += ubifs.o obj-$(CONFIG_CMD_UNIVERSE) += universe.o +obj-$(CONFIG_CMD_UNLZ4) += unlz4.o obj-$(CONFIG_CMD_UNZIP) += unzip.o obj-$(CONFIG_CMD_VIRTIO) += virtio.o obj-$(CONFIG_CMD_WDT) += wdt.o diff --git a/cmd/unlz4.c b/cmd/unlz4.c new file mode 100644 index 0000000000..5320b378d3 --- /dev/null +++ b/cmd/unlz4.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 + * FUJITSU COMPUTERTECHNOLOGIES LIMITED. All rights reserved. + */ + +#include +#include +#include +#include + +static int do_unlz4(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + unsigned long src, dst; + size_t src_len = ~0UL, dst_len = ~0UL; + int ret; + + switch (argc) { + case 4: + src = simple_strtoul(argv[1], NULL, 16); + dst = simple_strtoul(argv[2], NULL, 16); + dst_len = simple_strtoul(argv[3], NULL, 16); + break; + default: + return CMD_RET_USAGE; + } + + ret = ulz4fn((void *)src, src_len, (void *)dst, &dst_len); + if (ret) { + printf("Uncompressed err :%d\n", ret); + return 1; + } + + printf("Uncompressed size: %zd = 0x%zX\n", dst_len, dst_len); + env_set_hex("filesize", dst_len); + + return 0; +} + +U_BOOT_CMD(unlz4, 4, 1, do_unlz4, + "lz4 uncompress a memory region", + "srcaddr dstaddr dstsize\n" + "NOTE: Specify the destination size that is sufficiently larger\n" + " than the source size.\n" +); -- cgit From fd0e30b43b6b2401e68dc32c357869c617d4fdd1 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 26 Feb 2020 07:26:26 +0100 Subject: cmd: fat: remove unused includes Remove unused includes from cmd/fat.c. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- cmd/fat.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'cmd') diff --git a/cmd/fat.c b/cmd/fat.c index 50df127f6d..abce2f1e0c 100644 --- a/cmd/fat.c +++ b/cmd/fat.c @@ -8,13 +8,7 @@ * Boot support */ #include -#include -#include -#include -#include -#include #include -#include #include #include -- cgit From a8c708ea9f84cf637bb2bd5cfdcfd2dbbe71b86f Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Mar 2020 07:21:29 +0100 Subject: cmd: mem: Correctly count the errors in mtest This patch changes mtest to correctly count the overall errors and print them even in the abort (Ctrl-C) case. Signed-off-by: Stefan Roese --- cmd/mem.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'cmd') diff --git a/cmd/mem.c b/cmd/mem.c index 6d54f19527..9367278aa8 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -871,7 +871,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, ulong start, end; vu_long *buf, *dummy; ulong iteration_limit = 0; - int ret; + ulong count = 0; ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern = 0; int iteration; @@ -929,6 +929,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, } if (errs == -1UL) break; + count += errs; } /* @@ -947,14 +948,10 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */ putc('\n'); - ret = 1; - } else { - printf("Tested %d iteration(s) with %lu errors.\n", - iteration, errs); - ret = errs != 0; } + printf("Tested %d iteration(s) with %lu errors.\n", iteration, count); - return ret; + return errs != 0; } #endif /* CONFIG_CMD_MEMTEST */ -- cgit From 54de244c4779b452cc9314f475798d984fd27d0a Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Mar 2020 07:21:30 +0100 Subject: cmd: mem: Drop eldk-4.2 workaround and use cast in unmap_sysmem() Use a cast instead of the "eldk-4.2" workaround for unmap_sysmem(). Signed-off-by: Stefan Roese --- cmd/mem.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'cmd') diff --git a/cmd/mem.c b/cmd/mem.c index 9367278aa8..f519adaee2 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -932,18 +932,8 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, count += errs; } - /* - * Work-around for eldk-4.2 which gives this warning if we try to - * case in the unmap_sysmem() call: - * warning: initialization discards qualifiers from pointer target type - */ - { - void *vbuf = (void *)buf; - void *vdummy = (void *)dummy; - - unmap_sysmem(vbuf); - unmap_sysmem(vdummy); - } + unmap_sysmem((void *)buf); + unmap_sysmem((void *)dummy); if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */ -- cgit From f14bfa7ec6a5ec79e1c8dd48571b740922439912 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Mar 2020 07:21:31 +0100 Subject: cmd: mem: Use IS_ENABLED instead of alt_test variable This patch uses the IS_ENABLED() macro to check, which mtest variant is enabled. Signed-off-by: Stefan Roese --- cmd/mem.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'cmd') diff --git a/cmd/mem.c b/cmd/mem.c index f519adaee2..2ccc7032ad 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -875,11 +875,6 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern = 0; int iteration; -#if defined(CONFIG_SYS_ALT_MEMTEST) - const int alt_test = 1; -#else - const int alt_test = 0; -#endif start = CONFIG_SYS_MEMTEST_START; end = CONFIG_SYS_MEMTEST_END; @@ -921,7 +916,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, printf("Iteration: %6d\r", iteration + 1); debug("\n"); - if (alt_test) { + if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) { errs = mem_test_alt(buf, start, end, dummy); } else { errs = mem_test_quick(buf, start, end, pattern, -- cgit From 8e434cb705d463bc8cff935160e4fb4c77cb99ab Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Mar 2020 07:21:32 +0100 Subject: cmd: mem: Add bitflip memory test to alternate mtest This additional bitflip memory test is inspired by the bitflip test in memtester v4.3.0. It show some errors on some problematic GARDENA MT7688 based boards. The other memory tests usually don't show any errors here. Signed-off-by: Stefan Roese --- cmd/mem.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'cmd') diff --git a/cmd/mem.c b/cmd/mem.c index 2ccc7032ad..0bfb6081e7 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -801,6 +801,59 @@ static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, return errs; } +static int compare_regions(volatile unsigned long *bufa, + volatile unsigned long *bufb, size_t count) +{ + volatile unsigned long *p1 = bufa; + volatile unsigned long *p2 = bufb; + int errs = 0; + size_t i; + + for (i = 0; i < count; i++, p1++, p2++) { + if (*p1 != *p2) { + printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n", + (unsigned long)*p1, (unsigned long)*p2, + *p1 ^ *p2, __ffs(*p1 ^ *p2), + (unsigned long)(i * sizeof(unsigned long))); + errs++; + } + } + + return errs; +} + +static ulong test_bitflip_comparison(volatile unsigned long *bufa, + volatile unsigned long *bufb, size_t count) +{ + volatile unsigned long *p1 = bufa; + volatile unsigned long *p2 = bufb; + unsigned int j, k; + unsigned long q; + size_t i; + int max; + int errs = 0; + + max = sizeof(unsigned long) * 8; + for (k = 0; k < max; k++) { + q = 0x00000001L << k; + for (j = 0; j < 8; j++) { + WATCHDOG_RESET(); + q = ~q; + p1 = (volatile unsigned long *)bufa; + p2 = (volatile unsigned long *)bufb; + for (i = 0; i < count; i++) + *p1++ = *p2++ = (i % 2) == 0 ? q : ~q; + + errs += compare_regions(bufa, bufb, count); + } + + if (ctrlc()) + return -1UL; + } + + return errs; +} + static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, vu_long pattern, int iteration) { @@ -918,6 +971,13 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, debug("\n"); if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) { errs = mem_test_alt(buf, start, end, dummy); + if (errs == -1UL) + break; + count += errs; + errs = test_bitflip_comparison(buf, + buf + (end - start) / 2, + (end - start) / + sizeof(unsigned long)); } else { errs = mem_test_quick(buf, start, end, pattern, iteration); -- cgit From 414c34ed555b8ce5c260cf641261ecf45beca251 Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Thu, 5 Mar 2020 16:24:23 -0800 Subject: image: Add compressed Image parsing support in booti. Add compressed Image parsing support so that booti can parse both flat and compressed Image to boot Linux. Currently, it is difficult to calculate a safe address for every board where the compressed image can be decompressed. It is also not possible to figure out the size of the compressed file as well. Thus, user need to set two additional environment variables kernel_comp_addr_r and filesize to make this work. Following compression methods are supported for now. lzma, lzo, bzip2, gzip. lz4 support is not added as ARM64 kernel generates a lz4 compressed image with legacy header which U-Boot doesn't know how to parse and decompress. Tested on HiFive Unleashed and Qemu for RISC-V. Tested on Qemu for ARM64. Signed-off-by: Atish Patra Reviewed-by: Tom Rini [trini: Fix minor rST formatting problems] Signed-off-by: Tom Rini --- cmd/booti.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/booti.c b/cmd/booti.c index de5058236e..4fff8cfcf6 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -14,6 +14,7 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; /* * Image booting support */ @@ -24,6 +25,12 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, ulong ld; ulong relocated_addr; ulong image_size; + uint8_t *temp; + ulong dest; + ulong dest_end; + unsigned long comp_len; + unsigned long decomp_len; + int ctype; ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, images, 1); @@ -38,6 +45,33 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, debug("* kernel: cmdline image address = 0x%08lx\n", ld); } + temp = map_sysmem(ld, 0); + ctype = image_decomp_type(temp, 2); + if (ctype > 0) { + dest = env_get_ulong("kernel_comp_addr_r", 16, 0); + comp_len = env_get_ulong("kernel_comp_size", 16, 0); + if (!dest || !comp_len) { + puts("kernel_comp_addr_r or kernel_comp_size is not provided!\n"); + return -EINVAL; + } + if (dest < gd->ram_base || dest > gd->ram_top) { + puts("kernel_comp_addr_r is outside of DRAM range!\n"); + return -EINVAL; + } + + debug("kernel image compression type %d size = 0x%08lx address = 0x%08lx\n", + ctype, comp_len, (ulong)dest); + decomp_len = comp_len * 10; + ret = image_decomp(ctype, 0, ld, IH_TYPE_KERNEL, + (void *)dest, (void *)ld, comp_len, + decomp_len, &dest_end); + if (ret) + return ret; + /* dest_end contains the uncompressed Image size */ + memmove((void *) ld, (void *)dest, dest_end); + } + unmap_sysmem((void *)ld); + ret = booti_setup(ld, &relocated_addr, &image_size, false); if (ret != 0) return 1; @@ -100,10 +134,14 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #ifdef CONFIG_SYS_LONGHELP static char booti_help_text[] = "[addr [initrd[:size]] [fdt]]\n" - " - boot Linux 'Image' stored at 'addr'\n" + " - boot Linux flat or compressed 'Image' stored at 'addr'\n" "\tThe argument 'initrd' is optional and specifies the address\n" "\tof an initrd in memory. The optional parameter ':size' allows\n" "\tspecifying the size of a RAW initrd.\n" + "\tCurrently only booting from gz, bz2, lzma and lz4 compression\n" + "\ttypes are supported. In order to boot from any of these compressed\n" + "\timages, user have to set kernel_comp_addr_r and kernel_comp_size enviornment\n" + "\tvariables beforehand.\n" #if defined(CONFIG_OF_LIBFDT) "\tSince booting a Linux kernel requires a flat device-tree, a\n" "\tthird argument providing the address of the device-tree blob\n" -- cgit From 0563700672450c8d88d5f90840be499ee0c5a5eb Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 25 Feb 2020 21:44:05 +0100 Subject: Kconfig: fix typos in CMD_BEDBUG description Fix documentation bug reported by 'make refcheckdocs'. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass Reviewed-by: Patrick Delaunay --- cmd/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 0e2576262d..a46c77d69d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2103,7 +2103,7 @@ config CMD_BEDBUG help The bedbug (emBEDded deBUGger) command provides debugging features for some PowerPC processors. For details please see the - docuemntation in doc/README.beddbug + documentation in doc/README.bedbug. config CMD_DIAG bool "diag - Board diagnostics" -- cgit