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.
 
 
 
 
 
 

179 lines
4.0 KiB

  1. /*
  2. * (C) Copyright 2010
  3. * Linaro LTD, www.linaro.org
  4. * Author: John Rigby <john.rigby@linaro.org>
  5. * Based on TI's signGP.c
  6. *
  7. * (C) Copyright 2009
  8. * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
  9. *
  10. * (C) Copyright 2008
  11. * Marvell Semiconductor <www.marvell.com>
  12. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  13. *
  14. * SPDX-License-Identifier: GPL-2.0+
  15. */
  16. #include "imagetool.h"
  17. #include <compiler.h>
  18. #include <image.h>
  19. #include "gpheader.h"
  20. #include "omapimage.h"
  21. /* Header size is CH header rounded up to 512 bytes plus GP header */
  22. #define OMAP_CH_HDR_SIZE 512
  23. #define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE + GPIMAGE_HDR_SIZE)
  24. static int do_swap32 = 0;
  25. static uint8_t omapimage_header[OMAP_FILE_HDR_SIZE];
  26. static int omapimage_check_image_types(uint8_t type)
  27. {
  28. if (type == IH_TYPE_OMAPIMAGE)
  29. return EXIT_SUCCESS;
  30. return EXIT_FAILURE;
  31. }
  32. static int omapimage_verify_header(unsigned char *ptr, int image_size,
  33. struct image_tool_params *params)
  34. {
  35. struct ch_toc *toc = (struct ch_toc *)ptr;
  36. struct gp_header *gph = (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
  37. uint32_t offset, size;
  38. while (toc->section_offset != 0xffffffff
  39. && toc->section_size != 0xffffffff) {
  40. if (do_swap32) {
  41. offset = cpu_to_be32(toc->section_offset);
  42. size = cpu_to_be32(toc->section_size);
  43. } else {
  44. offset = toc->section_offset;
  45. size = toc->section_size;
  46. }
  47. if (!offset || !size)
  48. return -1;
  49. if (offset >= OMAP_CH_HDR_SIZE ||
  50. offset+size >= OMAP_CH_HDR_SIZE)
  51. return -1;
  52. toc++;
  53. }
  54. return gph_verify_header(gph, do_swap32);
  55. }
  56. static void omapimage_print_section(struct ch_settings *chs)
  57. {
  58. const char *section_name;
  59. if (chs->section_key)
  60. section_name = "CHSETTINGS";
  61. else
  62. section_name = "UNKNOWNKEY";
  63. printf("%s (%x) "
  64. "valid:%x "
  65. "version:%x "
  66. "reserved:%x "
  67. "flags:%x\n",
  68. section_name,
  69. chs->section_key,
  70. chs->valid,
  71. chs->version,
  72. chs->reserved,
  73. chs->flags);
  74. }
  75. static void omapimage_print_header(const void *ptr)
  76. {
  77. const struct ch_toc *toc = (struct ch_toc *)ptr;
  78. const struct gp_header *gph =
  79. (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
  80. uint32_t offset, size;
  81. while (toc->section_offset != 0xffffffff
  82. && toc->section_size != 0xffffffff) {
  83. if (do_swap32) {
  84. offset = cpu_to_be32(toc->section_offset);
  85. size = cpu_to_be32(toc->section_size);
  86. } else {
  87. offset = toc->section_offset;
  88. size = toc->section_size;
  89. }
  90. if (offset >= OMAP_CH_HDR_SIZE ||
  91. offset+size >= OMAP_CH_HDR_SIZE)
  92. exit(EXIT_FAILURE);
  93. printf("Section %s offset %x length %x\n",
  94. toc->section_name,
  95. toc->section_offset,
  96. toc->section_size);
  97. omapimage_print_section((struct ch_settings *)(ptr+offset));
  98. toc++;
  99. }
  100. gph_print_header(gph, do_swap32);
  101. }
  102. static int toc_offset(void *hdr, void *member)
  103. {
  104. return member - hdr;
  105. }
  106. static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd,
  107. struct image_tool_params *params)
  108. {
  109. struct ch_toc *toc = (struct ch_toc *)ptr;
  110. struct ch_settings *chs = (struct ch_settings *)
  111. (ptr + 2 * sizeof(*toc));
  112. struct gp_header *gph = (struct gp_header *)(ptr + OMAP_CH_HDR_SIZE);
  113. toc->section_offset = toc_offset(ptr, chs);
  114. toc->section_size = sizeof(struct ch_settings);
  115. strcpy((char *)toc->section_name, "CHSETTINGS");
  116. chs->section_key = KEY_CHSETTINGS;
  117. chs->valid = 0;
  118. chs->version = 1;
  119. chs->reserved = 0;
  120. chs->flags = 0;
  121. toc++;
  122. memset(toc, 0xff, sizeof(*toc));
  123. gph_set_header(gph, sbuf->st_size - OMAP_CH_HDR_SIZE + GPIMAGE_HDR_SIZE,
  124. params->addr, 0);
  125. if (strncmp(params->imagename, "byteswap", 8) == 0) {
  126. do_swap32 = 1;
  127. int swapped = 0;
  128. uint32_t *data = (uint32_t *)ptr;
  129. while (swapped <= (sbuf->st_size / sizeof(uint32_t))) {
  130. *data = cpu_to_be32(*data);
  131. swapped++;
  132. data++;
  133. }
  134. }
  135. }
  136. /*
  137. * omapimage parameters
  138. */
  139. U_BOOT_IMAGE_TYPE(
  140. omapimage,
  141. "TI OMAP CH/GP Boot Image support",
  142. OMAP_FILE_HDR_SIZE,
  143. (void *)&omapimage_header,
  144. gpimage_check_params,
  145. omapimage_verify_header,
  146. omapimage_print_header,
  147. omapimage_set_header,
  148. NULL,
  149. omapimage_check_image_types,
  150. NULL,
  151. NULL
  152. );