cbfs.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. /*
  7. * CBFS commands
  8. */
  9. #include <common.h>
  10. #include <command.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 = (int)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 (file_cbfs_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 (file_cbfs_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. setenv_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_STAGE:
  98. type_name = "stage";
  99. break;
  100. case CBFS_TYPE_PAYLOAD:
  101. type_name = "payload";
  102. break;
  103. case CBFS_TYPE_OPTIONROM:
  104. type_name = "option rom";
  105. break;
  106. case CBFS_TYPE_BOOTSPLASH:
  107. type_name = "boot splash";
  108. break;
  109. case CBFS_TYPE_RAW:
  110. type_name = "raw";
  111. break;
  112. case CBFS_TYPE_VSA:
  113. type_name = "vsa";
  114. break;
  115. case CBFS_TYPE_MBI:
  116. type_name = "mbi";
  117. break;
  118. case CBFS_TYPE_MICROCODE:
  119. type_name = "microcode";
  120. break;
  121. case CBFS_COMPONENT_CMOS_DEFAULT:
  122. type_name = "cmos default";
  123. break;
  124. case CBFS_COMPONENT_CMOS_LAYOUT:
  125. type_name = "cmos layout";
  126. break;
  127. case -1:
  128. case 0:
  129. type_name = "null";
  130. break;
  131. }
  132. if (type_name)
  133. printf(" %16s", type_name);
  134. else
  135. printf(" %16d", type);
  136. if (filename[0])
  137. printf(" %s\n", filename);
  138. else
  139. printf(" %s\n", "(empty)");
  140. file_cbfs_get_next(&file);
  141. files++;
  142. }
  143. printf("\n%d file(s)\n\n", files);
  144. return 0;
  145. }
  146. U_BOOT_CMD(
  147. cbfsls, 1, 1, do_cbfs_ls,
  148. "list files",
  149. " - list the files in the cbfs\n"
  150. );
  151. static int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
  152. char *const argv[])
  153. {
  154. const struct cbfs_header *header = file_cbfs_get_header();
  155. if (!header) {
  156. printf("%s.\n", file_cbfs_error());
  157. return 1;
  158. }
  159. printf("\n");
  160. printf("CBFS version: %#x\n", header->version);
  161. printf("ROM size: %#x\n", header->rom_size);
  162. printf("Boot block size: %#x\n", header->boot_block_size);
  163. printf("CBFS size: %#x\n",
  164. header->rom_size - header->boot_block_size - header->offset);
  165. printf("Alignment: %d\n", header->align);
  166. printf("Offset: %#x\n", header->offset);
  167. printf("\n");
  168. return 0;
  169. }
  170. U_BOOT_CMD(
  171. cbfsinfo, 1, 1, do_cbfs_fsinfo,
  172. "print information about filesystem",
  173. " - print information about the cbfs filesystem\n"
  174. );