unlz4.c 996 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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(struct cmd_tbl *cmdtp, int flag, int argc,
  11. char *const argv[])
  12. {
  13. unsigned long src, dst;
  14. size_t src_len = ~0UL, dst_len = ~0UL;
  15. int ret;
  16. switch (argc) {
  17. case 4:
  18. src = hextoul(argv[1], NULL);
  19. dst = hextoul(argv[2], NULL);
  20. dst_len = hextoul(argv[3], NULL);
  21. break;
  22. default:
  23. return CMD_RET_USAGE;
  24. }
  25. ret = ulz4fn((void *)src, src_len, (void *)dst, &dst_len);
  26. if (ret) {
  27. printf("Uncompressed err :%d\n", ret);
  28. return 1;
  29. }
  30. printf("Uncompressed size: %zd = 0x%zX\n", dst_len, dst_len);
  31. env_set_hex("filesize", dst_len);
  32. return 0;
  33. }
  34. U_BOOT_CMD(unlz4, 4, 1, do_unlz4,
  35. "lz4 uncompress a memory region",
  36. "srcaddr dstaddr dstsize\n"
  37. "NOTE: Specify the destination size that is sufficiently larger\n"
  38. " than the source size.\n"
  39. );