Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 4 | * Copyright 2012 Google Inc. |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 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 | |
Nico Huber | 8e4bb928 | 2013-05-26 18:17:54 +0200 | [diff] [blame] | 20 | #include <inttypes.h> |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 24 | #include <unistd.h> |
Stefan Reinauer | 8c59477 | 2013-04-19 14:22:29 -0700 | [diff] [blame] | 25 | #include <inttypes.h> |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 26 | #include <getopt.h> |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 27 | #include <dirent.h> |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 28 | #include <errno.h> |
| 29 | #include <fcntl.h> |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 30 | #include <ctype.h> |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 31 | #include <arpa/inet.h> |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 32 | #include <sys/types.h> |
| 33 | #include <sys/stat.h> |
| 34 | #include <sys/mman.h> |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 35 | #include <libgen.h> |
| 36 | #include <assert.h> |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 37 | |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 38 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 39 | #define MAP_BYTES (1024*1024) |
Kyösti Mälkki | b3594ab | 2014-06-18 00:43:35 +0300 | [diff] [blame] | 40 | #define IS_ENABLED(x) (defined (x) && (x)) |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 41 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 42 | #include "boot/coreboot_tables.h" |
| 43 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 44 | typedef uint8_t u8; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 45 | typedef uint16_t u16; |
| 46 | typedef uint32_t u32; |
| 47 | typedef uint64_t u64; |
| 48 | |
| 49 | #include "cbmem.h" |
| 50 | #include "timestamp.h" |
| 51 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 52 | #define CBMEM_VERSION "1.1" |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 53 | |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 54 | /* verbose output? */ |
| 55 | static int verbose = 0; |
| 56 | #define debug(x...) if(verbose) printf(x) |
| 57 | |
| 58 | /* File handle used to access /dev/mem */ |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 59 | static int mem_fd; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | * calculate ip checksum (16 bit quantities) on a passed in buffer. In case |
| 63 | * the buffer length is odd last byte is excluded from the calculation |
| 64 | */ |
| 65 | static u16 ipchcksum(const void *addr, unsigned size) |
| 66 | { |
| 67 | const u16 *p = addr; |
| 68 | unsigned i, n = size / 2; /* don't expect odd sized blocks */ |
| 69 | u32 sum = 0; |
| 70 | |
| 71 | for (i = 0; i < n; i++) |
| 72 | sum += p[i]; |
| 73 | |
| 74 | sum = (sum >> 16) + (sum & 0xffff); |
| 75 | sum += (sum >> 16); |
| 76 | sum = ~sum & 0xffff; |
| 77 | return (u16) sum; |
| 78 | } |
| 79 | |
| 80 | /* |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 81 | * Functions to map / unmap physical memory into virtual address space. These |
| 82 | * functions always maps 1MB at a time and can only map one area at once. |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 83 | */ |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 84 | static void *mapped_virtual; |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 85 | static size_t mapped_size; |
| 86 | |
| 87 | static inline size_t size_to_mib(size_t sz) |
| 88 | { |
| 89 | return sz >> 20; |
| 90 | } |
| 91 | |
| 92 | static void unmap_memory(void) |
| 93 | { |
| 94 | if (mapped_virtual == NULL) { |
| 95 | fprintf(stderr, "Error unmapping memory\n"); |
| 96 | return; |
| 97 | } |
| 98 | debug("Unmapping %zuMB of virtual memory at %p.\n", |
| 99 | size_to_mib(mapped_size), mapped_virtual); |
| 100 | munmap(mapped_virtual, mapped_size); |
| 101 | mapped_virtual = NULL; |
| 102 | mapped_size = 0; |
| 103 | } |
| 104 | |
| 105 | static void *map_memory_size(u64 physical, size_t size) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 106 | { |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 107 | void *v; |
| 108 | off_t p; |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 109 | u64 page = getpagesize(); |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 110 | size_t padding; |
| 111 | |
| 112 | if (mapped_virtual != NULL) |
| 113 | unmap_memory(); |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 114 | |
| 115 | /* Mapped memory must be aligned to page size */ |
| 116 | p = physical & ~(page - 1); |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 117 | padding = physical & (page-1); |
| 118 | size += padding; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 119 | |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 120 | debug("Mapping %zuMB of physical memory at 0x%jx.\n", |
| 121 | size_to_mib(size), (intmax_t)p); |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 122 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 123 | v = mmap(NULL, size, PROT_READ, MAP_SHARED, mem_fd, p); |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 124 | |
| 125 | if (v == MAP_FAILED) { |
| 126 | fprintf(stderr, "Failed to mmap /dev/mem: %s\n", |
| 127 | strerror(errno)); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 128 | exit(1); |
| 129 | } |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 130 | |
| 131 | /* Remember what we actually mapped ... */ |
| 132 | mapped_virtual = v; |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 133 | mapped_size = size; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 134 | |
| 135 | /* ... but return address to the physical memory that was requested */ |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 136 | if (padding) |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 137 | debug(" ... padding virtual address with 0x%zx bytes.\n", |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 138 | padding); |
| 139 | v += padding; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 140 | |
| 141 | return v; |
| 142 | } |
| 143 | |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 144 | static void *map_memory(u64 physical) |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 145 | { |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 146 | return map_memory_size(physical, MAP_BYTES); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 150 | * Try finding the timestamp table and coreboot cbmem console starting from the |
| 151 | * passed in memory offset. Could be called recursively in case a forwarding |
| 152 | * entry is found. |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 153 | * |
| 154 | * Returns pointer to a memory buffer containg the timestamp table or zero if |
| 155 | * none found. |
| 156 | */ |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 157 | |
| 158 | static struct lb_cbmem_ref timestamps; |
| 159 | static struct lb_cbmem_ref console; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 160 | static struct lb_memory_range cbmem; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 161 | |
Stefan Reinauer | 8c59477 | 2013-04-19 14:22:29 -0700 | [diff] [blame] | 162 | /* This is a work-around for a nasty problem introduced by initially having |
| 163 | * pointer sized entries in the lb_cbmem_ref structures. This caused problems |
| 164 | * on 64bit x86 systems because coreboot is 32bit on those systems. |
| 165 | * When the problem was found, it was corrected, but there are a lot of |
| 166 | * systems out there with a firmware that does not produce the right |
| 167 | * lb_cbmem_ref structure. Hence we try to autocorrect this issue here. |
| 168 | */ |
| 169 | static struct lb_cbmem_ref parse_cbmem_ref(struct lb_cbmem_ref *cbmem_ref) |
| 170 | { |
| 171 | struct lb_cbmem_ref ret; |
| 172 | |
| 173 | ret = *cbmem_ref; |
| 174 | |
| 175 | if (cbmem_ref->size < sizeof(*cbmem_ref)) |
| 176 | ret.cbmem_addr = (uint32_t)ret.cbmem_addr; |
| 177 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 178 | debug(" cbmem_addr = %" PRIx64 "\n", ret.cbmem_addr); |
| 179 | |
Stefan Reinauer | 8c59477 | 2013-04-19 14:22:29 -0700 | [diff] [blame] | 180 | return ret; |
| 181 | } |
| 182 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 183 | static int parse_cbtable(u64 address, size_t table_size) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 184 | { |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 185 | int i, found = 0; |
| 186 | void *buf; |
| 187 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 188 | debug("Looking for coreboot table at %" PRIx64 " %zd bytes.\n", |
| 189 | address, table_size); |
| 190 | buf = map_memory_size(address, table_size); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 191 | |
| 192 | /* look at every 16 bytes within 4K of the base */ |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 193 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 194 | for (i = 0; i < 0x1000; i += 0x10) { |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 195 | struct lb_header *lbh; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 196 | struct lb_record* lbr_p; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 197 | void *lbtable; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 198 | int j; |
| 199 | |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 200 | lbh = (struct lb_header *)(buf + i); |
| 201 | if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) || |
| 202 | !lbh->header_bytes || |
| 203 | ipchcksum(lbh, sizeof(*lbh))) { |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 204 | continue; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 205 | } |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 206 | lbtable = buf + i + lbh->header_bytes; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 207 | |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 208 | if (ipchcksum(lbtable, lbh->table_bytes) != |
| 209 | lbh->table_checksum) { |
| 210 | debug("Signature found, but wrong checksum.\n"); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 211 | continue; |
| 212 | } |
| 213 | |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 214 | found = 1; |
| 215 | debug("Found!\n"); |
| 216 | |
| 217 | for (j = 0; j < lbh->table_bytes; j += lbr_p->size) { |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 218 | lbr_p = (struct lb_record*) ((char *)lbtable + j); |
| 219 | debug(" coreboot table entry 0x%02x\n", lbr_p->tag); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 220 | switch (lbr_p->tag) { |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 221 | case LB_TAG_MEMORY: { |
| 222 | int i = 0; |
| 223 | debug(" Found memory map.\n"); |
| 224 | struct lb_memory *memory = |
| 225 | (struct lb_memory *)lbr_p; |
Paul Menzel | 747c07f | 2014-10-17 13:46:12 +0200 | [diff] [blame] | 226 | while ((char *)&memory->map[i] < ((char *)lbr_p |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 227 | + lbr_p->size)) { |
| 228 | if (memory->map[i].type == LB_MEM_TABLE) { |
| 229 | debug(" LB_MEM_TABLE found.\n"); |
| 230 | /* The last one found is CBMEM */ |
| 231 | cbmem = memory->map[i]; |
| 232 | } |
| 233 | i++; |
| 234 | } |
| 235 | continue; |
| 236 | } |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 237 | case LB_TAG_TIMESTAMPS: { |
Stefan Reinauer | d7144dc | 2013-01-07 15:25:37 -0800 | [diff] [blame] | 238 | debug(" Found timestamp table.\n"); |
Stefan Reinauer | 8c59477 | 2013-04-19 14:22:29 -0700 | [diff] [blame] | 239 | timestamps = parse_cbmem_ref((struct lb_cbmem_ref *) lbr_p); |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 240 | continue; |
| 241 | } |
| 242 | case LB_TAG_CBMEM_CONSOLE: { |
Stefan Reinauer | d7144dc | 2013-01-07 15:25:37 -0800 | [diff] [blame] | 243 | debug(" Found cbmem console.\n"); |
Stefan Reinauer | 8c59477 | 2013-04-19 14:22:29 -0700 | [diff] [blame] | 244 | console = parse_cbmem_ref((struct lb_cbmem_ref *) lbr_p); |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 245 | continue; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 246 | } |
| 247 | case LB_TAG_FORWARD: { |
| 248 | /* |
| 249 | * This is a forwarding entry - repeat the |
| 250 | * search at the new address. |
| 251 | */ |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 252 | struct lb_forward lbf_p = |
| 253 | *(struct lb_forward *) lbr_p; |
Stefan Reinauer | d7144dc | 2013-01-07 15:25:37 -0800 | [diff] [blame] | 254 | debug(" Found forwarding entry.\n"); |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 255 | unmap_memory(); |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 256 | return parse_cbtable(lbf_p.forward, table_size); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 257 | } |
| 258 | default: |
| 259 | break; |
| 260 | } |
| 261 | |
| 262 | } |
| 263 | } |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 264 | unmap_memory(); |
| 265 | |
| 266 | return found; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Stefan Reinauer | d8ef9e9 | 2013-07-31 15:44:37 -0700 | [diff] [blame] | 269 | #if defined(__i386__) || defined(__x86_64__) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 270 | /* |
| 271 | * read CPU frequency from a sysfs file, return an frequency in Kilohertz as |
| 272 | * an int or exit on any error. |
| 273 | */ |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 274 | static u64 get_cpu_freq_KHz(void) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 275 | { |
| 276 | FILE *cpuf; |
| 277 | char freqs[100]; |
| 278 | int size; |
| 279 | char *endp; |
| 280 | u64 rv; |
| 281 | |
| 282 | const char* freq_file = |
| 283 | "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; |
| 284 | |
| 285 | cpuf = fopen(freq_file, "r"); |
| 286 | if (!cpuf) { |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 287 | fprintf(stderr, "Could not open %s: %s\n", |
| 288 | freq_file, strerror(errno)); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 289 | exit(1); |
| 290 | } |
| 291 | |
| 292 | memset(freqs, 0, sizeof(freqs)); |
| 293 | size = fread(freqs, 1, sizeof(freqs), cpuf); |
| 294 | if (!size || (size == sizeof(freqs))) { |
| 295 | fprintf(stderr, "Wrong number of bytes(%d) read from %s\n", |
| 296 | size, freq_file); |
| 297 | exit(1); |
| 298 | } |
| 299 | fclose(cpuf); |
| 300 | rv = strtoull(freqs, &endp, 10); |
| 301 | |
| 302 | if (*endp == '\0' || *endp == '\n') |
| 303 | return rv; |
| 304 | fprintf(stderr, "Wrong formatted value ^%s^ read from %s\n", |
| 305 | freqs, freq_file); |
| 306 | exit(1); |
| 307 | } |
| 308 | |
Stefan Reinauer | d8ef9e9 | 2013-07-31 15:44:37 -0700 | [diff] [blame] | 309 | /* On x86 platforms timestamps are stored |
| 310 | * in CPU cycles (from rdtsc). Hence the |
| 311 | * timestamp divider is the CPU frequency |
| 312 | * in MHz. |
| 313 | */ |
| 314 | u64 arch_convert_raw_ts_entry(u64 ts) |
| 315 | { |
| 316 | static u64 cpu_freq_mhz = 0; |
| 317 | |
| 318 | if (!cpu_freq_mhz) |
| 319 | cpu_freq_mhz = get_cpu_freq_KHz() / 1000; |
| 320 | |
| 321 | return ts / cpu_freq_mhz; |
| 322 | } |
| 323 | |
| 324 | #else |
| 325 | |
| 326 | /* On non-x86 platforms the timestamp entries |
| 327 | * are not in clock cycles but in usecs |
| 328 | */ |
| 329 | u64 arch_convert_raw_ts_entry(u64 ts) |
| 330 | { |
| 331 | return ts; |
| 332 | } |
| 333 | #endif |
| 334 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 335 | /* |
| 336 | * Print an integer in 'normalized' form - with commas separating every three |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 337 | * decimal orders. |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 338 | */ |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 339 | static void print_norm(u64 v) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 340 | { |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 341 | if (v >= 1000) { |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 342 | /* print the higher order sections first */ |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 343 | print_norm(v / 1000); |
| 344 | printf(",%3.3u", (u32)(v % 1000)); |
| 345 | } else { |
| 346 | printf("%u", (u32)(v % 1000)); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 347 | } |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 350 | enum additional_timestamp_id { |
| 351 | // Depthcharge entry IDs start at 1000. |
| 352 | TS_DC_START = 1000, |
| 353 | |
| 354 | TS_RO_PARAMS_INIT = 1001, |
| 355 | TS_RO_VB_INIT = 1002, |
| 356 | TS_RO_VB_SELECT_FIRMWARE = 1003, |
| 357 | TS_RO_VB_SELECT_AND_LOAD_KERNEL = 1004, |
| 358 | |
| 359 | TS_RW_VB_SELECT_AND_LOAD_KERNEL = 1010, |
| 360 | |
| 361 | TS_VB_SELECT_AND_LOAD_KERNEL = 1020, |
| 362 | |
| 363 | TS_CROSSYSTEM_DATA = 1100, |
| 364 | TS_START_KERNEL = 1101 |
| 365 | }; |
| 366 | |
| 367 | static const struct timestamp_id_to_name { |
| 368 | u32 id; |
| 369 | const char *name; |
| 370 | } timestamp_ids[] = { |
| 371 | { TS_START_ROMSTAGE, "start of rom stage" }, |
| 372 | { TS_BEFORE_INITRAM, "before ram initialization" }, |
| 373 | { TS_AFTER_INITRAM, "after ram initialization" }, |
| 374 | { TS_END_ROMSTAGE, "end of romstage" }, |
| 375 | { TS_START_VBOOT, "start of verified boot" }, |
| 376 | { TS_END_VBOOT, "end of verified boot" }, |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 377 | { TS_START_COPYRAM, "starting to load ramstage" }, |
| 378 | { TS_END_COPYRAM, "finished loading ramstage" }, |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 379 | { TS_START_RAMSTAGE, "start of ramstage" }, |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 380 | { TS_START_BOOTBLOCK, "start of bootblock" }, |
| 381 | { TS_END_BOOTBLOCK, "end of bootblock" }, |
| 382 | { TS_START_COPYROM, "starting to load romstage" }, |
| 383 | { TS_END_COPYROM, "finished loading romstage" }, |
| 384 | { TS_START_ULZMA, "starting LZMA decompress (ignore for x86)" }, |
| 385 | { TS_END_ULZMA, "finished LZMA decompress (ignore for x86)" }, |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 386 | { TS_DEVICE_ENUMERATE, "device enumeration" }, |
| 387 | { TS_DEVICE_CONFIGURE, "device configuration" }, |
| 388 | { TS_DEVICE_ENABLE, "device enable" }, |
| 389 | { TS_DEVICE_INITIALIZE, "device initialization" }, |
| 390 | { TS_DEVICE_DONE, "device setup done" }, |
| 391 | { TS_CBMEM_POST, "cbmem post" }, |
| 392 | { TS_WRITE_TABLES, "write tables" }, |
| 393 | { TS_LOAD_PAYLOAD, "load payload" }, |
| 394 | { TS_ACPI_WAKE_JUMP, "ACPI wake jump" }, |
| 395 | { TS_SELFBOOT_JUMP, "selfboot jump" }, |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 396 | |
| 397 | { TS_START_COPYVER, "starting to load verstage" }, |
| 398 | { TS_END_COPYVER, "finished loading verstage" }, |
| 399 | { TS_START_TPMINIT, "starting to initialize TPM" }, |
| 400 | { TS_END_TPMINIT, "finished TPM initialization" }, |
| 401 | { TS_START_VERIFY_SLOT, "starting to verify keyblock/preamble (RSA)" }, |
| 402 | { TS_END_VERIFY_SLOT, "finished verifying keyblock/preamble (RSA)" }, |
| 403 | { TS_START_HASH_BODY, "starting to verify body (load+SHA2+RSA) " }, |
| 404 | { TS_DONE_LOADING, "finished loading body (ignore for x86)" }, |
| 405 | { TS_DONE_HASHING, "finished calculating body hash (SHA2)" }, |
| 406 | { TS_END_HASH_BODY, "finished verifying body signature (RSA)" }, |
| 407 | |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 408 | { TS_DC_START, "depthcharge start" }, |
| 409 | { TS_RO_PARAMS_INIT, "RO parameter init" }, |
| 410 | { TS_RO_VB_INIT, "RO vboot init" }, |
| 411 | { TS_RO_VB_SELECT_FIRMWARE, "RO vboot select firmware" }, |
| 412 | { TS_RO_VB_SELECT_AND_LOAD_KERNEL, "RO vboot select&load kernel" }, |
| 413 | { TS_RW_VB_SELECT_AND_LOAD_KERNEL, "RW vboot select&load kernel" }, |
| 414 | { TS_VB_SELECT_AND_LOAD_KERNEL, "vboot select&load kernel" }, |
| 415 | { TS_CROSSYSTEM_DATA, "crossystem data" }, |
Lee Leahy | b817908 | 2015-02-24 11:30:38 -0800 | [diff] [blame^] | 416 | { TS_START_KERNEL, "start kernel" }, |
| 417 | |
| 418 | /* FSP related timestamps */ |
| 419 | { TS_FSP_MEMORY_INIT_START, "calling FspMemoryInit" }, |
| 420 | { TS_FSP_MEMORY_INIT_END, "returning from FspMemoryInit" }, |
| 421 | { TS_FSP_TEMP_RAM_EXIT_START, "calling FspTempRamExit" }, |
| 422 | { TS_FSP_TEMP_RAM_EXIT_END, "returning from FspTempRamExit" }, |
| 423 | { TS_FSP_SILICON_INIT_START, "calling FspSiliconInit" }, |
| 424 | { TS_FSP_SILICON_INIT_END, "returning from FspSiliconInit" }, |
| 425 | { TS_FSP_BEFORE_ENUMERATE, "calling FspNotify(AfterPciEnumeration)" }, |
| 426 | { TS_FSP_AFTER_ENUMERATE, |
| 427 | "returning from FspNotify(AfterPciEnumeration)" }, |
| 428 | { TS_FSP_BEFORE_FINALIZE, "calling FspNotify(ReadyToBoot)" }, |
| 429 | { TS_FSP_AFTER_FINALIZE, "returning from FspNotify(ReadyToBoot)" } |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | void timestamp_print_entry(uint32_t id, uint64_t stamp, uint64_t prev_stamp) |
| 433 | { |
| 434 | int i; |
| 435 | const char *name; |
| 436 | |
| 437 | name = "<unknown>"; |
| 438 | for (i = 0; i < ARRAY_SIZE(timestamp_ids); i++) { |
| 439 | if (timestamp_ids[i].id == id) { |
| 440 | name = timestamp_ids[i].name; |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | printf("%4d:", id); |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 446 | printf("%-50s", name); |
| 447 | print_norm(arch_convert_raw_ts_entry(stamp)); |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 448 | if (prev_stamp) { |
| 449 | printf(" ("); |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 450 | print_norm(arch_convert_raw_ts_entry(stamp - prev_stamp)); |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 451 | printf(")"); |
| 452 | } |
| 453 | printf("\n"); |
| 454 | } |
| 455 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 456 | /* dump the timestamp table */ |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 457 | static void dump_timestamps(void) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 458 | { |
| 459 | int i; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 460 | struct timestamp_table *tst_p; |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 461 | size_t size; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 462 | |
| 463 | if (timestamps.tag != LB_TAG_TIMESTAMPS) { |
| 464 | fprintf(stderr, "No timestamps found in coreboot table.\n"); |
| 465 | return; |
| 466 | } |
| 467 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 468 | size = sizeof(*tst_p); |
| 469 | tst_p = map_memory_size((unsigned long)timestamps.cbmem_addr, size); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 470 | |
| 471 | printf("%d entries total:\n\n", tst_p->num_entries); |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 472 | size += tst_p->num_entries * sizeof(tst_p->entries[0]); |
| 473 | |
| 474 | unmap_memory(); |
| 475 | tst_p = map_memory_size((unsigned long)timestamps.cbmem_addr, size); |
| 476 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 477 | for (i = 0; i < tst_p->num_entries; i++) { |
| 478 | const struct timestamp_entry *tse_p = tst_p->entries + i; |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 479 | timestamp_print_entry(tse_p->entry_id, tse_p->entry_stamp, |
| 480 | i ? tse_p[-1].entry_stamp : 0); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 481 | } |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 482 | |
| 483 | unmap_memory(); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 486 | /* dump the cbmem console */ |
| 487 | static void dump_console(void) |
| 488 | { |
| 489 | void *console_p; |
| 490 | char *console_c; |
| 491 | uint32_t size; |
Vladimir Serbinenko | f4a0d01 | 2013-03-30 12:15:12 +0100 | [diff] [blame] | 492 | uint32_t cursor; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 493 | |
| 494 | if (console.tag != LB_TAG_CBMEM_CONSOLE) { |
| 495 | fprintf(stderr, "No console found in coreboot table.\n"); |
| 496 | return; |
| 497 | } |
| 498 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 499 | console_p = map_memory_size((unsigned long)console.cbmem_addr, |
| 500 | 2 * sizeof(uint32_t)); |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 501 | /* The in-memory format of the console area is: |
| 502 | * u32 size |
| 503 | * u32 cursor |
| 504 | * char console[size] |
| 505 | * Hence we have to add 8 to get to the actual console string. |
| 506 | */ |
Gabe Black | 06b13a3 | 2013-08-09 00:40:06 -0700 | [diff] [blame] | 507 | size = ((uint32_t *)console_p)[0]; |
| 508 | cursor = ((uint32_t *)console_p)[1]; |
Vladimir Serbinenko | f4a0d01 | 2013-03-30 12:15:12 +0100 | [diff] [blame] | 509 | /* Cursor continues to go on even after no more data fits in |
| 510 | * the buffer but the data is dropped in this case. |
| 511 | */ |
| 512 | if (size > cursor) |
| 513 | size = cursor; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 514 | console_c = malloc(size + 1); |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 515 | unmap_memory(); |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 516 | if (!console_c) { |
| 517 | fprintf(stderr, "Not enough memory for console.\n"); |
| 518 | exit(1); |
| 519 | } |
| 520 | |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 521 | console_p = map_memory_size((unsigned long)console.cbmem_addr, |
| 522 | size + sizeof(size) + sizeof(cursor)); |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 523 | memcpy(console_c, console_p + 8, size); |
| 524 | console_c[size] = 0; |
Gabe Black | 06b13a3 | 2013-08-09 00:40:06 -0700 | [diff] [blame] | 525 | console_c[cursor] = 0; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 526 | |
Vladimir Serbinenko | f4a0d01 | 2013-03-30 12:15:12 +0100 | [diff] [blame] | 527 | printf("%s\n", console_c); |
| 528 | if (size < cursor) |
| 529 | printf("%d %s lost\n", cursor - size, |
| 530 | (cursor - size) == 1 ? "byte":"bytes"); |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 531 | |
| 532 | free(console_c); |
| 533 | |
| 534 | unmap_memory(); |
| 535 | } |
| 536 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 537 | static void hexdump(unsigned long memory, int length) |
| 538 | { |
| 539 | int i; |
| 540 | uint8_t *m; |
| 541 | int all_zero = 0; |
| 542 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 543 | m = map_memory_size((intptr_t)memory, length); |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 544 | |
| 545 | if (length > MAP_BYTES) { |
| 546 | printf("Truncating hex dump from %d to %d bytes\n\n", |
| 547 | length, MAP_BYTES); |
| 548 | length = MAP_BYTES; |
| 549 | } |
| 550 | |
| 551 | for (i = 0; i < length; i += 16) { |
| 552 | int j; |
| 553 | |
| 554 | all_zero++; |
| 555 | for (j = 0; j < 16; j++) { |
| 556 | if(m[i+j] != 0) { |
| 557 | all_zero = 0; |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | if (all_zero < 2) { |
| 563 | printf("%08lx:", memory + i); |
| 564 | for (j = 0; j < 16; j++) |
| 565 | printf(" %02x", m[i+j]); |
| 566 | printf(" "); |
| 567 | for (j = 0; j < 16; j++) |
| 568 | printf("%c", isprint(m[i+j]) ? m[i+j] : '.'); |
| 569 | printf("\n"); |
| 570 | } else if (all_zero == 2) { |
| 571 | printf("...\n"); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | unmap_memory(); |
| 576 | } |
| 577 | |
| 578 | static void dump_cbmem_hex(void) |
| 579 | { |
| 580 | if (cbmem.type != LB_MEM_TABLE) { |
| 581 | fprintf(stderr, "No coreboot CBMEM area found!\n"); |
| 582 | return; |
| 583 | } |
| 584 | |
| 585 | hexdump(unpack_lb64(cbmem.start), unpack_lb64(cbmem.size)); |
| 586 | } |
| 587 | |
| 588 | /* The root region is at least DYN_CBMEM_ALIGN_SIZE . */ |
| 589 | #define DYN_CBMEM_ALIGN_SIZE (4096) |
| 590 | #define ROOT_MIN_SIZE DYN_CBMEM_ALIGN_SIZE |
| 591 | #define CBMEM_POINTER_MAGIC 0xc0389479 |
| 592 | #define CBMEM_ENTRY_MAGIC ~(CBMEM_POINTER_MAGIC) |
| 593 | |
| 594 | struct cbmem_root_pointer { |
| 595 | uint32_t magic; |
| 596 | uint32_t root; |
| 597 | } __attribute__((packed)); |
| 598 | |
| 599 | struct dynamic_cbmem_entry { |
| 600 | uint32_t magic; |
| 601 | uint32_t start; |
| 602 | uint32_t size; |
| 603 | uint32_t id; |
| 604 | } __attribute__((packed)); |
| 605 | |
| 606 | struct cbmem_root { |
| 607 | uint32_t max_entries; |
| 608 | uint32_t num_entries; |
| 609 | uint32_t locked; |
| 610 | uint32_t size; |
| 611 | struct dynamic_cbmem_entry entries[0]; |
| 612 | } __attribute__((packed)); |
| 613 | |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 614 | #define CBMEM_MAGIC 0x434f5245 |
| 615 | #define MAX_CBMEM_ENTRIES 16 |
| 616 | |
| 617 | struct cbmem_entry { |
| 618 | uint32_t magic; |
| 619 | uint32_t id; |
| 620 | uint64_t base; |
| 621 | uint64_t size; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 622 | } __attribute__((packed)); |
| 623 | |
Aaron Durbin | 0dff57d | 2015-03-05 21:18:33 -0600 | [diff] [blame] | 624 | struct cbmem_id_to_name { |
| 625 | uint32_t id; |
| 626 | const char *name; |
| 627 | }; |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 628 | static const struct cbmem_id_to_name cbmem_ids[] = { CBMEM_ID_TO_NAME_TABLE }; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 629 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 630 | void cbmem_print_entry(int n, uint32_t id, uint64_t base, uint64_t size) |
| 631 | { |
| 632 | int i; |
| 633 | const char *name; |
| 634 | |
| 635 | name = NULL; |
| 636 | for (i = 0; i < ARRAY_SIZE(cbmem_ids); i++) { |
| 637 | if (cbmem_ids[i].id == id) { |
| 638 | name = cbmem_ids[i].name; |
| 639 | break; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | printf("%2d. ", n); |
| 644 | if (name == NULL) |
| 645 | printf("%08x ", id); |
| 646 | else |
| 647 | printf("%s", name); |
| 648 | printf(" %08" PRIx64 " ", base); |
| 649 | printf(" %08" PRIx64 "\n", size); |
| 650 | } |
| 651 | |
| 652 | static void dump_static_cbmem_toc(struct cbmem_entry *entries) |
| 653 | { |
| 654 | int i; |
| 655 | |
| 656 | printf("CBMEM table of contents:\n"); |
| 657 | printf(" ID START LENGTH\n"); |
| 658 | |
| 659 | for (i=0; i<MAX_CBMEM_ENTRIES; i++) { |
| 660 | if (entries[i].magic != CBMEM_MAGIC) |
| 661 | break; |
| 662 | cbmem_print_entry(i, entries[i].id, |
| 663 | entries[i].base, entries[i].size); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | static void dump_dynamic_cbmem_toc(struct cbmem_root *root) |
| 668 | { |
| 669 | int i; |
| 670 | debug("CBMEM: max_entries=%d num_entries=%d locked=0x%x, size=%d\n\n", |
| 671 | root->max_entries, root->num_entries, root->locked, root->size); |
| 672 | |
| 673 | printf("CBMEM table of contents:\n"); |
| 674 | printf(" ID START LENGTH\n"); |
| 675 | |
| 676 | for (i = 0; i < root->num_entries; i++) { |
| 677 | if(root->entries[i].magic != CBMEM_ENTRY_MAGIC) |
| 678 | break; |
| 679 | cbmem_print_entry(i, root->entries[i].id, |
| 680 | root->entries[i].start, root->entries[i].size); |
| 681 | } |
| 682 | } |
| 683 | |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 684 | static void dump_cbmem_toc(void) |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 685 | { |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 686 | uint64_t start; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 687 | void *cbmem_area; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 688 | struct cbmem_entry *entries; |
| 689 | |
| 690 | if (cbmem.type != LB_MEM_TABLE) { |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 691 | fprintf(stderr, "No coreboot CBMEM area found!\n"); |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 692 | return; |
| 693 | } |
| 694 | |
| 695 | start = unpack_lb64(cbmem.start); |
| 696 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 697 | cbmem_area = map_memory_size(start, unpack_lb64(cbmem.size)); |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 698 | entries = (struct cbmem_entry *)cbmem_area; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 699 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 700 | if (entries[0].magic == CBMEM_MAGIC) { |
| 701 | dump_static_cbmem_toc(entries); |
| 702 | } else { |
| 703 | uint64_t rootptr; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 704 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 705 | rootptr = unpack_lb64(cbmem.start) + unpack_lb64(cbmem.size); |
| 706 | rootptr &= ~(DYN_CBMEM_ALIGN_SIZE - 1); |
| 707 | rootptr -= sizeof(struct cbmem_root_pointer); |
| 708 | unmap_memory(); |
| 709 | struct cbmem_root_pointer *r = |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 710 | map_memory_size(rootptr, sizeof(*r)); |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 711 | if (r->magic == CBMEM_POINTER_MAGIC) { |
| 712 | struct cbmem_root *root; |
| 713 | uint64_t rootaddr = r->root; |
| 714 | unmap_memory(); |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 715 | root = map_memory_size(rootaddr, ROOT_MIN_SIZE); |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 716 | dump_dynamic_cbmem_toc(root); |
| 717 | } else |
| 718 | fprintf(stderr, "No valid coreboot CBMEM root pointer found.\n"); |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 719 | } |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 720 | |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 721 | unmap_memory(); |
| 722 | } |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 723 | |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 724 | #define COVERAGE_MAGIC 0x584d4153 |
| 725 | struct file { |
| 726 | uint32_t magic; |
| 727 | uint32_t next; |
| 728 | uint32_t filename; |
| 729 | uint32_t data; |
| 730 | int offset; |
| 731 | int len; |
| 732 | }; |
| 733 | |
| 734 | static int mkpath(char *path, mode_t mode) |
| 735 | { |
| 736 | assert (path && *path); |
| 737 | char *p; |
| 738 | for (p = strchr(path+1, '/'); p; p = strchr(p + 1, '/')) { |
| 739 | *p = '\0'; |
| 740 | if (mkdir(path, mode) == -1) { |
| 741 | if (errno != EEXIST) { |
| 742 | *p = '/'; |
| 743 | return -1; |
| 744 | } |
| 745 | } |
| 746 | *p = '/'; |
| 747 | } |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static void dump_coverage(void) |
| 752 | { |
| 753 | int i, found = 0; |
| 754 | uint64_t start; |
| 755 | struct cbmem_entry *entries; |
| 756 | void *coverage; |
| 757 | unsigned long phys_offset; |
| 758 | #define phys_to_virt(x) ((void *)(unsigned long)(x) + phys_offset) |
| 759 | |
| 760 | if (cbmem.type != LB_MEM_TABLE) { |
| 761 | fprintf(stderr, "No coreboot table area found!\n"); |
| 762 | return; |
| 763 | } |
| 764 | |
| 765 | start = unpack_lb64(cbmem.start); |
| 766 | |
| 767 | entries = (struct cbmem_entry *)map_memory(start); |
| 768 | |
| 769 | for (i=0; i<MAX_CBMEM_ENTRIES; i++) { |
| 770 | if (entries[i].magic != CBMEM_MAGIC) |
| 771 | break; |
| 772 | if (entries[i].id == CBMEM_ID_COVERAGE) { |
| 773 | found = 1; |
| 774 | break; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | if (!found) { |
| 779 | unmap_memory(); |
| 780 | fprintf(stderr, "No coverage information found in" |
| 781 | " CBMEM area.\n"); |
| 782 | return; |
| 783 | } |
| 784 | |
| 785 | start = entries[i].base; |
| 786 | unmap_memory(); |
| 787 | /* Map coverage area */ |
| 788 | coverage = map_memory(start); |
| 789 | phys_offset = (unsigned long)coverage - (unsigned long)start; |
| 790 | |
| 791 | printf("Dumping coverage data...\n"); |
| 792 | |
| 793 | struct file *file = (struct file *)coverage; |
| 794 | while (file && file->magic == COVERAGE_MAGIC) { |
| 795 | FILE *f; |
| 796 | char *filename; |
| 797 | |
| 798 | debug(" -> %s\n", (char *)phys_to_virt(file->filename)); |
| 799 | filename = strdup((char *)phys_to_virt(file->filename)); |
| 800 | if (mkpath(filename, 0755) == -1) { |
| 801 | perror("Directory for coverage data could " |
| 802 | "not be created"); |
| 803 | exit(1); |
| 804 | } |
| 805 | f = fopen(filename, "wb"); |
| 806 | if (!f) { |
| 807 | printf("Could not open %s: %s\n", |
| 808 | filename, strerror(errno)); |
| 809 | exit(1); |
| 810 | } |
| 811 | if (fwrite((void *)phys_to_virt(file->data), |
| 812 | file->len, 1, f) != 1) { |
| 813 | printf("Could not write to %s: %s\n", |
| 814 | filename, strerror(errno)); |
| 815 | exit(1); |
| 816 | } |
| 817 | fclose(f); |
| 818 | free(filename); |
| 819 | |
| 820 | if (file->next) |
| 821 | file = (struct file *)phys_to_virt(file->next); |
| 822 | else |
| 823 | file = NULL; |
| 824 | } |
| 825 | unmap_memory(); |
| 826 | } |
| 827 | |
| 828 | static void print_version(void) |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 829 | { |
| 830 | printf("cbmem v%s -- ", CBMEM_VERSION); |
| 831 | printf("Copyright (C) 2012 The ChromiumOS Authors. All rights reserved.\n\n"); |
| 832 | printf( |
| 833 | "This program is free software: you can redistribute it and/or modify\n" |
| 834 | "it under the terms of the GNU General Public License as published by\n" |
| 835 | "the Free Software Foundation, version 2 of the License.\n\n" |
| 836 | "This program is distributed in the hope that it will be useful,\n" |
| 837 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
| 838 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" |
| 839 | "GNU General Public License for more details.\n\n" |
| 840 | "You should have received a copy of the GNU General Public License\n" |
| 841 | "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n"); |
| 842 | } |
| 843 | |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 844 | static void print_usage(const char *name) |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 845 | { |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 846 | printf("usage: %s [-cCltxVvh?]\n", name); |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 847 | printf("\n" |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 848 | " -c | --console: print cbmem console\n" |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 849 | " -C | --coverage: dump coverage information\n" |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 850 | " -l | --list: print cbmem table of contents\n" |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 851 | " -x | --hexdump: print hexdump of cbmem area\n" |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 852 | " -t | --timestamps: print timestamp information\n" |
| 853 | " -V | --verbose: verbose (debugging) output\n" |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 854 | " -v | --version: print the version\n" |
| 855 | " -h | --help: print this help\n" |
| 856 | "\n"); |
| 857 | exit(1); |
| 858 | } |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 859 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 860 | #ifdef __arm__ |
| 861 | static void dt_update_cells(const char *name, int *addr_cells_ptr, |
| 862 | int *size_cells_ptr) |
| 863 | { |
| 864 | if (*addr_cells_ptr >= 0 && *size_cells_ptr >= 0) |
| 865 | return; |
| 866 | |
| 867 | int buffer; |
| 868 | size_t nlen = strlen(name); |
| 869 | char *prop = alloca(nlen + sizeof("/#address-cells")); |
| 870 | strcpy(prop, name); |
| 871 | |
| 872 | if (*addr_cells_ptr < 0) { |
| 873 | strcpy(prop + nlen, "/#address-cells"); |
| 874 | int fd = open(prop, O_RDONLY); |
| 875 | if (fd < 0 && errno != ENOENT) { |
| 876 | perror(prop); |
| 877 | } else if (fd >= 0) { |
| 878 | if (read(fd, &buffer, sizeof(int)) < 0) |
| 879 | perror(prop); |
| 880 | else |
| 881 | *addr_cells_ptr = ntohl(buffer); |
| 882 | close(fd); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | if (*size_cells_ptr < 0) { |
| 887 | strcpy(prop + nlen, "/#size-cells"); |
| 888 | int fd = open(prop, O_RDONLY); |
| 889 | if (fd < 0 && errno != ENOENT) { |
| 890 | perror(prop); |
| 891 | } else if (fd >= 0) { |
| 892 | if (read(fd, &buffer, sizeof(int)) < 0) |
| 893 | perror(prop); |
| 894 | else |
| 895 | *size_cells_ptr = ntohl(buffer); |
| 896 | close(fd); |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | static char *dt_find_compat(const char *parent, const char *compat, |
| 902 | int *addr_cells_ptr, int *size_cells_ptr) |
| 903 | { |
| 904 | char *ret = NULL; |
| 905 | struct dirent *entry; |
| 906 | DIR *dir; |
| 907 | |
| 908 | if (!(dir = opendir(parent))) { |
| 909 | perror(parent); |
| 910 | return NULL; |
| 911 | } |
| 912 | |
| 913 | /* Loop through all files in the directory (DT node). */ |
| 914 | while ((entry = readdir(dir))) { |
| 915 | /* We only care about compatible props or subnodes. */ |
| 916 | if (entry->d_name[0] == '.' || !((entry->d_type & DT_DIR) || |
| 917 | !strcmp(entry->d_name, "compatible"))) |
| 918 | continue; |
| 919 | |
| 920 | /* Assemble the file name (on the stack, for speed). */ |
| 921 | size_t plen = strlen(parent); |
| 922 | char *name = alloca(plen + strlen(entry->d_name) + 2); |
| 923 | |
| 924 | strcpy(name, parent); |
| 925 | name[plen] = '/'; |
| 926 | strcpy(name + plen + 1, entry->d_name); |
| 927 | |
| 928 | /* If it's a subnode, recurse. */ |
| 929 | if (entry->d_type & DT_DIR) { |
| 930 | ret = dt_find_compat(name, compat, addr_cells_ptr, |
| 931 | size_cells_ptr); |
| 932 | |
| 933 | /* There is only one matching node to find, abort. */ |
| 934 | if (ret) { |
| 935 | /* Gather cells values on the way up. */ |
| 936 | dt_update_cells(parent, addr_cells_ptr, |
| 937 | size_cells_ptr); |
| 938 | break; |
| 939 | } |
| 940 | continue; |
| 941 | } |
| 942 | |
| 943 | /* If it's a compatible string, see if it's the right one. */ |
| 944 | int fd = open(name, O_RDONLY); |
| 945 | int clen = strlen(compat); |
| 946 | char *buffer = alloca(clen + 1); |
| 947 | |
| 948 | if (fd < 0) { |
| 949 | perror(name); |
| 950 | continue; |
| 951 | } |
| 952 | |
| 953 | if (read(fd, buffer, clen + 1) < 0) { |
| 954 | perror(name); |
| 955 | close(fd); |
| 956 | continue; |
| 957 | } |
| 958 | close(fd); |
| 959 | |
| 960 | if (!strcmp(compat, buffer)) { |
| 961 | /* Initialize these to "unset" for the way up. */ |
| 962 | *addr_cells_ptr = *size_cells_ptr = -1; |
| 963 | |
| 964 | /* Can't leave string on the stack or we'll lose it! */ |
| 965 | ret = strdup(parent); |
| 966 | break; |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | closedir(dir); |
| 971 | return ret; |
| 972 | } |
| 973 | #endif /* __arm__ */ |
| 974 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 975 | int main(int argc, char** argv) |
| 976 | { |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 977 | int print_defaults = 1; |
| 978 | int print_console = 0; |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 979 | int print_coverage = 0; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 980 | int print_list = 0; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 981 | int print_hexdump = 0; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 982 | int print_timestamps = 0; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 983 | |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 984 | int opt, option_index = 0; |
| 985 | static struct option long_options[] = { |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 986 | {"console", 0, 0, 'c'}, |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 987 | {"coverage", 0, 0, 'C'}, |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 988 | {"list", 0, 0, 'l'}, |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 989 | {"timestamps", 0, 0, 't'}, |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 990 | {"hexdump", 0, 0, 'x'}, |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 991 | {"verbose", 0, 0, 'V'}, |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 992 | {"version", 0, 0, 'v'}, |
| 993 | {"help", 0, 0, 'h'}, |
| 994 | {0, 0, 0, 0} |
| 995 | }; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 996 | while ((opt = getopt_long(argc, argv, "cCltxVvh?", |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 997 | long_options, &option_index)) != EOF) { |
| 998 | switch (opt) { |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 999 | case 'c': |
| 1000 | print_console = 1; |
| 1001 | print_defaults = 0; |
| 1002 | break; |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 1003 | case 'C': |
| 1004 | print_coverage = 1; |
| 1005 | print_defaults = 0; |
| 1006 | break; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 1007 | case 'l': |
| 1008 | print_list = 1; |
| 1009 | print_defaults = 0; |
| 1010 | break; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 1011 | case 'x': |
| 1012 | print_hexdump = 1; |
| 1013 | print_defaults = 0; |
| 1014 | break; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 1015 | case 't': |
| 1016 | print_timestamps = 1; |
| 1017 | print_defaults = 0; |
| 1018 | break; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 1019 | case 'V': |
| 1020 | verbose = 1; |
| 1021 | break; |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 1022 | case 'v': |
| 1023 | print_version(); |
| 1024 | exit(0); |
| 1025 | break; |
| 1026 | case 'h': |
| 1027 | case '?': |
| 1028 | default: |
| 1029 | print_usage(argv[0]); |
| 1030 | exit(0); |
| 1031 | break; |
| 1032 | } |
| 1033 | } |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1034 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1035 | mem_fd = open("/dev/mem", O_RDONLY, 0); |
| 1036 | if (mem_fd < 0) { |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 1037 | fprintf(stderr, "Failed to gain memory access: %s\n", |
| 1038 | strerror(errno)); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1039 | return 1; |
| 1040 | } |
| 1041 | |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1042 | #ifdef __arm__ |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1043 | int addr_cells, size_cells; |
| 1044 | char *coreboot_node = dt_find_compat("/proc/device-tree", "coreboot", |
| 1045 | &addr_cells, &size_cells); |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1046 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1047 | if (!coreboot_node) { |
| 1048 | fprintf(stderr, "Could not find 'coreboot' compatible node!\n"); |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1049 | return 1; |
| 1050 | } |
| 1051 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1052 | if (addr_cells < 0) { |
| 1053 | fprintf(stderr, "Warning: no #address-cells node in tree!\n"); |
| 1054 | addr_cells = 1; |
| 1055 | } |
| 1056 | |
| 1057 | int nlen = strlen(coreboot_node); |
| 1058 | char *reg = alloca(nlen + sizeof("/reg")); |
| 1059 | |
| 1060 | strcpy(reg, coreboot_node); |
| 1061 | strcpy(reg + nlen, "/reg"); |
| 1062 | free(coreboot_node); |
| 1063 | |
| 1064 | int fd = open(reg, O_RDONLY); |
| 1065 | if (fd < 0) { |
| 1066 | perror(reg); |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1067 | return 1; |
| 1068 | } |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1069 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1070 | int i; |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 1071 | size_t size_to_read = addr_cells * 4 + size_cells * 4; |
| 1072 | u8 *dtbuffer = alloca(size_to_read); |
| 1073 | if (read(fd, dtbuffer, size_to_read) < 0) { |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1074 | perror(reg); |
| 1075 | return 1; |
| 1076 | } |
| 1077 | close(fd); |
| 1078 | |
| 1079 | /* No variable-length byte swap function anywhere in C... how sad. */ |
| 1080 | u64 baseaddr = 0; |
| 1081 | for (i = 0; i < addr_cells * 4; i++) { |
| 1082 | baseaddr <<= 8; |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 1083 | baseaddr |= *dtbuffer; |
| 1084 | dtbuffer++; |
| 1085 | } |
| 1086 | u64 cb_table_size = 0; |
| 1087 | for (i = 0; i < size_cells * 4; i++) { |
| 1088 | cb_table_size <<= 8; |
| 1089 | cb_table_size |= *dtbuffer; |
| 1090 | dtbuffer++; |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 1093 | parse_cbtable(baseaddr, cb_table_size); |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1094 | #else |
| 1095 | int j; |
| 1096 | static const int possible_base_addresses[] = { 0, 0xf0000 }; |
| 1097 | |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 1098 | /* Find and parse coreboot table */ |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1099 | for (j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) { |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 1100 | if (parse_cbtable(possible_base_addresses[j], MAP_BYTES)) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1101 | break; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1102 | } |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1103 | #endif |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1104 | |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 1105 | if (print_console) |
| 1106 | dump_console(); |
| 1107 | |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 1108 | if (print_coverage) |
| 1109 | dump_coverage(); |
| 1110 | |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 1111 | if (print_list) |
| 1112 | dump_cbmem_toc(); |
| 1113 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 1114 | if (print_hexdump) |
| 1115 | dump_cbmem_hex(); |
| 1116 | |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 1117 | if (print_defaults || print_timestamps) |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 1118 | dump_timestamps(); |
| 1119 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1120 | close(mem_fd); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1121 | return 0; |
| 1122 | } |