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.
 
 
 
 
 
 

204 lines
4.4 KiB

  1. #include "compiler.h"
  2. enum {
  3. MODE_GEN_INFO,
  4. MODE_GEN_DATA
  5. };
  6. typedef struct bitmap_s { /* bitmap description */
  7. uint16_t width;
  8. uint16_t height;
  9. uint8_t palette[256*3];
  10. uint8_t *data;
  11. } bitmap_t;
  12. #define DEFAULT_CMAP_SIZE 16 /* size of default color map */
  13. void usage(const char *prog)
  14. {
  15. fprintf(stderr, "Usage: %s [--gen-info|--gen-data] file\n", prog);
  16. }
  17. /*
  18. * Neutralize little endians.
  19. */
  20. uint16_t le_short(uint16_t x)
  21. {
  22. uint16_t val;
  23. uint8_t *p = (uint8_t *)(&x);
  24. val = (*p++ & 0xff) << 0;
  25. val |= (*p & 0xff) << 8;
  26. return val;
  27. }
  28. void skip_bytes (FILE *fp, int n)
  29. {
  30. while (n-- > 0)
  31. fgetc (fp);
  32. }
  33. __attribute__ ((__noreturn__))
  34. int error (char * msg, FILE *fp)
  35. {
  36. fprintf (stderr, "ERROR: %s\n", msg);
  37. fclose (fp);
  38. exit (EXIT_FAILURE);
  39. }
  40. void gen_info(bitmap_t *b, uint16_t n_colors)
  41. {
  42. printf("/*\n"
  43. " * Automatically generated by \"tools/bmp_logo\"\n"
  44. " *\n"
  45. " * DO NOT EDIT\n"
  46. " *\n"
  47. " */\n\n\n"
  48. "#ifndef __BMP_LOGO_H__\n"
  49. "#define __BMP_LOGO_H__\n\n"
  50. "#define BMP_LOGO_WIDTH\t\t%d\n"
  51. "#define BMP_LOGO_HEIGHT\t\t%d\n"
  52. "#define BMP_LOGO_COLORS\t\t%d\n"
  53. "#define BMP_LOGO_OFFSET\t\t%d\n\n"
  54. "extern unsigned short bmp_logo_palette[];\n"
  55. "extern unsigned char bmp_logo_bitmap[];\n\n"
  56. "#endif /* __BMP_LOGO_H__ */\n",
  57. b->width, b->height, n_colors,
  58. DEFAULT_CMAP_SIZE);
  59. }
  60. int main (int argc, char *argv[])
  61. {
  62. int mode, i, x;
  63. FILE *fp;
  64. bitmap_t bmp;
  65. bitmap_t *b = &bmp;
  66. uint16_t data_offset, n_colors;
  67. if (argc < 3) {
  68. usage(argv[0]);
  69. exit (EXIT_FAILURE);
  70. }
  71. if (!strcmp(argv[1], "--gen-info"))
  72. mode = MODE_GEN_INFO;
  73. else if (!strcmp(argv[1], "--gen-data"))
  74. mode = MODE_GEN_DATA;
  75. else {
  76. usage(argv[0]);
  77. exit(EXIT_FAILURE);
  78. }
  79. fp = fopen(argv[2], "rb");
  80. if (!fp) {
  81. perror(argv[2]);
  82. exit (EXIT_FAILURE);
  83. }
  84. if (fgetc (fp) != 'B' || fgetc (fp) != 'M')
  85. error ("Input file is not a bitmap", fp);
  86. /*
  87. * read width and height of the image, and the number of colors used;
  88. * ignore the rest
  89. */
  90. skip_bytes (fp, 8);
  91. if (fread (&data_offset, sizeof (uint16_t), 1, fp) != 1)
  92. error ("Couldn't read bitmap data offset", fp);
  93. skip_bytes (fp, 6);
  94. if (fread (&b->width, sizeof (uint16_t), 1, fp) != 1)
  95. error ("Couldn't read bitmap width", fp);
  96. skip_bytes (fp, 2);
  97. if (fread (&b->height, sizeof (uint16_t), 1, fp) != 1)
  98. error ("Couldn't read bitmap height", fp);
  99. skip_bytes (fp, 22);
  100. if (fread (&n_colors, sizeof (uint16_t), 1, fp) != 1)
  101. error ("Couldn't read bitmap colors", fp);
  102. skip_bytes (fp, 6);
  103. /*
  104. * Repair endianess.
  105. */
  106. data_offset = le_short(data_offset);
  107. b->width = le_short(b->width);
  108. b->height = le_short(b->height);
  109. n_colors = le_short(n_colors);
  110. /* assume we are working with an 8-bit file */
  111. if ((n_colors == 0) || (n_colors > 256 - DEFAULT_CMAP_SIZE)) {
  112. /* reserve DEFAULT_CMAP_SIZE color map entries for default map */
  113. n_colors = 256 - DEFAULT_CMAP_SIZE;
  114. }
  115. if (mode == MODE_GEN_INFO) {
  116. gen_info(b, n_colors);
  117. goto out;
  118. }
  119. printf("/*\n"
  120. " * Automatically generated by \"tools/bmp_logo\"\n"
  121. " *\n"
  122. " * DO NOT EDIT\n"
  123. " *\n"
  124. " */\n\n\n"
  125. "#ifndef __BMP_LOGO_DATA_H__\n"
  126. "#define __BMP_LOGO_DATA_H__\n\n");
  127. /* allocate memory */
  128. if ((b->data = (uint8_t *)malloc(b->width * b->height)) == NULL)
  129. error ("Error allocating memory for file", fp);
  130. /* read and print the palette information */
  131. printf("unsigned short bmp_logo_palette[] = {\n");
  132. for (i=0; i<n_colors; ++i) {
  133. b->palette[(int)(i*3+2)] = fgetc(fp);
  134. b->palette[(int)(i*3+1)] = fgetc(fp);
  135. b->palette[(int)(i*3+0)] = fgetc(fp);
  136. x=fgetc(fp);
  137. printf ("%s0x0%X%X%X,%s",
  138. ((i%8) == 0) ? "\t" : " ",
  139. (b->palette[(int)(i*3+0)] >> 4) & 0x0F,
  140. (b->palette[(int)(i*3+1)] >> 4) & 0x0F,
  141. (b->palette[(int)(i*3+2)] >> 4) & 0x0F,
  142. ((i%8) == 7) ? "\n" : ""
  143. );
  144. }
  145. /* seek to offset indicated by file header */
  146. fseek(fp, (long)data_offset, SEEK_SET);
  147. /* read the bitmap; leave room for default color map */
  148. printf ("\n");
  149. printf ("};\n");
  150. printf ("\n");
  151. printf("unsigned char bmp_logo_bitmap[] = {\n");
  152. for (i=(b->height-1)*b->width; i>=0; i-=b->width) {
  153. for (x = 0; x < b->width; x++) {
  154. b->data[i + x] = (uint8_t) fgetc(fp)
  155. + DEFAULT_CMAP_SIZE;
  156. }
  157. }
  158. for (i=0; i<(b->height*b->width); ++i) {
  159. if ((i%8) == 0)
  160. putchar ('\t');
  161. printf ("0x%02X,%c",
  162. b->data[i],
  163. ((i%8) == 7) ? '\n' : ' '
  164. );
  165. }
  166. printf ("\n"
  167. "};\n\n"
  168. "#endif /* __BMP_LOGO_DATA_H__ */\n"
  169. );
  170. out:
  171. fclose(fp);
  172. return 0;
  173. }