cmd_cbfs.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. char buf[12];
  64. long size;
  65. if (argc < 3) {
  66. printf("usage: cbfsload <addr> <filename> [bytes]\n");
  67. return 1;
  68. }
  69. /* parse offset and count */
  70. offset = simple_strtoul(argv[1], NULL, 16);
  71. if (argc == 4)
  72. count = simple_strtoul(argv[3], NULL, 16);
  73. else
  74. count = 0;
  75. file = file_cbfs_find(argv[2]);
  76. if (!file) {
  77. if (file_cbfs_result == CBFS_FILE_NOT_FOUND)
  78. printf("%s: %s\n", file_cbfs_error(), argv[2]);
  79. else
  80. printf("%s.\n", file_cbfs_error());
  81. return 1;
  82. }
  83. printf("reading %s\n", file_cbfs_name(file));
  84. size = file_cbfs_read(file, (void *)offset, count);
  85. printf("\n%ld bytes read\n", size);
  86. sprintf(buf, "%lX", size);
  87. setenv("filesize", buf);
  88. return 0;
  89. }
  90. U_BOOT_CMD(
  91. cbfsload, 4, 0, do_cbfs_fsload,
  92. "load binary file from a cbfs filesystem",
  93. "<addr> <filename> [bytes]\n"
  94. " - load binary file 'filename' from the cbfs to address 'addr'\n"
  95. );
  96. int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  97. {
  98. const struct cbfs_cachenode *file = file_cbfs_get_first();
  99. int files = 0;
  100. if (!file) {
  101. printf("%s.\n", file_cbfs_error());
  102. return 1;
  103. }
  104. printf(" size type name\n");
  105. printf("------------------------------------------\n");
  106. while (file) {
  107. u32 type = file_cbfs_type(file);
  108. char *type_name = NULL;
  109. const char *filename = file_cbfs_name(file);
  110. printf(" %8d", file_cbfs_size(file));
  111. switch (type) {
  112. case CBFS_TYPE_STAGE:
  113. type_name = "stage";
  114. break;
  115. case CBFS_TYPE_PAYLOAD:
  116. type_name = "payload";
  117. break;
  118. case CBFS_TYPE_OPTIONROM:
  119. type_name = "option rom";
  120. break;
  121. case CBFS_TYPE_BOOTSPLASH:
  122. type_name = "boot splash";
  123. break;
  124. case CBFS_TYPE_RAW:
  125. type_name = "raw";
  126. break;
  127. case CBFS_TYPE_VSA:
  128. type_name = "vsa";
  129. break;
  130. case CBFS_TYPE_MBI:
  131. type_name = "mbi";
  132. break;
  133. case CBFS_TYPE_MICROCODE:
  134. type_name = "microcode";
  135. break;
  136. case CBFS_COMPONENT_CMOS_DEFAULT:
  137. type_name = "cmos default";
  138. break;
  139. case CBFS_COMPONENT_CMOS_LAYOUT:
  140. type_name = "cmos layout";
  141. break;
  142. case -1UL:
  143. type_name = "null";
  144. break;
  145. }
  146. if (type_name)
  147. printf(" %16s", type_name);
  148. else
  149. printf(" %16d", type);
  150. if (filename[0])
  151. printf(" %s\n", filename);
  152. else
  153. printf(" %s\n", "(empty)");
  154. file_cbfs_get_next(&file);
  155. files++;
  156. }
  157. printf("\n%d file(s)\n\n", files);
  158. return 0;
  159. }
  160. U_BOOT_CMD(
  161. cbfsls, 1, 1, do_cbfs_ls,
  162. "list files",
  163. " - list the files in the cbfs\n"
  164. );
  165. int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  166. {
  167. const struct cbfs_header *header = file_cbfs_get_header();
  168. if (!header) {
  169. printf("%s.\n", file_cbfs_error());
  170. return 1;
  171. }
  172. printf("\n");
  173. printf("CBFS version: %#x\n", header->version);
  174. printf("ROM size: %#x\n", header->rom_size);
  175. printf("Boot block size: %#x\n", header->boot_block_size);
  176. printf("CBFS size: %#x\n",
  177. header->rom_size - header->boot_block_size - header->offset);
  178. printf("Alignment: %d\n", header->align);
  179. printf("Offset: %#x\n", header->offset);
  180. printf("\n");
  181. return 0;
  182. }
  183. U_BOOT_CMD(
  184. cbfsinfo, 1, 1, do_cbfs_fsinfo,
  185. "print information about filesystem",
  186. " - print information about the cbfs filesystem\n"
  187. );