cmd_cbfs.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. /*
  23. * CBFS commands
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <cbfs.h>
  28. int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  29. {
  30. uintptr_t end_of_rom = 0xffffffff;
  31. char *ep;
  32. if (argc > 2) {
  33. printf("usage: cbfsls [end of rom]>\n");
  34. return 0;
  35. }
  36. if (argc == 2) {
  37. end_of_rom = (int)simple_strtoul(argv[1], &ep, 16);
  38. if (*ep) {
  39. puts("\n** Invalid end of ROM **\n");
  40. return 1;
  41. }
  42. }
  43. file_cbfs_init(end_of_rom);
  44. if (file_cbfs_result != CBFS_SUCCESS) {
  45. printf("%s.\n", file_cbfs_error());
  46. return 1;
  47. }
  48. return 0;
  49. }
  50. U_BOOT_CMD(
  51. cbfsinit, 2, 0, do_cbfs_init,
  52. "initialize the cbfs driver",
  53. "[end of rom]\n"
  54. " - Initialize the cbfs driver. The optional 'end of rom'\n"
  55. " parameter specifies where the end of the ROM is that the\n"
  56. " CBFS is in. It defaults to 0xFFFFFFFF\n"
  57. );
  58. int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  59. {
  60. const struct cbfs_cachenode *file;
  61. unsigned long offset;
  62. unsigned long count;
  63. long size;
  64. if (argc < 3) {
  65. printf("usage: cbfsload <addr> <filename> [bytes]\n");
  66. return 1;
  67. }
  68. /* parse offset and count */
  69. offset = simple_strtoul(argv[1], NULL, 16);
  70. if (argc == 4)
  71. count = simple_strtoul(argv[3], NULL, 16);
  72. else
  73. count = 0;
  74. file = file_cbfs_find(argv[2]);
  75. if (!file) {
  76. if (file_cbfs_result == CBFS_FILE_NOT_FOUND)
  77. printf("%s: %s\n", file_cbfs_error(), argv[2]);
  78. else
  79. printf("%s.\n", file_cbfs_error());
  80. return 1;
  81. }
  82. printf("reading %s\n", file_cbfs_name(file));
  83. size = file_cbfs_read(file, (void *)offset, count);
  84. printf("\n%ld bytes read\n", size);
  85. setenv_hex("filesize", size);
  86. return 0;
  87. }
  88. U_BOOT_CMD(
  89. cbfsload, 4, 0, do_cbfs_fsload,
  90. "load binary file from a cbfs filesystem",
  91. "<addr> <filename> [bytes]\n"
  92. " - load binary file 'filename' from the cbfs to address 'addr'\n"
  93. );
  94. int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  95. {
  96. const struct cbfs_cachenode *file = file_cbfs_get_first();
  97. int files = 0;
  98. if (!file) {
  99. printf("%s.\n", file_cbfs_error());
  100. return 1;
  101. }
  102. printf(" size type name\n");
  103. printf("------------------------------------------\n");
  104. while (file) {
  105. u32 type = file_cbfs_type(file);
  106. char *type_name = NULL;
  107. const char *filename = file_cbfs_name(file);
  108. printf(" %8d", file_cbfs_size(file));
  109. switch (type) {
  110. case CBFS_TYPE_STAGE:
  111. type_name = "stage";
  112. break;
  113. case CBFS_TYPE_PAYLOAD:
  114. type_name = "payload";
  115. break;
  116. case CBFS_TYPE_OPTIONROM:
  117. type_name = "option rom";
  118. break;
  119. case CBFS_TYPE_BOOTSPLASH:
  120. type_name = "boot splash";
  121. break;
  122. case CBFS_TYPE_RAW:
  123. type_name = "raw";
  124. break;
  125. case CBFS_TYPE_VSA:
  126. type_name = "vsa";
  127. break;
  128. case CBFS_TYPE_MBI:
  129. type_name = "mbi";
  130. break;
  131. case CBFS_TYPE_MICROCODE:
  132. type_name = "microcode";
  133. break;
  134. case CBFS_COMPONENT_CMOS_DEFAULT:
  135. type_name = "cmos default";
  136. break;
  137. case CBFS_COMPONENT_CMOS_LAYOUT:
  138. type_name = "cmos layout";
  139. break;
  140. case -1UL:
  141. type_name = "null";
  142. break;
  143. }
  144. if (type_name)
  145. printf(" %16s", type_name);
  146. else
  147. printf(" %16d", type);
  148. if (filename[0])
  149. printf(" %s\n", filename);
  150. else
  151. printf(" %s\n", "(empty)");
  152. file_cbfs_get_next(&file);
  153. files++;
  154. }
  155. printf("\n%d file(s)\n\n", files);
  156. return 0;
  157. }
  158. U_BOOT_CMD(
  159. cbfsls, 1, 1, do_cbfs_ls,
  160. "list files",
  161. " - list the files in the cbfs\n"
  162. );
  163. int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  164. {
  165. const struct cbfs_header *header = file_cbfs_get_header();
  166. if (!header) {
  167. printf("%s.\n", file_cbfs_error());
  168. return 1;
  169. }
  170. printf("\n");
  171. printf("CBFS version: %#x\n", header->version);
  172. printf("ROM size: %#x\n", header->rom_size);
  173. printf("Boot block size: %#x\n", header->boot_block_size);
  174. printf("CBFS size: %#x\n",
  175. header->rom_size - header->boot_block_size - header->offset);
  176. printf("Alignment: %d\n", header->align);
  177. printf("Offset: %#x\n", header->offset);
  178. printf("\n");
  179. return 0;
  180. }
  181. U_BOOT_CMD(
  182. cbfsinfo, 1, 1, do_cbfs_fsinfo,
  183. "print information about filesystem",
  184. " - print information about the cbfs filesystem\n"
  185. );