cbfs.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <cbfs.h>
  11. static int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc,
  12. char *const argv[])
  13. {
  14. uintptr_t end_of_rom = 0xffffffff;
  15. char *ep;
  16. if (argc > 2) {
  17. printf("usage: cbfsls [end of rom]>\n");
  18. return 0;
  19. }
  20. if (argc == 2) {
  21. end_of_rom = simple_strtoul(argv[1], &ep, 16);
  22. if (*ep) {
  23. puts("\n** Invalid end of ROM **\n");
  24. return 1;
  25. }
  26. }
  27. file_cbfs_init(end_of_rom);
  28. if (file_cbfs_result != CBFS_SUCCESS) {
  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(cmd_tbl_t *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 = simple_strtoul(argv[1], NULL, 16);
  55. if (argc == 4)
  56. count = simple_strtoul(argv[3], NULL, 16);
  57. else
  58. count = 0;
  59. file = file_cbfs_find(argv[2]);
  60. if (!file) {
  61. if (file_cbfs_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(cmd_tbl_t *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_STAGE:
  97. type_name = "stage";
  98. break;
  99. case CBFS_TYPE_PAYLOAD:
  100. type_name = "payload";
  101. break;
  102. case CBFS_TYPE_OPTIONROM:
  103. type_name = "option rom";
  104. break;
  105. case CBFS_TYPE_BOOTSPLASH:
  106. type_name = "boot splash";
  107. break;
  108. case CBFS_TYPE_RAW:
  109. type_name = "raw";
  110. break;
  111. case CBFS_TYPE_VSA:
  112. type_name = "vsa";
  113. break;
  114. case CBFS_TYPE_MBI:
  115. type_name = "mbi";
  116. break;
  117. case CBFS_TYPE_MICROCODE:
  118. type_name = "microcode";
  119. break;
  120. case CBFS_COMPONENT_CMOS_DEFAULT:
  121. type_name = "cmos default";
  122. break;
  123. case CBFS_COMPONENT_CMOS_LAYOUT:
  124. type_name = "cmos layout";
  125. break;
  126. case -1:
  127. case 0:
  128. type_name = "null";
  129. break;
  130. }
  131. if (type_name)
  132. printf(" %16s", type_name);
  133. else
  134. printf(" %16d", type);
  135. if (filename[0])
  136. printf(" %s\n", filename);
  137. else
  138. printf(" %s\n", "(empty)");
  139. file_cbfs_get_next(&file);
  140. files++;
  141. }
  142. printf("\n%d file(s)\n\n", files);
  143. return 0;
  144. }
  145. U_BOOT_CMD(
  146. cbfsls, 1, 1, do_cbfs_ls,
  147. "list files",
  148. " - list the files in the cbfs\n"
  149. );
  150. static int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
  151. char *const argv[])
  152. {
  153. const struct cbfs_header *header = file_cbfs_get_header();
  154. if (!header) {
  155. printf("%s.\n", file_cbfs_error());
  156. return 1;
  157. }
  158. printf("\n");
  159. printf("CBFS version: %#x\n", header->version);
  160. printf("ROM size: %#x\n", header->rom_size);
  161. printf("Boot block size: %#x\n", header->boot_block_size);
  162. printf("CBFS size: %#x\n",
  163. header->rom_size - header->boot_block_size - header->offset);
  164. printf("Alignment: %d\n", header->align);
  165. printf("Offset: %#x\n", header->offset);
  166. printf("\n");
  167. return 0;
  168. }
  169. U_BOOT_CMD(
  170. cbfsinfo, 1, 1, do_cbfs_fsinfo,
  171. "print information about filesystem",
  172. " - print information about the cbfs filesystem\n"
  173. );