Fork of the vendor (Boundary Devices) u-boot for Reform 2, with minor tweaks. The goal is to migrate to mainstream u-boot or barebox ASAP. The main impediment so far is the 4GB RAM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

108 lines
2.1 KiB

  1. /*
  2. * (C) Copyright 2014
  3. * DENX Software Engineering
  4. * Heiko Schocher <hs@denx.de>
  5. *
  6. * (C) Copyright 2008 Semihalf
  7. *
  8. * (C) Copyright 2000-2004
  9. * DENX Software Engineering
  10. * Wolfgang Denk, wd@denx.de
  11. *
  12. * Updated-by: Prafulla Wadaskar <prafulla@marvell.com>
  13. * FIT image specific code abstracted from mkimage.c
  14. * some functions added to address abstraction
  15. *
  16. * All rights reserved.
  17. *
  18. * SPDX-License-Identifier: GPL-2.0+
  19. */
  20. #include "imagetool.h"
  21. #include "mkimage.h"
  22. #include "fit_common.h"
  23. #include <image.h>
  24. #include <u-boot/crc.h>
  25. int fit_verify_header(unsigned char *ptr, int image_size,
  26. struct image_tool_params *params)
  27. {
  28. return fdt_check_header(ptr);
  29. }
  30. int fit_check_image_types(uint8_t type)
  31. {
  32. if (type == IH_TYPE_FLATDT)
  33. return EXIT_SUCCESS;
  34. else
  35. return EXIT_FAILURE;
  36. }
  37. int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
  38. void **blobp, struct stat *sbuf, bool delete_on_error)
  39. {
  40. void *ptr;
  41. int fd;
  42. /* Load FIT blob into memory (we need to write hashes/signatures) */
  43. fd = open(fname, O_RDWR | O_BINARY);
  44. if (fd < 0) {
  45. fprintf(stderr, "%s: Can't open %s: %s\n",
  46. cmdname, fname, strerror(errno));
  47. goto err;
  48. }
  49. if (fstat(fd, sbuf) < 0) {
  50. fprintf(stderr, "%s: Can't stat %s: %s\n",
  51. cmdname, fname, strerror(errno));
  52. goto err;
  53. }
  54. if (size_inc) {
  55. sbuf->st_size += size_inc;
  56. if (ftruncate(fd, sbuf->st_size)) {
  57. fprintf(stderr, "%s: Can't expand %s: %s\n",
  58. cmdname, fname, strerror(errno));
  59. goto err;
  60. }
  61. }
  62. errno = 0;
  63. ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  64. if ((ptr == MAP_FAILED) || (errno != 0)) {
  65. fprintf(stderr, "%s: Can't read %s: %s\n",
  66. cmdname, fname, strerror(errno));
  67. goto err;
  68. }
  69. /* check if ptr has a valid blob */
  70. if (fdt_check_header(ptr)) {
  71. fprintf(stderr, "%s: Invalid FIT blob\n", cmdname);
  72. goto err;
  73. }
  74. /* expand if needed */
  75. if (size_inc) {
  76. int ret;
  77. ret = fdt_open_into(ptr, ptr, sbuf->st_size);
  78. if (ret) {
  79. fprintf(stderr, "%s: Cannot expand FDT: %s\n",
  80. cmdname, fdt_strerror(ret));
  81. goto err;
  82. }
  83. }
  84. *blobp = ptr;
  85. return fd;
  86. err:
  87. if (fd >= 0)
  88. close(fd);
  89. if (delete_on_error)
  90. unlink(fname);
  91. return -1;
  92. }