cmd_cbfs.c 4.2 KB

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