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