2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4 * See file CREDITS for list of people who contributed to this
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.
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.
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,
30 int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
32 uintptr_t end_of_rom = 0xffffffff;
36 printf("usage: cbfsls [end of rom]>\n");
40 end_of_rom = (int)simple_strtoul(argv[1], &ep, 16);
42 puts("\n** Invalid end of ROM **\n");
46 file_cbfs_init(end_of_rom);
47 if (file_cbfs_result != CBFS_SUCCESS) {
48 printf("%s.\n", file_cbfs_error());
55 cbfsinit, 2, 0, do_cbfs_init,
56 "initialize the cbfs driver",
58 " - Initialize the cbfs driver. The optional 'end of rom'\n"
59 " parameter specifies where the end of the ROM is that the\n"
60 " CBFS is in. It defaults to 0xFFFFFFFF\n"
63 int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
65 const struct cbfs_cachenode *file;
72 printf("usage: cbfsload <addr> <filename> [bytes]\n");
76 /* parse offset and count */
77 offset = simple_strtoul(argv[1], NULL, 16);
79 count = simple_strtoul(argv[3], NULL, 16);
83 file = file_cbfs_find(argv[2]);
85 if (file_cbfs_result == CBFS_FILE_NOT_FOUND)
86 printf("%s: %s\n", file_cbfs_error(), argv[2]);
88 printf("%s.\n", file_cbfs_error());
92 printf("reading %s\n", file_cbfs_name(file));
94 size = file_cbfs_read(file, (void *)offset, count);
96 printf("\n%ld bytes read\n", size);
98 sprintf(buf, "%lX", size);
99 setenv("filesize", buf);
105 cbfsload, 4, 0, do_cbfs_fsload,
106 "load binary file from a cbfs filesystem",
107 "<addr> <filename> [bytes]\n"
108 " - load binary file 'filename' from the cbfs to address 'addr'\n"
111 int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
113 const struct cbfs_cachenode *file = file_cbfs_get_first();
117 printf("%s.\n", file_cbfs_error());
121 printf(" size type name\n");
122 printf("------------------------------------------\n");
124 u32 type = file_cbfs_type(file);
125 char *type_name = NULL;
126 const char *filename = file_cbfs_name(file);
128 printf(" %8d", file_cbfs_size(file));
131 case CBFS_TYPE_STAGE:
134 case CBFS_TYPE_PAYLOAD:
135 type_name = "payload";
137 case CBFS_TYPE_OPTIONROM:
138 type_name = "option rom";
140 case CBFS_TYPE_BOOTSPLASH:
141 type_name = "boot splash";
152 case CBFS_TYPE_MICROCODE:
153 type_name = "microcode";
155 case CBFS_COMPONENT_CMOS_DEFAULT:
156 type_name = "cmos default";
158 case CBFS_COMPONENT_CMOS_LAYOUT:
159 type_name = "cmos layout";
166 printf(" %16s", type_name);
168 printf(" %16d", type);
171 printf(" %s\n", filename);
173 printf(" %s\n", "(empty)");
174 file_cbfs_get_next(&file);
178 printf("\n%d file(s)\n\n", files);
183 cbfsls, 1, 1, do_cbfs_ls,
185 " - list the files in the cbfs\n"
188 int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
190 const struct cbfs_header *header = file_cbfs_get_header();
193 printf("%s.\n", file_cbfs_error());
198 printf("CBFS version: %#x\n", header->version);
199 printf("ROM size: %#x\n", header->rom_size);
200 printf("Boot block size: %#x\n", header->boot_block_size);
201 printf("CBFS size: %#x\n",
202 header->rom_size - header->boot_block_size - header->offset);
203 printf("Alignment: %d\n", header->align);
204 printf("Offset: %#x\n", header->offset);
211 cbfsinfo, 1, 1, do_cbfs_fsinfo,
212 "print information about filesystem",
213 " - print information about the cbfs filesystem\n"