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