This is transition code for cbfs to implement
[coreboot.git] / util / cbfstool / print.c
1 /*
2  * cbfstool
3  *
4  * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
18  */
19
20 #include <string.h>
21 #include "cbfstool.h"
22
23 void print_usage(void)
24 {
25         printf("print\t\t\t\tShow the contents of the ROM\n");
26 }
27
28 int print_handler(struct rom *rom, int argc, char **argv)
29 {
30         if ( argc > 0 ) {
31                 ERROR("print %s? print takes no arguments.\n", argv[0]);
32                 print_usage();
33                 return -1;
34         }
35
36         printf("%s: %d kB, bootblocksize %d, romsize %d, offset 0x%x\n", rom->name, rom->size / 1024, 
37                                 ntohl(rom->header->bootblocksize), ntohl(rom->header->romsize), ntohl(rom->header->offset));
38         printf("Alignment: %d bytes\n\n", ntohl(rom->header->align));
39
40         struct cbfs_file *c = rom_find_first(rom);
41
42         printf("%-30s Offset     %-12s Size\n", "Name", "Type");
43
44         while (c) {
45                 char type[12];
46
47                 switch (htonl(c->type)) {
48                 case CBFS_COMPONENT_STAGE:
49                         strcpy(type, "stage");
50                         break;
51                 case CBFS_COMPONENT_PAYLOAD:
52                         strcpy(type, "payload");
53                         break;
54                 case CBFS_COMPONENT_OPTIONROM:
55                         strcpy(type, "optionrom");
56                         break;
57                 case CBFS_COMPONENT_NULL:
58                         strcpy(type, "free");
59                         break;
60                 case CBFS_COMPONENT_DELETED:
61                         strcpy(type, "deleted");
62                         break;
63                 default:
64                         sprintf(type, "0x%8.8x", htonl(c->type));
65                         break;
66                 }
67
68                 printf("%-30s 0x%-8x %-12s %d\n", CBFS_NAME(c),
69                        ROM_OFFSET(rom, c), type, htonl(c->len));
70
71                 c = rom_find_next(rom, c);
72         }
73
74         return 0;
75 }