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.
 
 
 
 
 
 

132 lines
3.4 KiB

  1. /*
  2. * (C) Copyright 2001
  3. * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <errno.h>
  8. #include <stdio.h>
  9. #include <stdint.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <unistd.h>
  13. #include <linux/kconfig.h>
  14. #ifndef __ASSEMBLY__
  15. #define __ASSEMBLY__ /* Dirty trick to get only #defines */
  16. #endif
  17. #define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */
  18. #include <config.h>
  19. #undef __ASSEMBLY__
  20. #if defined(CONFIG_ENV_IS_IN_FLASH)
  21. # ifndef CONFIG_ENV_ADDR
  22. # define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET)
  23. # endif
  24. # ifndef CONFIG_ENV_OFFSET
  25. # define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE)
  26. # endif
  27. # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND)
  28. # define CONFIG_ENV_ADDR_REDUND (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
  29. # endif
  30. # ifndef CONFIG_ENV_SIZE
  31. # define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
  32. # endif
  33. # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND)
  34. # define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE
  35. # endif
  36. # if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \
  37. ((CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN))
  38. # define ENV_IS_EMBEDDED
  39. # endif
  40. # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
  41. # define CONFIG_SYS_REDUNDAND_ENVIRONMENT
  42. # endif
  43. #endif /* CONFIG_ENV_IS_IN_FLASH */
  44. #if defined(ENV_IS_EMBEDDED) && !defined(CONFIG_BUILD_ENVCRC)
  45. # define CONFIG_BUILD_ENVCRC
  46. #endif
  47. #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
  48. # define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
  49. #else
  50. # define ENV_HEADER_SIZE (sizeof(uint32_t))
  51. #endif
  52. #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
  53. #ifdef CONFIG_BUILD_ENVCRC
  54. # include <environment.h>
  55. extern unsigned int env_size;
  56. extern env_t environment;
  57. #endif /* CONFIG_BUILD_ENVCRC */
  58. extern uint32_t crc32 (uint32_t, const unsigned char *, unsigned int);
  59. int main (int argc, char **argv)
  60. {
  61. #ifdef CONFIG_BUILD_ENVCRC
  62. unsigned char pad = 0x00;
  63. uint32_t crc;
  64. unsigned char *envptr = (unsigned char *)&environment,
  65. *dataptr = envptr + ENV_HEADER_SIZE;
  66. unsigned int datasize = ENV_SIZE;
  67. unsigned int eoe;
  68. if (argv[1] && !strncmp(argv[1], "--binary", 8)) {
  69. int ipad = 0xff;
  70. if (argv[1][8] == '=')
  71. sscanf(argv[1] + 9, "%i", &ipad);
  72. pad = ipad;
  73. }
  74. if (pad) {
  75. /* find the end of env */
  76. for (eoe = 0; eoe < datasize - 1; ++eoe)
  77. if (!dataptr[eoe] && !dataptr[eoe+1]) {
  78. eoe += 2;
  79. break;
  80. }
  81. if (eoe < datasize - 1)
  82. memset(dataptr + eoe, pad, datasize - eoe);
  83. }
  84. crc = crc32 (0, dataptr, datasize);
  85. /* Check if verbose mode is activated passing a parameter to the program */
  86. if (argc > 1) {
  87. if (!strncmp(argv[1], "--binary", 8)) {
  88. int le = (argc > 2 ? !strcmp(argv[2], "le") : 1);
  89. size_t i, start, end, step;
  90. if (le) {
  91. start = 0;
  92. end = ENV_HEADER_SIZE;
  93. step = 1;
  94. } else {
  95. start = ENV_HEADER_SIZE - 1;
  96. end = -1;
  97. step = -1;
  98. }
  99. for (i = start; i != end; i += step)
  100. printf("%c", (crc & (0xFF << (i * 8))) >> (i * 8));
  101. if (fwrite(dataptr, 1, datasize, stdout) != datasize)
  102. fprintf(stderr, "fwrite() failed: %s\n", strerror(errno));
  103. } else {
  104. printf("CRC32 from offset %08X to %08X of environment = %08X\n",
  105. (unsigned int) (dataptr - envptr),
  106. (unsigned int) (dataptr - envptr) + datasize,
  107. crc);
  108. }
  109. } else {
  110. printf ("0x%08X\n", crc);
  111. }
  112. #else
  113. printf ("0\n");
  114. #endif
  115. return EXIT_SUCCESS;
  116. }