Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * CBFS commands |
| 8 | */ |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
Simon Glass | c7694dd | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 11 | #include <env.h> |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 12 | #include <cbfs.h> |
| 13 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 14 | static int do_cbfs_init(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | 633fb73 | 2016-03-13 19:07:27 -0600 | [diff] [blame] | 15 | char *const argv[]) |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 16 | { |
| 17 | uintptr_t end_of_rom = 0xffffffff; |
| 18 | char *ep; |
| 19 | |
| 20 | if (argc > 2) { |
| 21 | printf("usage: cbfsls [end of rom]>\n"); |
| 22 | return 0; |
| 23 | } |
| 24 | if (argc == 2) { |
Andre Heider | 33222c8 | 2018-02-15 07:40:10 +0100 | [diff] [blame] | 25 | end_of_rom = simple_strtoul(argv[1], &ep, 16); |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 26 | if (*ep) { |
| 27 | puts("\n** Invalid end of ROM **\n"); |
| 28 | return 1; |
| 29 | } |
| 30 | } |
Simon Glass | 0e7b631 | 2020-05-24 17:38:21 -0600 | [diff] [blame] | 31 | if (file_cbfs_init(end_of_rom)) { |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 32 | printf("%s.\n", file_cbfs_error()); |
| 33 | return 1; |
| 34 | } |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | U_BOOT_CMD( |
| 39 | cbfsinit, 2, 0, do_cbfs_init, |
| 40 | "initialize the cbfs driver", |
| 41 | "[end of rom]\n" |
| 42 | " - Initialize the cbfs driver. The optional 'end of rom'\n" |
| 43 | " parameter specifies where the end of the ROM is that the\n" |
| 44 | " CBFS is in. It defaults to 0xFFFFFFFF\n" |
| 45 | ); |
| 46 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 47 | static int do_cbfs_fsload(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | 633fb73 | 2016-03-13 19:07:27 -0600 | [diff] [blame] | 48 | char *const argv[]) |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 49 | { |
| 50 | const struct cbfs_cachenode *file; |
| 51 | unsigned long offset; |
| 52 | unsigned long count; |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 53 | long size; |
| 54 | |
| 55 | if (argc < 3) { |
| 56 | printf("usage: cbfsload <addr> <filename> [bytes]\n"); |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | /* parse offset and count */ |
| 61 | offset = simple_strtoul(argv[1], NULL, 16); |
| 62 | if (argc == 4) |
| 63 | count = simple_strtoul(argv[3], NULL, 16); |
| 64 | else |
| 65 | count = 0; |
| 66 | |
| 67 | file = file_cbfs_find(argv[2]); |
| 68 | if (!file) { |
Simon Glass | c7f1693 | 2019-08-14 19:56:13 -0600 | [diff] [blame] | 69 | if (cbfs_get_result() == CBFS_FILE_NOT_FOUND) |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 70 | printf("%s: %s\n", file_cbfs_error(), argv[2]); |
| 71 | else |
| 72 | printf("%s.\n", file_cbfs_error()); |
| 73 | return 1; |
| 74 | } |
| 75 | |
| 76 | printf("reading %s\n", file_cbfs_name(file)); |
| 77 | |
| 78 | size = file_cbfs_read(file, (void *)offset, count); |
| 79 | |
| 80 | printf("\n%ld bytes read\n", size); |
| 81 | |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 82 | env_set_hex("filesize", size); |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | U_BOOT_CMD( |
| 88 | cbfsload, 4, 0, do_cbfs_fsload, |
| 89 | "load binary file from a cbfs filesystem", |
| 90 | "<addr> <filename> [bytes]\n" |
| 91 | " - load binary file 'filename' from the cbfs to address 'addr'\n" |
| 92 | ); |
| 93 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 94 | static int do_cbfs_ls(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | 633fb73 | 2016-03-13 19:07:27 -0600 | [diff] [blame] | 95 | char *const argv[]) |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 96 | { |
| 97 | const struct cbfs_cachenode *file = file_cbfs_get_first(); |
| 98 | int files = 0; |
| 99 | |
| 100 | if (!file) { |
| 101 | printf("%s.\n", file_cbfs_error()); |
| 102 | return 1; |
| 103 | } |
| 104 | |
| 105 | printf(" size type name\n"); |
| 106 | printf("------------------------------------------\n"); |
| 107 | while (file) { |
Simon Glass | a696d76 | 2016-02-29 15:25:49 -0700 | [diff] [blame] | 108 | int type = file_cbfs_type(file); |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 109 | char *type_name = NULL; |
| 110 | const char *filename = file_cbfs_name(file); |
| 111 | |
| 112 | printf(" %8d", file_cbfs_size(file)); |
| 113 | |
| 114 | switch (type) { |
Bin Meng | 881bb9a | 2018-12-22 01:55:51 -0800 | [diff] [blame] | 115 | case CBFS_TYPE_BOOTBLOCK: |
| 116 | type_name = "bootblock"; |
| 117 | break; |
| 118 | case CBFS_TYPE_CBFSHEADER: |
| 119 | type_name = "cbfs header"; |
| 120 | break; |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 121 | case CBFS_TYPE_STAGE: |
| 122 | type_name = "stage"; |
| 123 | break; |
| 124 | case CBFS_TYPE_PAYLOAD: |
| 125 | type_name = "payload"; |
| 126 | break; |
Bin Meng | 881bb9a | 2018-12-22 01:55:51 -0800 | [diff] [blame] | 127 | case CBFS_TYPE_FIT: |
| 128 | type_name = "fit"; |
| 129 | break; |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 130 | case CBFS_TYPE_OPTIONROM: |
| 131 | type_name = "option rom"; |
| 132 | break; |
| 133 | case CBFS_TYPE_BOOTSPLASH: |
| 134 | type_name = "boot splash"; |
| 135 | break; |
| 136 | case CBFS_TYPE_RAW: |
| 137 | type_name = "raw"; |
| 138 | break; |
| 139 | case CBFS_TYPE_VSA: |
| 140 | type_name = "vsa"; |
| 141 | break; |
| 142 | case CBFS_TYPE_MBI: |
| 143 | type_name = "mbi"; |
| 144 | break; |
| 145 | case CBFS_TYPE_MICROCODE: |
| 146 | type_name = "microcode"; |
| 147 | break; |
Bin Meng | 881bb9a | 2018-12-22 01:55:51 -0800 | [diff] [blame] | 148 | case CBFS_TYPE_FSP: |
| 149 | type_name = "fsp"; |
| 150 | break; |
| 151 | case CBFS_TYPE_MRC: |
| 152 | type_name = "mrc"; |
| 153 | break; |
| 154 | case CBFS_TYPE_MMA: |
| 155 | type_name = "mma"; |
| 156 | break; |
| 157 | case CBFS_TYPE_EFI: |
| 158 | type_name = "efi"; |
| 159 | break; |
| 160 | case CBFS_TYPE_STRUCT: |
| 161 | type_name = "struct"; |
| 162 | break; |
Bin Meng | 14fdf91 | 2018-12-22 01:55:50 -0800 | [diff] [blame] | 163 | case CBFS_TYPE_CMOS_DEFAULT: |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 164 | type_name = "cmos default"; |
| 165 | break; |
Bin Meng | 881bb9a | 2018-12-22 01:55:51 -0800 | [diff] [blame] | 166 | case CBFS_TYPE_SPD: |
| 167 | type_name = "spd"; |
| 168 | break; |
| 169 | case CBFS_TYPE_MRC_CACHE: |
| 170 | type_name = "mrc cache"; |
| 171 | break; |
Bin Meng | 14fdf91 | 2018-12-22 01:55:50 -0800 | [diff] [blame] | 172 | case CBFS_TYPE_CMOS_LAYOUT: |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 173 | type_name = "cmos layout"; |
| 174 | break; |
Simon Glass | a696d76 | 2016-02-29 15:25:49 -0700 | [diff] [blame] | 175 | case -1: |
| 176 | case 0: |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 177 | type_name = "null"; |
| 178 | break; |
| 179 | } |
| 180 | if (type_name) |
| 181 | printf(" %16s", type_name); |
| 182 | else |
| 183 | printf(" %16d", type); |
| 184 | |
| 185 | if (filename[0]) |
| 186 | printf(" %s\n", filename); |
| 187 | else |
| 188 | printf(" %s\n", "(empty)"); |
| 189 | file_cbfs_get_next(&file); |
| 190 | files++; |
| 191 | } |
| 192 | |
| 193 | printf("\n%d file(s)\n\n", files); |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | U_BOOT_CMD( |
| 198 | cbfsls, 1, 1, do_cbfs_ls, |
| 199 | "list files", |
| 200 | " - list the files in the cbfs\n" |
| 201 | ); |
| 202 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 203 | static int do_cbfs_fsinfo(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | 633fb73 | 2016-03-13 19:07:27 -0600 | [diff] [blame] | 204 | char *const argv[]) |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 205 | { |
| 206 | const struct cbfs_header *header = file_cbfs_get_header(); |
| 207 | |
| 208 | if (!header) { |
| 209 | printf("%s.\n", file_cbfs_error()); |
| 210 | return 1; |
| 211 | } |
| 212 | |
| 213 | printf("\n"); |
| 214 | printf("CBFS version: %#x\n", header->version); |
| 215 | printf("ROM size: %#x\n", header->rom_size); |
| 216 | printf("Boot block size: %#x\n", header->boot_block_size); |
| 217 | printf("CBFS size: %#x\n", |
| 218 | header->rom_size - header->boot_block_size - header->offset); |
| 219 | printf("Alignment: %d\n", header->align); |
| 220 | printf("Offset: %#x\n", header->offset); |
| 221 | printf("\n"); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | U_BOOT_CMD( |
| 227 | cbfsinfo, 1, 1, do_cbfs_fsinfo, |
| 228 | "print information about filesystem", |
| 229 | " - print information about the cbfs filesystem\n" |
| 230 | ); |