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