Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 |
| 4 | * Lei Wen <leiwen@marvell.com>, Marvell Inc. |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | c7694dd | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 8 | #include <env.h> |
Michael Walle | 2843444 | 2020-05-22 14:07:37 +0200 | [diff] [blame] | 9 | #include <gzip.h> |
Tom Rini | 03de305 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 10 | #include <vsprintf.h> |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 11 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 12 | static int do_zip(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 13 | { |
| 14 | unsigned long src, dst; |
| 15 | unsigned long src_len, dst_len = ~0UL; |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 16 | |
| 17 | switch (argc) { |
| 18 | case 5: |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 19 | dst_len = hextoul(argv[4], NULL); |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 20 | /* fall through */ |
| 21 | case 4: |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 22 | src = hextoul(argv[1], NULL); |
| 23 | src_len = hextoul(argv[2], NULL); |
| 24 | dst = hextoul(argv[3], NULL); |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 25 | break; |
| 26 | default: |
| 27 | return cmd_usage(cmdtp); |
| 28 | } |
| 29 | |
| 30 | if (gzip((void *) dst, &dst_len, (void *) src, src_len) != 0) |
| 31 | return 1; |
| 32 | |
Heinrich Schuchardt | d667090 | 2019-01-06 12:38:37 +0100 | [diff] [blame] | 33 | printf("Compressed size: %lu = 0x%lX\n", dst_len, dst_len); |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 34 | env_set_hex("filesize", dst_len); |
Lei Wen | f2b96df | 2012-09-28 04:26:47 +0000 | [diff] [blame] | 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | U_BOOT_CMD( |
| 40 | zip, 5, 1, do_zip, |
| 41 | "zip a memory region", |
| 42 | "srcaddr srcsize dstaddr [dstsize]" |
| 43 | ); |