cbfs.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
  4. */
  5. /*
  6. * CBFS commands
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <env.h>
  11. #include <cbfs.h>
  12. static int do_cbfs_init(struct cmd_tbl *cmdtp, int flag, int argc,
  13. char *const argv[])
  14. {
  15. uintptr_t end_of_rom = 0xffffffff;
  16. char *ep;
  17. if (argc > 2) {
  18. printf("usage: cbfsls [end of rom]>\n");
  19. return 0;
  20. }
  21. if (argc == 2) {
  22. end_of_rom = hextoul(argv[1], &ep);
  23. if (*ep) {
  24. puts("\n** Invalid end of ROM **\n");
  25. return 1;
  26. }
  27. }
  28. if (file_cbfs_init(end_of_rom)) {
  29. printf("%s.\n", file_cbfs_error());
  30. return 1;
  31. }
  32. return 0;
  33. }
  34. U_BOOT_CMD(
  35. cbfsinit, 2, 0, do_cbfs_init,
  36. "initialize the cbfs driver",
  37. "[end of rom]\n"
  38. " - Initialize the cbfs driver. The optional 'end of rom'\n"
  39. " parameter specifies where the end of the ROM is that the\n"
  40. " CBFS is in. It defaults to 0xFFFFFFFF\n"
  41. );
  42. static int do_cbfs_fsload(struct cmd_tbl *cmdtp, int flag, int argc,
  43. char *const argv[])
  44. {
  45. const struct cbfs_cachenode *file;
  46. unsigned long offset;
  47. unsigned long count;
  48. long size;
  49. if (argc < 3) {
  50. printf("usage: cbfsload <addr> <filename> [bytes]\n");
  51. return 1;
  52. }
  53. /* parse offset and count */
  54. offset = hextoul(argv[1], NULL);
  55. if (argc == 4)
  56. count = hextoul(argv[3], NULL);
  57. else
  58. count = 0;
  59. file = file_cbfs_find(argv[2]);
  60. if (!file) {
  61. if (cbfs_get_result() == CBFS_FILE_NOT_FOUND)
  62. printf("%s: %s\n", file_cbfs_error(), argv[2]);
  63. else
  64. printf("%s.\n", file_cbfs_error());
  65. return 1;
  66. }
  67. printf("reading %s\n", file_cbfs_name(file));
  68. size = file_cbfs_read(file, (void *)offset, count);
  69. printf("\n%ld bytes read\n", size);
  70. env_set_hex("filesize", size);
  71. return 0;
  72. }
  73. U_BOOT_CMD(
  74. cbfsload, 4, 0, do_cbfs_fsload,
  75. "load binary file from a cbfs filesystem",
  76. "<addr> <filename> [bytes]\n"
  77. " - load binary file 'filename' from the cbfs to address 'addr'\n"
  78. );
  79. static int do_cbfs_ls(struct cmd_tbl *cmdtp, int flag, int argc,
  80. char *const argv[])
  81. {
  82. const struct cbfs_cachenode *file = file_cbfs_get_first();
  83. int files = 0;
  84. if (!file) {
  85. printf("%s.\n", file_cbfs_error());
  86. return 1;
  87. }
  88. printf(" size type name\n");
  89. printf("------------------------------------------\n");
  90. while (file) {
  91. int type = file_cbfs_type(file);
  92. char *type_name = NULL;
  93. const char *filename = file_cbfs_name(file);
  94. printf(" %8d", file_cbfs_size(file));
  95. switch (type) {
  96. case CBFS_TYPE_BOOTBLOCK:
  97. type_name = "bootblock";
  98. break;
  99. case CBFS_TYPE_CBFSHEADER:
  100. type_name = "cbfs header";
  101. break;
  102. case CBFS_TYPE_STAGE:
  103. type_name = "stage";
  104. break;
  105. case CBFS_TYPE_PAYLOAD:
  106. type_name = "payload";
  107. break;
  108. case CBFS_TYPE_FIT:
  109. type_name = "fit";
  110. break;
  111. case CBFS_TYPE_OPTIONROM:
  112. type_name = "option rom";
  113. break;
  114. case CBFS_TYPE_BOOTSPLASH:
  115. type_name = "boot splash";
  116. break;
  117. case CBFS_TYPE_RAW:
  118. type_name = "raw";
  119. break;
  120. case CBFS_TYPE_VSA:
  121. type_name = "vsa";
  122. break;
  123. case CBFS_TYPE_MBI:
  124. type_name = "mbi";
  125. break;
  126. case CBFS_TYPE_MICROCODE:
  127. type_name = "microcode";
  128. break;
  129. case CBFS_TYPE_FSP:
  130. type_name = "fsp";
  131. break;
  132. case CBFS_TYPE_MRC:
  133. type_name = "mrc";
  134. break;
  135. case CBFS_TYPE_MMA:
  136. type_name = "mma";
  137. break;
  138. case CBFS_TYPE_EFI:
  139. type_name = "efi";
  140. break;
  141. case CBFS_TYPE_STRUCT:
  142. type_name = "struct";
  143. break;
  144. case CBFS_TYPE_CMOS_DEFAULT:
  145. type_name = "cmos default";
  146. break;
  147. case CBFS_TYPE_SPD:
  148. type_name = "spd";
  149. break;
  150. case CBFS_TYPE_MRC_CACHE:
  151. type_name = "mrc cache";
  152. break;
  153. case CBFS_TYPE_CMOS_LAYOUT:
  154. type_name = "cmos layout";
  155. break;
  156. case -1:
  157. case 0:
  158. type_name = "null";
  159. break;
  160. }
  161. if (type_name)
  162. printf(" %16s", type_name);
  163. else
  164. printf(" %16d", type);
  165. if (filename[0])
  166. printf(" %s\n", filename);
  167. else
  168. printf(" %s\n", "(empty)");
  169. file_cbfs_get_next(&file);
  170. files++;
  171. }
  172. printf("\n%d file(s)\n\n", files);
  173. return 0;
  174. }
  175. U_BOOT_CMD(
  176. cbfsls, 1, 1, do_cbfs_ls,
  177. "list files",
  178. " - list the files in the cbfs\n"
  179. );
  180. static int do_cbfs_fsinfo(struct cmd_tbl *cmdtp, int flag, int argc,
  181. char *const argv[])
  182. {
  183. const struct cbfs_header *header = file_cbfs_get_header();
  184. if (!header) {
  185. printf("%s.\n", file_cbfs_error());
  186. return 1;
  187. }
  188. printf("\n");
  189. printf("CBFS version: %#x\n", header->version);
  190. printf("ROM size: %#x\n", header->rom_size);
  191. printf("Boot block size: %#x\n", header->boot_block_size);
  192. printf("CBFS size: %#x\n",
  193. header->rom_size - header->boot_block_size - header->offset);
  194. printf("Alignment: %d\n", header->align);
  195. printf("Offset: %#x\n", header->offset);
  196. printf("\n");
  197. return 0;
  198. }
  199. U_BOOT_CMD(
  200. cbfsinfo, 1, 1, do_cbfs_fsinfo,
  201. "print information about filesystem",
  202. " - print information about the cbfs filesystem\n"
  203. );