unlz4.c 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020
  4. * FUJITSU COMPUTERTECHNOLOGIES LIMITED. All rights reserved.
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <env.h>
  9. #include <lz4.h>
  10. static int do_unlz4(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  11. {
  12. unsigned long src, dst;
  13. size_t src_len = ~0UL, dst_len = ~0UL;
  14. int ret;
  15. switch (argc) {
  16. case 4:
  17. src = simple_strtoul(argv[1], NULL, 16);
  18. dst = simple_strtoul(argv[2], NULL, 16);
  19. dst_len = simple_strtoul(argv[3], NULL, 16);
  20. break;
  21. default:
  22. return CMD_RET_USAGE;
  23. }
  24. ret = ulz4fn((void *)src, src_len, (void *)dst, &dst_len);
  25. if (ret) {
  26. printf("Uncompressed err :%d\n", ret);
  27. return 1;
  28. }
  29. printf("Uncompressed size: %zd = 0x%zX\n", dst_len, dst_len);
  30. env_set_hex("filesize", dst_len);
  31. return 0;
  32. }
  33. U_BOOT_CMD(unlz4, 4, 1, do_unlz4,
  34. "lz4 uncompress a memory region",
  35. "srcaddr dstaddr dstsize\n"
  36. "NOTE: Specify the destination size that is sufficiently larger\n"
  37. " than the source size.\n"
  38. );