2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-04-03 09:40:19 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2019-08-01 23:46:46 +08:00
|
|
|
#include <env.h>
|
2019-08-01 23:46:36 +08:00
|
|
|
#include <gzip.h>
|
2021-11-20 04:23:52 +08:00
|
|
|
#include <mapmem.h>
|
2020-05-11 01:39:58 +08:00
|
|
|
#include <part.h>
|
2011-04-03 09:40:19 +08:00
|
|
|
|
2020-05-11 01:40:03 +08:00
|
|
|
static int do_unzip(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2011-04-03 09:40:19 +08:00
|
|
|
{
|
|
|
|
unsigned long src, dst;
|
|
|
|
unsigned long src_len = ~0UL, dst_len = ~0UL;
|
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
case 4:
|
2021-07-24 23:03:29 +08:00
|
|
|
dst_len = hextoul(argv[3], NULL);
|
2011-04-03 09:40:19 +08:00
|
|
|
/* fall through */
|
|
|
|
case 3:
|
2021-07-24 23:03:29 +08:00
|
|
|
src = hextoul(argv[1], NULL);
|
|
|
|
dst = hextoul(argv[2], NULL);
|
2011-04-03 09:40:19 +08:00
|
|
|
break;
|
|
|
|
default:
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2011-04-03 09:40:19 +08:00
|
|
|
}
|
|
|
|
|
2021-11-20 04:23:52 +08:00
|
|
|
if (gunzip(map_sysmem(dst, dst_len), dst_len, map_sysmem(src, 0),
|
|
|
|
&src_len) != 0)
|
2011-04-03 09:40:19 +08:00
|
|
|
return 1;
|
|
|
|
|
2019-01-06 19:34:16 +08:00
|
|
|
printf("Uncompressed size: %lu = 0x%lX\n", src_len, src_len);
|
2017-08-04 02:22:10 +08:00
|
|
|
env_set_hex("filesize", src_len);
|
2011-04-03 09:40:19 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
unzip, 4, 1, do_unzip,
|
|
|
|
"unzip a memory region",
|
|
|
|
"srcaddr dstaddr [dstsize]"
|
|
|
|
);
|
2015-02-16 07:16:07 +08:00
|
|
|
|
2020-05-11 01:40:03 +08:00
|
|
|
static int do_gzwrite(struct cmd_tbl *cmdtp, int flag,
|
|
|
|
int argc, char *const argv[])
|
2015-02-16 07:16:07 +08:00
|
|
|
{
|
2016-03-01 06:25:34 +08:00
|
|
|
struct blk_desc *bdev;
|
2015-02-16 07:16:07 +08:00
|
|
|
int ret;
|
|
|
|
unsigned char *addr;
|
|
|
|
unsigned long length;
|
|
|
|
unsigned long writebuf = 1<<20;
|
|
|
|
u64 startoffs = 0;
|
|
|
|
u64 szexpected = 0;
|
|
|
|
|
|
|
|
if (argc < 5)
|
|
|
|
return CMD_RET_USAGE;
|
2016-03-01 06:25:43 +08:00
|
|
|
ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
|
2015-02-16 07:16:07 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
2021-07-24 23:03:29 +08:00
|
|
|
addr = (unsigned char *)hextoul(argv[3], NULL);
|
|
|
|
length = hextoul(argv[4], NULL);
|
2015-02-16 07:16:07 +08:00
|
|
|
|
|
|
|
if (5 < argc) {
|
2021-07-24 23:03:29 +08:00
|
|
|
writebuf = hextoul(argv[5], NULL);
|
2015-02-16 07:16:07 +08:00
|
|
|
if (6 < argc) {
|
|
|
|
startoffs = simple_strtoull(argv[6], NULL, 16);
|
|
|
|
if (7 < argc)
|
|
|
|
szexpected = simple_strtoull(argv[7],
|
|
|
|
NULL, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gzwrite(addr, length, bdev, writebuf, startoffs, szexpected);
|
|
|
|
|
|
|
|
return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
gzwrite, 8, 0, do_gzwrite,
|
|
|
|
"unzip and write memory to block device",
|
|
|
|
"<interface> <dev> <addr> length [wbuf=1M [offs=0 [outsize=0]]]\n"
|
|
|
|
"\twbuf is the size in bytes (hex) of write buffer\n"
|
|
|
|
"\t\tand should be padded to erase size for SSDs\n"
|
|
|
|
"\toffs is the output start offset in bytes (hex)\n"
|
|
|
|
"\toutsize is the size of the expected output (hex bytes)\n"
|
|
|
|
"\t\tand is required for files with uncompressed lengths\n"
|
|
|
|
"\t\t4 GiB or larger\n"
|
|
|
|
);
|