zip.c 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2012
  4. * Lei Wen <leiwen@marvell.com>, Marvell Inc.
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <env.h>
  9. static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  10. {
  11. unsigned long src, dst;
  12. unsigned long src_len, dst_len = ~0UL;
  13. switch (argc) {
  14. case 5:
  15. dst_len = simple_strtoul(argv[4], NULL, 16);
  16. /* fall through */
  17. case 4:
  18. src = simple_strtoul(argv[1], NULL, 16);
  19. src_len = simple_strtoul(argv[2], NULL, 16);
  20. dst = simple_strtoul(argv[3], NULL, 16);
  21. break;
  22. default:
  23. return cmd_usage(cmdtp);
  24. }
  25. if (gzip((void *) dst, &dst_len, (void *) src, src_len) != 0)
  26. return 1;
  27. printf("Compressed size: %lu = 0x%lX\n", dst_len, dst_len);
  28. env_set_hex("filesize", dst_len);
  29. return 0;
  30. }
  31. U_BOOT_CMD(
  32. zip, 5, 1, do_zip,
  33. "zip a memory region",
  34. "srcaddr srcsize dstaddr [dstsize]"
  35. );