cbfs.c 4.8 KB

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