Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * CBFS commands |
| 25 | */ |
| 26 | #include <common.h> |
| 27 | #include <command.h> |
| 28 | #include <cbfs.h> |
| 29 | |
| 30 | int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 31 | { |
| 32 | uintptr_t end_of_rom = 0xffffffff; |
| 33 | char *ep; |
| 34 | |
| 35 | if (argc > 2) { |
| 36 | printf("usage: cbfsls [end of rom]>\n"); |
| 37 | return 0; |
| 38 | } |
| 39 | if (argc == 2) { |
| 40 | end_of_rom = (int)simple_strtoul(argv[1], &ep, 16); |
| 41 | if (*ep) { |
| 42 | puts("\n** Invalid end of ROM **\n"); |
| 43 | return 1; |
| 44 | } |
| 45 | } |
| 46 | file_cbfs_init(end_of_rom); |
| 47 | if (file_cbfs_result != CBFS_SUCCESS) { |
| 48 | printf("%s.\n", file_cbfs_error()); |
| 49 | return 1; |
| 50 | } |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | U_BOOT_CMD( |
| 55 | cbfsinit, 2, 0, do_cbfs_init, |
| 56 | "initialize the cbfs driver", |
| 57 | "[end of rom]\n" |
| 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" |
| 61 | ); |
| 62 | |
| 63 | int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 64 | { |
| 65 | const struct cbfs_cachenode *file; |
| 66 | unsigned long offset; |
| 67 | unsigned long count; |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 68 | long size; |
| 69 | |
| 70 | if (argc < 3) { |
| 71 | printf("usage: cbfsload <addr> <filename> [bytes]\n"); |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | /* parse offset and count */ |
| 76 | offset = simple_strtoul(argv[1], NULL, 16); |
| 77 | if (argc == 4) |
| 78 | count = simple_strtoul(argv[3], NULL, 16); |
| 79 | else |
| 80 | count = 0; |
| 81 | |
| 82 | file = file_cbfs_find(argv[2]); |
| 83 | if (!file) { |
| 84 | if (file_cbfs_result == CBFS_FILE_NOT_FOUND) |
| 85 | printf("%s: %s\n", file_cbfs_error(), argv[2]); |
| 86 | else |
| 87 | printf("%s.\n", file_cbfs_error()); |
| 88 | return 1; |
| 89 | } |
| 90 | |
| 91 | printf("reading %s\n", file_cbfs_name(file)); |
| 92 | |
| 93 | size = file_cbfs_read(file, (void *)offset, count); |
| 94 | |
| 95 | printf("\n%ld bytes read\n", size); |
| 96 | |
Simon Glass | 41ef372 | 2013-02-24 17:33:22 +0000 | [diff] [blame^] | 97 | setenv_hex("filesize", size); |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | U_BOOT_CMD( |
| 103 | cbfsload, 4, 0, do_cbfs_fsload, |
| 104 | "load binary file from a cbfs filesystem", |
| 105 | "<addr> <filename> [bytes]\n" |
| 106 | " - load binary file 'filename' from the cbfs to address 'addr'\n" |
| 107 | ); |
| 108 | |
| 109 | int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 110 | { |
| 111 | const struct cbfs_cachenode *file = file_cbfs_get_first(); |
| 112 | int files = 0; |
| 113 | |
| 114 | if (!file) { |
| 115 | printf("%s.\n", file_cbfs_error()); |
| 116 | return 1; |
| 117 | } |
| 118 | |
| 119 | printf(" size type name\n"); |
| 120 | printf("------------------------------------------\n"); |
| 121 | while (file) { |
| 122 | u32 type = file_cbfs_type(file); |
| 123 | char *type_name = NULL; |
| 124 | const char *filename = file_cbfs_name(file); |
| 125 | |
| 126 | printf(" %8d", file_cbfs_size(file)); |
| 127 | |
| 128 | switch (type) { |
| 129 | case CBFS_TYPE_STAGE: |
| 130 | type_name = "stage"; |
| 131 | break; |
| 132 | case CBFS_TYPE_PAYLOAD: |
| 133 | type_name = "payload"; |
| 134 | break; |
| 135 | case CBFS_TYPE_OPTIONROM: |
| 136 | type_name = "option rom"; |
| 137 | break; |
| 138 | case CBFS_TYPE_BOOTSPLASH: |
| 139 | type_name = "boot splash"; |
| 140 | break; |
| 141 | case CBFS_TYPE_RAW: |
| 142 | type_name = "raw"; |
| 143 | break; |
| 144 | case CBFS_TYPE_VSA: |
| 145 | type_name = "vsa"; |
| 146 | break; |
| 147 | case CBFS_TYPE_MBI: |
| 148 | type_name = "mbi"; |
| 149 | break; |
| 150 | case CBFS_TYPE_MICROCODE: |
| 151 | type_name = "microcode"; |
| 152 | break; |
| 153 | case CBFS_COMPONENT_CMOS_DEFAULT: |
| 154 | type_name = "cmos default"; |
| 155 | break; |
| 156 | case CBFS_COMPONENT_CMOS_LAYOUT: |
| 157 | type_name = "cmos layout"; |
| 158 | break; |
| 159 | case -1UL: |
| 160 | type_name = "null"; |
| 161 | break; |
| 162 | } |
| 163 | if (type_name) |
| 164 | printf(" %16s", type_name); |
| 165 | else |
| 166 | printf(" %16d", type); |
| 167 | |
| 168 | if (filename[0]) |
| 169 | printf(" %s\n", filename); |
| 170 | else |
| 171 | printf(" %s\n", "(empty)"); |
| 172 | file_cbfs_get_next(&file); |
| 173 | files++; |
| 174 | } |
| 175 | |
| 176 | printf("\n%d file(s)\n\n", files); |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | U_BOOT_CMD( |
| 181 | cbfsls, 1, 1, do_cbfs_ls, |
| 182 | "list files", |
| 183 | " - list the files in the cbfs\n" |
| 184 | ); |
| 185 | |
| 186 | int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 187 | { |
| 188 | const struct cbfs_header *header = file_cbfs_get_header(); |
| 189 | |
| 190 | if (!header) { |
| 191 | printf("%s.\n", file_cbfs_error()); |
| 192 | return 1; |
| 193 | } |
| 194 | |
| 195 | printf("\n"); |
| 196 | printf("CBFS version: %#x\n", header->version); |
| 197 | printf("ROM size: %#x\n", header->rom_size); |
| 198 | printf("Boot block size: %#x\n", header->boot_block_size); |
| 199 | printf("CBFS size: %#x\n", |
| 200 | header->rom_size - header->boot_block_size - header->offset); |
| 201 | printf("Alignment: %d\n", header->align); |
| 202 | printf("Offset: %#x\n", header->offset); |
| 203 | printf("\n"); |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | U_BOOT_CMD( |
| 209 | cbfsinfo, 1, 1, do_cbfs_fsinfo, |
| 210 | "print information about filesystem", |
| 211 | " - print information about the cbfs filesystem\n" |
| 212 | ); |