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