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" }, |
| 416 | { TS_START_KERNEL, "start kernel" } |
| 417 | }; |
| 418 | |
| 419 | void timestamp_print_entry(uint32_t id, uint64_t stamp, uint64_t prev_stamp) |
| 420 | { |
| 421 | int i; |
| 422 | const char *name; |
| 423 | |
| 424 | name = "<unknown>"; |
| 425 | for (i = 0; i < ARRAY_SIZE(timestamp_ids); i++) { |
| 426 | if (timestamp_ids[i].id == id) { |
| 427 | name = timestamp_ids[i].name; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | printf("%4d:", id); |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 433 | printf("%-50s", name); |
| 434 | print_norm(arch_convert_raw_ts_entry(stamp)); |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 435 | if (prev_stamp) { |
| 436 | printf(" ("); |
Julius Werner | a7d9244 | 2014-12-02 20:51:19 -0800 | [diff] [blame] | 437 | print_norm(arch_convert_raw_ts_entry(stamp - prev_stamp)); |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 438 | printf(")"); |
| 439 | } |
| 440 | printf("\n"); |
| 441 | } |
| 442 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 443 | /* dump the timestamp table */ |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 444 | static void dump_timestamps(void) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 445 | { |
| 446 | int i; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 447 | struct timestamp_table *tst_p; |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 448 | size_t size; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 449 | |
| 450 | if (timestamps.tag != LB_TAG_TIMESTAMPS) { |
| 451 | fprintf(stderr, "No timestamps found in coreboot table.\n"); |
| 452 | return; |
| 453 | } |
| 454 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 455 | size = sizeof(*tst_p); |
| 456 | tst_p = map_memory_size((unsigned long)timestamps.cbmem_addr, size); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 457 | |
| 458 | printf("%d entries total:\n\n", tst_p->num_entries); |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 459 | size += tst_p->num_entries * sizeof(tst_p->entries[0]); |
| 460 | |
| 461 | unmap_memory(); |
| 462 | tst_p = map_memory_size((unsigned long)timestamps.cbmem_addr, size); |
| 463 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 464 | for (i = 0; i < tst_p->num_entries; i++) { |
| 465 | const struct timestamp_entry *tse_p = tst_p->entries + i; |
Stefan Reinauer | 0db924d | 2013-08-09 11:06:11 -0700 | [diff] [blame] | 466 | timestamp_print_entry(tse_p->entry_id, tse_p->entry_stamp, |
| 467 | i ? tse_p[-1].entry_stamp : 0); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 468 | } |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 469 | |
| 470 | unmap_memory(); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 473 | /* dump the cbmem console */ |
| 474 | static void dump_console(void) |
| 475 | { |
| 476 | void *console_p; |
| 477 | char *console_c; |
| 478 | uint32_t size; |
Vladimir Serbinenko | f4a0d01 | 2013-03-30 12:15:12 +0100 | [diff] [blame] | 479 | uint32_t cursor; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 480 | |
| 481 | if (console.tag != LB_TAG_CBMEM_CONSOLE) { |
| 482 | fprintf(stderr, "No console found in coreboot table.\n"); |
| 483 | return; |
| 484 | } |
| 485 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 486 | console_p = map_memory_size((unsigned long)console.cbmem_addr, |
| 487 | 2 * sizeof(uint32_t)); |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 488 | /* The in-memory format of the console area is: |
| 489 | * u32 size |
| 490 | * u32 cursor |
| 491 | * char console[size] |
| 492 | * Hence we have to add 8 to get to the actual console string. |
| 493 | */ |
Gabe Black | 06b13a3 | 2013-08-09 00:40:06 -0700 | [diff] [blame] | 494 | size = ((uint32_t *)console_p)[0]; |
| 495 | cursor = ((uint32_t *)console_p)[1]; |
Vladimir Serbinenko | f4a0d01 | 2013-03-30 12:15:12 +0100 | [diff] [blame] | 496 | /* Cursor continues to go on even after no more data fits in |
| 497 | * the buffer but the data is dropped in this case. |
| 498 | */ |
| 499 | if (size > cursor) |
| 500 | size = cursor; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 501 | console_c = malloc(size + 1); |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 502 | unmap_memory(); |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 503 | if (!console_c) { |
| 504 | fprintf(stderr, "Not enough memory for console.\n"); |
| 505 | exit(1); |
| 506 | } |
| 507 | |
Aaron Durbin | ab180d8 | 2014-03-31 11:59:58 -0500 | [diff] [blame] | 508 | console_p = map_memory_size((unsigned long)console.cbmem_addr, |
| 509 | size + sizeof(size) + sizeof(cursor)); |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 510 | memcpy(console_c, console_p + 8, size); |
| 511 | console_c[size] = 0; |
Gabe Black | 06b13a3 | 2013-08-09 00:40:06 -0700 | [diff] [blame] | 512 | console_c[cursor] = 0; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 513 | |
Vladimir Serbinenko | f4a0d01 | 2013-03-30 12:15:12 +0100 | [diff] [blame] | 514 | printf("%s\n", console_c); |
| 515 | if (size < cursor) |
| 516 | printf("%d %s lost\n", cursor - size, |
| 517 | (cursor - size) == 1 ? "byte":"bytes"); |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 518 | |
| 519 | free(console_c); |
| 520 | |
| 521 | unmap_memory(); |
| 522 | } |
| 523 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 524 | static void hexdump(unsigned long memory, int length) |
| 525 | { |
| 526 | int i; |
| 527 | uint8_t *m; |
| 528 | int all_zero = 0; |
| 529 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 530 | m = map_memory_size((intptr_t)memory, length); |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 531 | |
| 532 | if (length > MAP_BYTES) { |
| 533 | printf("Truncating hex dump from %d to %d bytes\n\n", |
| 534 | length, MAP_BYTES); |
| 535 | length = MAP_BYTES; |
| 536 | } |
| 537 | |
| 538 | for (i = 0; i < length; i += 16) { |
| 539 | int j; |
| 540 | |
| 541 | all_zero++; |
| 542 | for (j = 0; j < 16; j++) { |
| 543 | if(m[i+j] != 0) { |
| 544 | all_zero = 0; |
| 545 | break; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if (all_zero < 2) { |
| 550 | printf("%08lx:", memory + i); |
| 551 | for (j = 0; j < 16; j++) |
| 552 | printf(" %02x", m[i+j]); |
| 553 | printf(" "); |
| 554 | for (j = 0; j < 16; j++) |
| 555 | printf("%c", isprint(m[i+j]) ? m[i+j] : '.'); |
| 556 | printf("\n"); |
| 557 | } else if (all_zero == 2) { |
| 558 | printf("...\n"); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | unmap_memory(); |
| 563 | } |
| 564 | |
| 565 | static void dump_cbmem_hex(void) |
| 566 | { |
| 567 | if (cbmem.type != LB_MEM_TABLE) { |
| 568 | fprintf(stderr, "No coreboot CBMEM area found!\n"); |
| 569 | return; |
| 570 | } |
| 571 | |
| 572 | hexdump(unpack_lb64(cbmem.start), unpack_lb64(cbmem.size)); |
| 573 | } |
| 574 | |
| 575 | /* The root region is at least DYN_CBMEM_ALIGN_SIZE . */ |
| 576 | #define DYN_CBMEM_ALIGN_SIZE (4096) |
| 577 | #define ROOT_MIN_SIZE DYN_CBMEM_ALIGN_SIZE |
| 578 | #define CBMEM_POINTER_MAGIC 0xc0389479 |
| 579 | #define CBMEM_ENTRY_MAGIC ~(CBMEM_POINTER_MAGIC) |
| 580 | |
| 581 | struct cbmem_root_pointer { |
| 582 | uint32_t magic; |
| 583 | uint32_t root; |
| 584 | } __attribute__((packed)); |
| 585 | |
| 586 | struct dynamic_cbmem_entry { |
| 587 | uint32_t magic; |
| 588 | uint32_t start; |
| 589 | uint32_t size; |
| 590 | uint32_t id; |
| 591 | } __attribute__((packed)); |
| 592 | |
| 593 | struct cbmem_root { |
| 594 | uint32_t max_entries; |
| 595 | uint32_t num_entries; |
| 596 | uint32_t locked; |
| 597 | uint32_t size; |
| 598 | struct dynamic_cbmem_entry entries[0]; |
| 599 | } __attribute__((packed)); |
| 600 | |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 601 | #define CBMEM_MAGIC 0x434f5245 |
| 602 | #define MAX_CBMEM_ENTRIES 16 |
| 603 | |
| 604 | struct cbmem_entry { |
| 605 | uint32_t magic; |
| 606 | uint32_t id; |
| 607 | uint64_t base; |
| 608 | uint64_t size; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 609 | } __attribute__((packed)); |
| 610 | |
Aaron Durbin | 0dff57d | 2015-03-05 21:18:33 -0600 | [diff] [blame] | 611 | struct cbmem_id_to_name { |
| 612 | uint32_t id; |
| 613 | const char *name; |
| 614 | }; |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 615 | 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] | 616 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 617 | void cbmem_print_entry(int n, uint32_t id, uint64_t base, uint64_t size) |
| 618 | { |
| 619 | int i; |
| 620 | const char *name; |
| 621 | |
| 622 | name = NULL; |
| 623 | for (i = 0; i < ARRAY_SIZE(cbmem_ids); i++) { |
| 624 | if (cbmem_ids[i].id == id) { |
| 625 | name = cbmem_ids[i].name; |
| 626 | break; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | printf("%2d. ", n); |
| 631 | if (name == NULL) |
| 632 | printf("%08x ", id); |
| 633 | else |
| 634 | printf("%s", name); |
| 635 | printf(" %08" PRIx64 " ", base); |
| 636 | printf(" %08" PRIx64 "\n", size); |
| 637 | } |
| 638 | |
| 639 | static void dump_static_cbmem_toc(struct cbmem_entry *entries) |
| 640 | { |
| 641 | int i; |
| 642 | |
| 643 | printf("CBMEM table of contents:\n"); |
| 644 | printf(" ID START LENGTH\n"); |
| 645 | |
| 646 | for (i=0; i<MAX_CBMEM_ENTRIES; i++) { |
| 647 | if (entries[i].magic != CBMEM_MAGIC) |
| 648 | break; |
| 649 | cbmem_print_entry(i, entries[i].id, |
| 650 | entries[i].base, entries[i].size); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | static void dump_dynamic_cbmem_toc(struct cbmem_root *root) |
| 655 | { |
| 656 | int i; |
| 657 | debug("CBMEM: max_entries=%d num_entries=%d locked=0x%x, size=%d\n\n", |
| 658 | root->max_entries, root->num_entries, root->locked, root->size); |
| 659 | |
| 660 | printf("CBMEM table of contents:\n"); |
| 661 | printf(" ID START LENGTH\n"); |
| 662 | |
| 663 | for (i = 0; i < root->num_entries; i++) { |
| 664 | if(root->entries[i].magic != CBMEM_ENTRY_MAGIC) |
| 665 | break; |
| 666 | cbmem_print_entry(i, root->entries[i].id, |
| 667 | root->entries[i].start, root->entries[i].size); |
| 668 | } |
| 669 | } |
| 670 | |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 671 | static void dump_cbmem_toc(void) |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 672 | { |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 673 | uint64_t start; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 674 | void *cbmem_area; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 675 | struct cbmem_entry *entries; |
| 676 | |
| 677 | if (cbmem.type != LB_MEM_TABLE) { |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 678 | fprintf(stderr, "No coreboot CBMEM area found!\n"); |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 679 | return; |
| 680 | } |
| 681 | |
| 682 | start = unpack_lb64(cbmem.start); |
| 683 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 684 | cbmem_area = map_memory_size(start, unpack_lb64(cbmem.size)); |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 685 | entries = (struct cbmem_entry *)cbmem_area; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 686 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 687 | if (entries[0].magic == CBMEM_MAGIC) { |
| 688 | dump_static_cbmem_toc(entries); |
| 689 | } else { |
| 690 | uint64_t rootptr; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 691 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 692 | rootptr = unpack_lb64(cbmem.start) + unpack_lb64(cbmem.size); |
| 693 | rootptr &= ~(DYN_CBMEM_ALIGN_SIZE - 1); |
| 694 | rootptr -= sizeof(struct cbmem_root_pointer); |
| 695 | unmap_memory(); |
| 696 | struct cbmem_root_pointer *r = |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 697 | map_memory_size(rootptr, sizeof(*r)); |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 698 | if (r->magic == CBMEM_POINTER_MAGIC) { |
| 699 | struct cbmem_root *root; |
| 700 | uint64_t rootaddr = r->root; |
| 701 | unmap_memory(); |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 702 | root = map_memory_size(rootaddr, ROOT_MIN_SIZE); |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 703 | dump_dynamic_cbmem_toc(root); |
| 704 | } else |
| 705 | fprintf(stderr, "No valid coreboot CBMEM root pointer found.\n"); |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 706 | } |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 707 | |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 708 | unmap_memory(); |
| 709 | } |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 710 | |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 711 | #define COVERAGE_MAGIC 0x584d4153 |
| 712 | struct file { |
| 713 | uint32_t magic; |
| 714 | uint32_t next; |
| 715 | uint32_t filename; |
| 716 | uint32_t data; |
| 717 | int offset; |
| 718 | int len; |
| 719 | }; |
| 720 | |
| 721 | static int mkpath(char *path, mode_t mode) |
| 722 | { |
| 723 | assert (path && *path); |
| 724 | char *p; |
| 725 | for (p = strchr(path+1, '/'); p; p = strchr(p + 1, '/')) { |
| 726 | *p = '\0'; |
| 727 | if (mkdir(path, mode) == -1) { |
| 728 | if (errno != EEXIST) { |
| 729 | *p = '/'; |
| 730 | return -1; |
| 731 | } |
| 732 | } |
| 733 | *p = '/'; |
| 734 | } |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static void dump_coverage(void) |
| 739 | { |
| 740 | int i, found = 0; |
| 741 | uint64_t start; |
| 742 | struct cbmem_entry *entries; |
| 743 | void *coverage; |
| 744 | unsigned long phys_offset; |
| 745 | #define phys_to_virt(x) ((void *)(unsigned long)(x) + phys_offset) |
| 746 | |
| 747 | if (cbmem.type != LB_MEM_TABLE) { |
| 748 | fprintf(stderr, "No coreboot table area found!\n"); |
| 749 | return; |
| 750 | } |
| 751 | |
| 752 | start = unpack_lb64(cbmem.start); |
| 753 | |
| 754 | entries = (struct cbmem_entry *)map_memory(start); |
| 755 | |
| 756 | for (i=0; i<MAX_CBMEM_ENTRIES; i++) { |
| 757 | if (entries[i].magic != CBMEM_MAGIC) |
| 758 | break; |
| 759 | if (entries[i].id == CBMEM_ID_COVERAGE) { |
| 760 | found = 1; |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | if (!found) { |
| 766 | unmap_memory(); |
| 767 | fprintf(stderr, "No coverage information found in" |
| 768 | " CBMEM area.\n"); |
| 769 | return; |
| 770 | } |
| 771 | |
| 772 | start = entries[i].base; |
| 773 | unmap_memory(); |
| 774 | /* Map coverage area */ |
| 775 | coverage = map_memory(start); |
| 776 | phys_offset = (unsigned long)coverage - (unsigned long)start; |
| 777 | |
| 778 | printf("Dumping coverage data...\n"); |
| 779 | |
| 780 | struct file *file = (struct file *)coverage; |
| 781 | while (file && file->magic == COVERAGE_MAGIC) { |
| 782 | FILE *f; |
| 783 | char *filename; |
| 784 | |
| 785 | debug(" -> %s\n", (char *)phys_to_virt(file->filename)); |
| 786 | filename = strdup((char *)phys_to_virt(file->filename)); |
| 787 | if (mkpath(filename, 0755) == -1) { |
| 788 | perror("Directory for coverage data could " |
| 789 | "not be created"); |
| 790 | exit(1); |
| 791 | } |
| 792 | f = fopen(filename, "wb"); |
| 793 | if (!f) { |
| 794 | printf("Could not open %s: %s\n", |
| 795 | filename, strerror(errno)); |
| 796 | exit(1); |
| 797 | } |
| 798 | if (fwrite((void *)phys_to_virt(file->data), |
| 799 | file->len, 1, f) != 1) { |
| 800 | printf("Could not write to %s: %s\n", |
| 801 | filename, strerror(errno)); |
| 802 | exit(1); |
| 803 | } |
| 804 | fclose(f); |
| 805 | free(filename); |
| 806 | |
| 807 | if (file->next) |
| 808 | file = (struct file *)phys_to_virt(file->next); |
| 809 | else |
| 810 | file = NULL; |
| 811 | } |
| 812 | unmap_memory(); |
| 813 | } |
| 814 | |
| 815 | static void print_version(void) |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 816 | { |
| 817 | printf("cbmem v%s -- ", CBMEM_VERSION); |
| 818 | printf("Copyright (C) 2012 The ChromiumOS Authors. All rights reserved.\n\n"); |
| 819 | printf( |
| 820 | "This program is free software: you can redistribute it and/or modify\n" |
| 821 | "it under the terms of the GNU General Public License as published by\n" |
| 822 | "the Free Software Foundation, version 2 of the License.\n\n" |
| 823 | "This program is distributed in the hope that it will be useful,\n" |
| 824 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
| 825 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" |
| 826 | "GNU General Public License for more details.\n\n" |
| 827 | "You should have received a copy of the GNU General Public License\n" |
| 828 | "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n"); |
| 829 | } |
| 830 | |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 831 | static void print_usage(const char *name) |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 832 | { |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 833 | printf("usage: %s [-cCltxVvh?]\n", name); |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 834 | printf("\n" |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 835 | " -c | --console: print cbmem console\n" |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 836 | " -C | --coverage: dump coverage information\n" |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 837 | " -l | --list: print cbmem table of contents\n" |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 838 | " -x | --hexdump: print hexdump of cbmem area\n" |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 839 | " -t | --timestamps: print timestamp information\n" |
| 840 | " -V | --verbose: verbose (debugging) output\n" |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 841 | " -v | --version: print the version\n" |
| 842 | " -h | --help: print this help\n" |
| 843 | "\n"); |
| 844 | exit(1); |
| 845 | } |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 846 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 847 | #ifdef __arm__ |
| 848 | static void dt_update_cells(const char *name, int *addr_cells_ptr, |
| 849 | int *size_cells_ptr) |
| 850 | { |
| 851 | if (*addr_cells_ptr >= 0 && *size_cells_ptr >= 0) |
| 852 | return; |
| 853 | |
| 854 | int buffer; |
| 855 | size_t nlen = strlen(name); |
| 856 | char *prop = alloca(nlen + sizeof("/#address-cells")); |
| 857 | strcpy(prop, name); |
| 858 | |
| 859 | if (*addr_cells_ptr < 0) { |
| 860 | strcpy(prop + nlen, "/#address-cells"); |
| 861 | int fd = open(prop, O_RDONLY); |
| 862 | if (fd < 0 && errno != ENOENT) { |
| 863 | perror(prop); |
| 864 | } else if (fd >= 0) { |
| 865 | if (read(fd, &buffer, sizeof(int)) < 0) |
| 866 | perror(prop); |
| 867 | else |
| 868 | *addr_cells_ptr = ntohl(buffer); |
| 869 | close(fd); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | if (*size_cells_ptr < 0) { |
| 874 | strcpy(prop + nlen, "/#size-cells"); |
| 875 | int fd = open(prop, O_RDONLY); |
| 876 | if (fd < 0 && errno != ENOENT) { |
| 877 | perror(prop); |
| 878 | } else if (fd >= 0) { |
| 879 | if (read(fd, &buffer, sizeof(int)) < 0) |
| 880 | perror(prop); |
| 881 | else |
| 882 | *size_cells_ptr = ntohl(buffer); |
| 883 | close(fd); |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | static char *dt_find_compat(const char *parent, const char *compat, |
| 889 | int *addr_cells_ptr, int *size_cells_ptr) |
| 890 | { |
| 891 | char *ret = NULL; |
| 892 | struct dirent *entry; |
| 893 | DIR *dir; |
| 894 | |
| 895 | if (!(dir = opendir(parent))) { |
| 896 | perror(parent); |
| 897 | return NULL; |
| 898 | } |
| 899 | |
| 900 | /* Loop through all files in the directory (DT node). */ |
| 901 | while ((entry = readdir(dir))) { |
| 902 | /* We only care about compatible props or subnodes. */ |
| 903 | if (entry->d_name[0] == '.' || !((entry->d_type & DT_DIR) || |
| 904 | !strcmp(entry->d_name, "compatible"))) |
| 905 | continue; |
| 906 | |
| 907 | /* Assemble the file name (on the stack, for speed). */ |
| 908 | size_t plen = strlen(parent); |
| 909 | char *name = alloca(plen + strlen(entry->d_name) + 2); |
| 910 | |
| 911 | strcpy(name, parent); |
| 912 | name[plen] = '/'; |
| 913 | strcpy(name + plen + 1, entry->d_name); |
| 914 | |
| 915 | /* If it's a subnode, recurse. */ |
| 916 | if (entry->d_type & DT_DIR) { |
| 917 | ret = dt_find_compat(name, compat, addr_cells_ptr, |
| 918 | size_cells_ptr); |
| 919 | |
| 920 | /* There is only one matching node to find, abort. */ |
| 921 | if (ret) { |
| 922 | /* Gather cells values on the way up. */ |
| 923 | dt_update_cells(parent, addr_cells_ptr, |
| 924 | size_cells_ptr); |
| 925 | break; |
| 926 | } |
| 927 | continue; |
| 928 | } |
| 929 | |
| 930 | /* If it's a compatible string, see if it's the right one. */ |
| 931 | int fd = open(name, O_RDONLY); |
| 932 | int clen = strlen(compat); |
| 933 | char *buffer = alloca(clen + 1); |
| 934 | |
| 935 | if (fd < 0) { |
| 936 | perror(name); |
| 937 | continue; |
| 938 | } |
| 939 | |
| 940 | if (read(fd, buffer, clen + 1) < 0) { |
| 941 | perror(name); |
| 942 | close(fd); |
| 943 | continue; |
| 944 | } |
| 945 | close(fd); |
| 946 | |
| 947 | if (!strcmp(compat, buffer)) { |
| 948 | /* Initialize these to "unset" for the way up. */ |
| 949 | *addr_cells_ptr = *size_cells_ptr = -1; |
| 950 | |
| 951 | /* Can't leave string on the stack or we'll lose it! */ |
| 952 | ret = strdup(parent); |
| 953 | break; |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | closedir(dir); |
| 958 | return ret; |
| 959 | } |
| 960 | #endif /* __arm__ */ |
| 961 | |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 962 | int main(int argc, char** argv) |
| 963 | { |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 964 | int print_defaults = 1; |
| 965 | int print_console = 0; |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 966 | int print_coverage = 0; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 967 | int print_list = 0; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 968 | int print_hexdump = 0; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 969 | int print_timestamps = 0; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 970 | |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 971 | int opt, option_index = 0; |
| 972 | static struct option long_options[] = { |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 973 | {"console", 0, 0, 'c'}, |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 974 | {"coverage", 0, 0, 'C'}, |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 975 | {"list", 0, 0, 'l'}, |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 976 | {"timestamps", 0, 0, 't'}, |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 977 | {"hexdump", 0, 0, 'x'}, |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 978 | {"verbose", 0, 0, 'V'}, |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 979 | {"version", 0, 0, 'v'}, |
| 980 | {"help", 0, 0, 'h'}, |
| 981 | {0, 0, 0, 0} |
| 982 | }; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 983 | while ((opt = getopt_long(argc, argv, "cCltxVvh?", |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 984 | long_options, &option_index)) != EOF) { |
| 985 | switch (opt) { |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 986 | case 'c': |
| 987 | print_console = 1; |
| 988 | print_defaults = 0; |
| 989 | break; |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 990 | case 'C': |
| 991 | print_coverage = 1; |
| 992 | print_defaults = 0; |
| 993 | break; |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 994 | case 'l': |
| 995 | print_list = 1; |
| 996 | print_defaults = 0; |
| 997 | break; |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 998 | case 'x': |
| 999 | print_hexdump = 1; |
| 1000 | print_defaults = 0; |
| 1001 | break; |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 1002 | case 't': |
| 1003 | print_timestamps = 1; |
| 1004 | print_defaults = 0; |
| 1005 | break; |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 1006 | case 'V': |
| 1007 | verbose = 1; |
| 1008 | break; |
Stefan Reinauer | 1e0e556 | 2013-01-02 15:43:56 -0800 | [diff] [blame] | 1009 | case 'v': |
| 1010 | print_version(); |
| 1011 | exit(0); |
| 1012 | break; |
| 1013 | case 'h': |
| 1014 | case '?': |
| 1015 | default: |
| 1016 | print_usage(argv[0]); |
| 1017 | exit(0); |
| 1018 | break; |
| 1019 | } |
| 1020 | } |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1021 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1022 | mem_fd = open("/dev/mem", O_RDONLY, 0); |
| 1023 | if (mem_fd < 0) { |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 1024 | fprintf(stderr, "Failed to gain memory access: %s\n", |
| 1025 | strerror(errno)); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1026 | return 1; |
| 1027 | } |
| 1028 | |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1029 | #ifdef __arm__ |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1030 | int addr_cells, size_cells; |
| 1031 | char *coreboot_node = dt_find_compat("/proc/device-tree", "coreboot", |
| 1032 | &addr_cells, &size_cells); |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1033 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1034 | if (!coreboot_node) { |
| 1035 | fprintf(stderr, "Could not find 'coreboot' compatible node!\n"); |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1036 | return 1; |
| 1037 | } |
| 1038 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1039 | if (addr_cells < 0) { |
| 1040 | fprintf(stderr, "Warning: no #address-cells node in tree!\n"); |
| 1041 | addr_cells = 1; |
| 1042 | } |
| 1043 | |
| 1044 | int nlen = strlen(coreboot_node); |
| 1045 | char *reg = alloca(nlen + sizeof("/reg")); |
| 1046 | |
| 1047 | strcpy(reg, coreboot_node); |
| 1048 | strcpy(reg + nlen, "/reg"); |
| 1049 | free(coreboot_node); |
| 1050 | |
| 1051 | int fd = open(reg, O_RDONLY); |
| 1052 | if (fd < 0) { |
| 1053 | perror(reg); |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1054 | return 1; |
| 1055 | } |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1056 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1057 | int i; |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 1058 | size_t size_to_read = addr_cells * 4 + size_cells * 4; |
| 1059 | u8 *dtbuffer = alloca(size_to_read); |
| 1060 | if (read(fd, dtbuffer, size_to_read) < 0) { |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1061 | perror(reg); |
| 1062 | return 1; |
| 1063 | } |
| 1064 | close(fd); |
| 1065 | |
| 1066 | /* No variable-length byte swap function anywhere in C... how sad. */ |
| 1067 | u64 baseaddr = 0; |
| 1068 | for (i = 0; i < addr_cells * 4; i++) { |
| 1069 | baseaddr <<= 8; |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 1070 | baseaddr |= *dtbuffer; |
| 1071 | dtbuffer++; |
| 1072 | } |
| 1073 | u64 cb_table_size = 0; |
| 1074 | for (i = 0; i < size_cells * 4; i++) { |
| 1075 | cb_table_size <<= 8; |
| 1076 | cb_table_size |= *dtbuffer; |
| 1077 | dtbuffer++; |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 1080 | parse_cbtable(baseaddr, cb_table_size); |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1081 | #else |
| 1082 | int j; |
| 1083 | static const int possible_base_addresses[] = { 0, 0xf0000 }; |
| 1084 | |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 1085 | /* Find and parse coreboot table */ |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1086 | for (j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) { |
Aaron Durbin | b58f9e3 | 2014-10-07 14:56:35 -0500 | [diff] [blame] | 1087 | if (parse_cbtable(possible_base_addresses[j], MAP_BYTES)) |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1088 | break; |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1089 | } |
Stefan Reinauer | 7f68150 | 2013-06-19 15:39:09 -0700 | [diff] [blame] | 1090 | #endif |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1091 | |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 1092 | if (print_console) |
| 1093 | dump_console(); |
| 1094 | |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 1095 | if (print_coverage) |
| 1096 | dump_coverage(); |
| 1097 | |
Stefan Reinauer | c019907 | 2013-01-07 16:26:10 -0800 | [diff] [blame] | 1098 | if (print_list) |
| 1099 | dump_cbmem_toc(); |
| 1100 | |
Stefan Reinauer | a9c8361 | 2013-07-16 17:47:35 -0700 | [diff] [blame] | 1101 | if (print_hexdump) |
| 1102 | dump_cbmem_hex(); |
| 1103 | |
Stefan Reinauer | 19f8756 | 2013-01-07 13:37:12 -0800 | [diff] [blame] | 1104 | if (print_defaults || print_timestamps) |
Stefan Reinauer | 05cbce6 | 2013-01-03 14:30:33 -0800 | [diff] [blame] | 1105 | dump_timestamps(); |
| 1106 | |
Julius Werner | 337de4c | 2014-06-16 23:02:03 -0700 | [diff] [blame] | 1107 | close(mem_fd); |
Vadim Bendebury | 6d18fd0 | 2012-09-27 19:24:07 -0700 | [diff] [blame] | 1108 | return 0; |
| 1109 | } |