Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
| 9 | |
| 10 | static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 11 | { |
| 12 | unsigned long src, dst; |
| 13 | unsigned long src_len = ~0UL, dst_len = ~0UL; |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 14 | |
| 15 | switch (argc) { |
| 16 | case 4: |
| 17 | dst_len = simple_strtoul(argv[3], NULL, 16); |
| 18 | /* fall through */ |
| 19 | case 3: |
| 20 | src = simple_strtoul(argv[1], NULL, 16); |
| 21 | dst = simple_strtoul(argv[2], NULL, 16); |
| 22 | break; |
| 23 | default: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 24 | return CMD_RET_USAGE; |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | if (gunzip((void *) dst, dst_len, (void *) src, &src_len) != 0) |
| 28 | return 1; |
| 29 | |
Heinrich Schuchardt | 9ae2ddc | 2019-01-06 12:34:16 +0100 | [diff] [blame] | 30 | printf("Uncompressed size: %lu = 0x%lX\n", src_len, src_len); |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 31 | env_set_hex("filesize", src_len); |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | U_BOOT_CMD( |
| 37 | unzip, 4, 1, do_unzip, |
| 38 | "unzip a memory region", |
| 39 | "srcaddr dstaddr [dstsize]" |
| 40 | ); |
Eric Nelson | 5d27223 | 2015-02-15 16:16:07 -0700 | [diff] [blame] | 41 | |
| 42 | static int do_gzwrite(cmd_tbl_t *cmdtp, int flag, |
| 43 | int argc, char * const argv[]) |
| 44 | { |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 45 | struct blk_desc *bdev; |
Eric Nelson | 5d27223 | 2015-02-15 16:16:07 -0700 | [diff] [blame] | 46 | int ret; |
| 47 | unsigned char *addr; |
| 48 | unsigned long length; |
| 49 | unsigned long writebuf = 1<<20; |
| 50 | u64 startoffs = 0; |
| 51 | u64 szexpected = 0; |
| 52 | |
| 53 | if (argc < 5) |
| 54 | return CMD_RET_USAGE; |
Simon Glass | ebac37c | 2016-02-29 15:25:43 -0700 | [diff] [blame] | 55 | ret = blk_get_device_by_str(argv[1], argv[2], &bdev); |
Eric Nelson | 5d27223 | 2015-02-15 16:16:07 -0700 | [diff] [blame] | 56 | if (ret < 0) |
| 57 | return CMD_RET_FAILURE; |
| 58 | |
| 59 | addr = (unsigned char *)simple_strtoul(argv[3], NULL, 16); |
| 60 | length = simple_strtoul(argv[4], NULL, 16); |
| 61 | |
| 62 | if (5 < argc) { |
| 63 | writebuf = simple_strtoul(argv[5], NULL, 16); |
| 64 | if (6 < argc) { |
| 65 | startoffs = simple_strtoull(argv[6], NULL, 16); |
| 66 | if (7 < argc) |
| 67 | szexpected = simple_strtoull(argv[7], |
| 68 | NULL, 16); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | ret = gzwrite(addr, length, bdev, writebuf, startoffs, szexpected); |
| 73 | |
| 74 | return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS; |
| 75 | } |
| 76 | |
| 77 | U_BOOT_CMD( |
| 78 | gzwrite, 8, 0, do_gzwrite, |
| 79 | "unzip and write memory to block device", |
| 80 | "<interface> <dev> <addr> length [wbuf=1M [offs=0 [outsize=0]]]\n" |
| 81 | "\twbuf is the size in bytes (hex) of write buffer\n" |
| 82 | "\t\tand should be padded to erase size for SSDs\n" |
| 83 | "\toffs is the output start offset in bytes (hex)\n" |
| 84 | "\toutsize is the size of the expected output (hex bytes)\n" |
| 85 | "\t\tand is required for files with uncompressed lengths\n" |
| 86 | "\t\t4 GiB or larger\n" |
| 87 | ); |