]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - cmd/cbfs.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
14 static int do_cbfs_init(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
17 uintptr_t end_of_rom
= 0xffffffff;
21 printf("usage: cbfsls [end of rom]>\n");
25 end_of_rom
= simple_strtoul(argv
[1], &ep
, 16);
27 puts("\n** Invalid end of ROM **\n");
31 file_cbfs_init(end_of_rom
);
32 if (cbfs_get_result() != CBFS_SUCCESS
) {
33 printf("%s.\n", file_cbfs_error());
40 cbfsinit
, 2, 0, do_cbfs_init
,
41 "initialize the cbfs driver",
43 " - Initialize the cbfs driver. The optional 'end of rom'\n"
44 " parameter specifies where the end of the ROM is that the\n"
45 " CBFS is in. It defaults to 0xFFFFFFFF\n"
48 static int do_cbfs_fsload(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
51 const struct cbfs_cachenode
*file
;
57 printf("usage: cbfsload <addr> <filename> [bytes]\n");
61 /* parse offset and count */
62 offset
= simple_strtoul(argv
[1], NULL
, 16);
64 count
= simple_strtoul(argv
[3], NULL
, 16);
68 file
= file_cbfs_find(argv
[2]);
70 if (cbfs_get_result() == CBFS_FILE_NOT_FOUND
)
71 printf("%s: %s\n", file_cbfs_error(), argv
[2]);
73 printf("%s.\n", file_cbfs_error());
77 printf("reading %s\n", file_cbfs_name(file
));
79 size
= file_cbfs_read(file
, (void *)offset
, count
);
81 printf("\n%ld bytes read\n", size
);
83 env_set_hex("filesize", size
);
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"
95 static int do_cbfs_ls(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
98 const struct cbfs_cachenode
*file
= file_cbfs_get_first();
102 printf("%s.\n", file_cbfs_error());
106 printf(" size type name\n");
107 printf("------------------------------------------\n");
109 int type
= file_cbfs_type(file
);
110 char *type_name
= NULL
;
111 const char *filename
= file_cbfs_name(file
);
113 printf(" %8d", file_cbfs_size(file
));
116 case CBFS_TYPE_BOOTBLOCK
:
117 type_name
= "bootblock";
119 case CBFS_TYPE_CBFSHEADER
:
120 type_name
= "cbfs header";
122 case CBFS_TYPE_STAGE
:
125 case CBFS_TYPE_PAYLOAD
:
126 type_name
= "payload";
131 case CBFS_TYPE_OPTIONROM
:
132 type_name
= "option rom";
134 case CBFS_TYPE_BOOTSPLASH
:
135 type_name
= "boot splash";
146 case CBFS_TYPE_MICROCODE
:
147 type_name
= "microcode";
161 case CBFS_TYPE_STRUCT
:
162 type_name
= "struct";
164 case CBFS_TYPE_CMOS_DEFAULT
:
165 type_name
= "cmos default";
170 case CBFS_TYPE_MRC_CACHE
:
171 type_name
= "mrc cache";
173 case CBFS_TYPE_CMOS_LAYOUT
:
174 type_name
= "cmos layout";
182 printf(" %16s", type_name
);
184 printf(" %16d", type
);
187 printf(" %s\n", filename
);
189 printf(" %s\n", "(empty)");
190 file_cbfs_get_next(&file
);
194 printf("\n%d file(s)\n\n", files
);
199 cbfsls
, 1, 1, do_cbfs_ls
,
201 " - list the files in the cbfs\n"
204 static int do_cbfs_fsinfo(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
207 const struct cbfs_header
*header
= file_cbfs_get_header();
210 printf("%s.\n", file_cbfs_error());
215 printf("CBFS version: %#x\n", header
->version
);
216 printf("ROM size: %#x\n", header
->rom_size
);
217 printf("Boot block size: %#x\n", header
->boot_block_size
);
218 printf("CBFS size: %#x\n",
219 header
->rom_size
- header
->boot_block_size
- header
->offset
);
220 printf("Alignment: %d\n", header
->align
);
221 printf("Offset: %#x\n", header
->offset
);
228 cbfsinfo
, 1, 1, do_cbfs_fsinfo
,
229 "print information about filesystem",
230 " - print information about the cbfs filesystem\n"