blob: 34e79d368d0bb1b705026b83468db4c1d4b3d42a [file] [log] [blame]
Patrick Georgi7333a112020-05-08 20:48:04 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07002
Nico Huber8e4bb9282013-05-26 18:17:54 +02003#include <inttypes.h>
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07004#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08007#include <unistd.h>
8#include <getopt.h>
Julius Werner337de4c2014-06-16 23:02:03 -07009#include <dirent.h>
Stefan Reinauer05cbce62013-01-03 14:30:33 -080010#include <errno.h>
11#include <fcntl.h>
Stefan Reinauera9c83612013-07-16 17:47:35 -070012#include <ctype.h>
Stefan Reinauer7f681502013-06-19 15:39:09 -070013#include <arpa/inet.h>
Stefan Reinauer05cbce62013-01-03 14:30:33 -080014#include <sys/types.h>
15#include <sys/stat.h>
16#include <sys/mman.h>
Stefan Reinauerd37ab452012-12-18 16:23:28 -080017#include <libgen.h>
18#include <assert.h>
Julius Wernerb7b64a92017-04-28 16:31:46 -070019#include <regex.h>
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050020#include <commonlib/cbmem_id.h>
21#include <commonlib/timestamp_serialized.h>
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +020022#include <commonlib/tcpa_log_serialized.h>
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050023#include <commonlib/coreboot_tables.h>
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070024
Patrick Georgid00f1802015-07-13 16:53:50 +020025#ifdef __OpenBSD__
26#include <sys/param.h>
27#include <sys/sysctl.h>
28#endif
29
Stefan Reinauer05cbce62013-01-03 14:30:33 -080030#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070031
Julius Werner337de4c2014-06-16 23:02:03 -070032typedef uint8_t u8;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070033typedef uint16_t u16;
34typedef uint32_t u32;
35typedef uint64_t u64;
36
Aaron Durbin46300aa2017-09-26 16:22:38 -060037/* Return < 0 on error, 0 on success. */
38static int parse_cbtable(u64 address, size_t table_size);
39
40struct mapping {
41 void *virt;
42 size_t offset;
43 size_t virt_size;
44 unsigned long long phys;
45 size_t size;
46};
47
Stefan Reinauera9c83612013-07-16 17:47:35 -070048#define CBMEM_VERSION "1.1"
Stefan Reinauer1e0e5562013-01-02 15:43:56 -080049
Stefan Reinauer05cbce62013-01-03 14:30:33 -080050/* verbose output? */
51static int verbose = 0;
52#define debug(x...) if(verbose) printf(x)
53
54/* File handle used to access /dev/mem */
Julius Werner337de4c2014-06-16 23:02:03 -070055static int mem_fd;
Aaron Durbin46300aa2017-09-26 16:22:38 -060056static struct mapping lbtable_mapping;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070057
Aaron Durbin46300aa2017-09-26 16:22:38 -060058static void die(const char *msg)
59{
60 if (msg)
61 fputs(msg, stderr);
62 exit(1);
63}
64
65static unsigned long long system_page_size(void)
66{
67 static unsigned long long page_size;
68
69 if (!page_size)
70 page_size = getpagesize();
71
72 return page_size;
73}
74
75static inline size_t size_to_mib(size_t sz)
76{
77 return sz >> 20;
78}
79
80/* Return mapping of physical address requested. */
81static const void *mapping_virt(const struct mapping *mapping)
82{
83 const char *v = mapping->virt;
84
85 if (v == NULL)
86 return NULL;
87
88 return v + mapping->offset;
89}
90
Aaron Durbincf20c902017-09-28 17:52:59 -060091/* Returns virtual address on success, NULL on error. mapping is filled in. */
Aaron Durbin46300aa2017-09-26 16:22:38 -060092static const void *map_memory(struct mapping *mapping, unsigned long long phys,
93 size_t sz)
94{
95 void *v;
96 unsigned long long page_size;
97
98 page_size = system_page_size();
99
100 mapping->virt = NULL;
101 mapping->offset = phys % page_size;
102 mapping->virt_size = sz + mapping->offset;
103 mapping->size = sz;
104 mapping->phys = phys;
105
106 if (size_to_mib(mapping->virt_size) == 0) {
107 debug("Mapping %zuB of physical memory at 0x%llx (requested 0x%llx).\n",
108 mapping->virt_size, phys - mapping->offset, phys);
109 } else {
110 debug("Mapping %zuMB of physical memory at 0x%llx (requested 0x%llx).\n",
111 size_to_mib(mapping->virt_size), phys - mapping->offset,
112 phys);
113 }
114
115 v = mmap(NULL, mapping->virt_size, PROT_READ, MAP_SHARED, mem_fd,
116 phys - mapping->offset);
117
118 if (v == MAP_FAILED) {
119 debug("Mapping failed %zuB of physical memory at 0x%llx.\n",
120 mapping->virt_size, phys - mapping->offset);
121 return NULL;
122 }
123
124 mapping->virt = v;
125
126 if (mapping->offset != 0)
127 debug(" ... padding virtual address with 0x%zx bytes.\n",
128 mapping->offset);
129
130 return mapping_virt(mapping);
131}
132
133/* Returns 0 on success, < 0 on error. mapping is cleared if successful. */
134static int unmap_memory(struct mapping *mapping)
135{
136 if (mapping->virt == NULL)
137 return -1;
138
139 munmap(mapping->virt, mapping->virt_size);
140 mapping->virt = NULL;
141 mapping->offset = 0;
142 mapping->virt_size = 0;
143
144 return 0;
145}
146
147/* Return size of physical address mapping requested. */
148static size_t mapping_size(const struct mapping *mapping)
149{
150 if (mapping->virt == NULL)
151 return 0;
152
153 return mapping->size;
154}
Timothy Pearsondf699d52015-05-16 14:55:54 -0500155
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700156/*
Julius Werner127a79e2017-02-03 12:50:03 -0800157 * Some architectures map /dev/mem memory in a way that doesn't support
158 * unaligned accesses. Most normal libc memcpy()s aren't safe to use in this
159 * case, so build our own which makes sure to never do unaligned accesses on
160 * *src (*dest is fine since we never map /dev/mem for writing).
161 */
162static void *aligned_memcpy(void *dest, const void *src, size_t n)
163{
164 u8 *d = dest;
165 const volatile u8 *s = src; /* volatile to prevent optimization */
166
167 while ((uintptr_t)s & (sizeof(size_t) - 1)) {
168 if (n-- == 0)
169 return dest;
170 *d++ = *s++;
171 }
172
173 while (n >= sizeof(size_t)) {
174 *(size_t *)d = *(const volatile size_t *)s;
175 d += sizeof(size_t);
176 s += sizeof(size_t);
177 n -= sizeof(size_t);
178 }
179
180 while (n-- > 0)
181 *d++ = *s++;
182
183 return dest;
184}
185
186/*
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700187 * calculate ip checksum (16 bit quantities) on a passed in buffer. In case
188 * the buffer length is odd last byte is excluded from the calculation
189 */
190static u16 ipchcksum(const void *addr, unsigned size)
191{
192 const u16 *p = addr;
193 unsigned i, n = size / 2; /* don't expect odd sized blocks */
194 u32 sum = 0;
195
196 for (i = 0; i < n; i++)
197 sum += p[i];
198
199 sum = (sum >> 16) + (sum & 0xffff);
200 sum += (sum >> 16);
201 sum = ~sum & 0xffff;
202 return (u16) sum;
203}
204
Aaron Durbin09c0c112015-09-30 12:33:01 -0500205/* Find the first cbmem entry filling in the details. */
206static int find_cbmem_entry(uint32_t id, uint64_t *addr, size_t *size)
207{
Aaron Durbinf2a38222017-09-26 17:44:28 -0600208 const uint8_t *table;
Aaron Durbin09c0c112015-09-30 12:33:01 -0500209 size_t offset;
210 int ret = -1;
211
Aaron Durbin46300aa2017-09-26 16:22:38 -0600212 table = mapping_virt(&lbtable_mapping);
Aaron Durbin09c0c112015-09-30 12:33:01 -0500213
214 if (table == NULL)
215 return -1;
216
217 offset = 0;
218
Aaron Durbin46300aa2017-09-26 16:22:38 -0600219 while (offset < mapping_size(&lbtable_mapping)) {
Aaron Durbinf2a38222017-09-26 17:44:28 -0600220 const struct lb_record *lbr;
221 const struct lb_cbmem_entry *lbe;
Aaron Durbin09c0c112015-09-30 12:33:01 -0500222
Aaron Durbinf2a38222017-09-26 17:44:28 -0600223 lbr = (const void *)(table + offset);
Aaron Durbin09c0c112015-09-30 12:33:01 -0500224 offset += lbr->size;
225
226 if (lbr->tag != LB_TAG_CBMEM_ENTRY)
227 continue;
228
Aaron Durbinf2a38222017-09-26 17:44:28 -0600229 lbe = (const void *)lbr;
Aaron Durbin09c0c112015-09-30 12:33:01 -0500230 if (lbe->id != id)
231 continue;
232
233 *addr = lbe->address;
234 *size = lbe->entry_size;
235 ret = 0;
236 break;
237 }
238
Aaron Durbin09c0c112015-09-30 12:33:01 -0500239 return ret;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700240}
241
242/*
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800243 * Try finding the timestamp table and coreboot cbmem console starting from the
244 * passed in memory offset. Could be called recursively in case a forwarding
245 * entry is found.
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700246 *
Patrick Georgi220c2092020-01-30 12:58:08 +0100247 * Returns pointer to a memory buffer containing the timestamp table or zero if
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700248 * none found.
249 */
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800250
251static struct lb_cbmem_ref timestamps;
252static struct lb_cbmem_ref console;
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200253static struct lb_cbmem_ref tcpa_log;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800254static struct lb_memory_range cbmem;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800255
Stefan Reinauer8c594772013-04-19 14:22:29 -0700256/* This is a work-around for a nasty problem introduced by initially having
257 * pointer sized entries in the lb_cbmem_ref structures. This caused problems
258 * on 64bit x86 systems because coreboot is 32bit on those systems.
259 * When the problem was found, it was corrected, but there are a lot of
260 * systems out there with a firmware that does not produce the right
261 * lb_cbmem_ref structure. Hence we try to autocorrect this issue here.
262 */
Aaron Durbinf2a38222017-09-26 17:44:28 -0600263static struct lb_cbmem_ref parse_cbmem_ref(const struct lb_cbmem_ref *cbmem_ref)
Stefan Reinauer8c594772013-04-19 14:22:29 -0700264{
265 struct lb_cbmem_ref ret;
266
Julius Wernere3c23912018-11-26 15:57:59 -0800267 aligned_memcpy(&ret, cbmem_ref, sizeof(ret));
Stefan Reinauer8c594772013-04-19 14:22:29 -0700268
269 if (cbmem_ref->size < sizeof(*cbmem_ref))
270 ret.cbmem_addr = (uint32_t)ret.cbmem_addr;
271
Stefan Reinauera9c83612013-07-16 17:47:35 -0700272 debug(" cbmem_addr = %" PRIx64 "\n", ret.cbmem_addr);
273
Stefan Reinauer8c594772013-04-19 14:22:29 -0700274 return ret;
275}
276
Aaron Durbin46300aa2017-09-26 16:22:38 -0600277static void parse_memory_tags(const struct lb_memory *mem)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700278{
Aaron Durbin46300aa2017-09-26 16:22:38 -0600279 int num_entries;
280 int i;
281
282 /* Peel off the header size and calculate the number of entries. */
283 num_entries = (mem->size - sizeof(*mem)) / sizeof(mem->map[0]);
284
285 for (i = 0; i < num_entries; i++) {
286 if (mem->map[i].type != LB_MEM_TABLE)
287 continue;
288 debug(" LB_MEM_TABLE found.\n");
289 /* The last one found is CBMEM */
Aaron Durbineb722282019-01-31 09:40:26 -0700290 aligned_memcpy(&cbmem, &mem->map[i], sizeof(cbmem));
Aaron Durbin46300aa2017-09-26 16:22:38 -0600291 }
292}
293
294/* Return < 0 on error, 0 on success, 1 if forwarding table entry found. */
295static int parse_cbtable_entries(const struct mapping *table_mapping)
296{
297 size_t i;
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200298 const struct lb_record *lbr_p;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600299 size_t table_size = mapping_size(table_mapping);
300 const void *lbtable = mapping_virt(table_mapping);
301 int forwarding_table_found = 0;
302
303 for (i = 0; i < table_size; i += lbr_p->size) {
304 lbr_p = lbtable + i;
305 debug(" coreboot table entry 0x%02x\n", lbr_p->tag);
306 switch (lbr_p->tag) {
307 case LB_TAG_MEMORY:
308 debug(" Found memory map.\n");
309 parse_memory_tags(lbtable + i);
310 continue;
311 case LB_TAG_TIMESTAMPS: {
312 debug(" Found timestamp table.\n");
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200313 timestamps =
314 parse_cbmem_ref((struct lb_cbmem_ref *)lbr_p);
Aaron Durbin46300aa2017-09-26 16:22:38 -0600315 continue;
316 }
317 case LB_TAG_CBMEM_CONSOLE: {
318 debug(" Found cbmem console.\n");
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200319 console = parse_cbmem_ref((struct lb_cbmem_ref *)lbr_p);
320 continue;
321 }
322 case LB_TAG_TCPA_LOG: {
323 debug(" Found tcpa log table.\n");
324 tcpa_log =
325 parse_cbmem_ref((struct lb_cbmem_ref *)lbr_p);
Aaron Durbin46300aa2017-09-26 16:22:38 -0600326 continue;
327 }
328 case LB_TAG_FORWARD: {
329 int ret;
330 /*
331 * This is a forwarding entry - repeat the
332 * search at the new address.
333 */
334 struct lb_forward lbf_p =
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200335 *(const struct lb_forward *)lbr_p;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600336 debug(" Found forwarding entry.\n");
337 ret = parse_cbtable(lbf_p.forward, 0);
338
339 /* Assume the forwarding entry is valid. If this fails
340 * then there's a total failure. */
341 if (ret < 0)
342 return -1;
343 forwarding_table_found = 1;
344 }
345 default:
346 break;
347 }
348 }
349
350 return forwarding_table_found;
351}
352
353/* Return < 0 on error, 0 on success. */
354static int parse_cbtable(u64 address, size_t table_size)
355{
Aaron Durbinf2a38222017-09-26 17:44:28 -0600356 const void *buf;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600357 struct mapping header_mapping;
358 size_t req_size;
359 size_t i;
360
361 req_size = table_size;
362 /* Default to 4 KiB search space. */
363 if (req_size == 0)
364 req_size = 4 * 1024;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800365
Aaron Durbinb58f9e32014-10-07 14:56:35 -0500366 debug("Looking for coreboot table at %" PRIx64 " %zd bytes.\n",
Aaron Durbin46300aa2017-09-26 16:22:38 -0600367 address, req_size);
368
369 buf = map_memory(&header_mapping, address, req_size);
370
Timothy Pearsonbea71402015-09-05 18:07:17 -0500371 if (!buf)
Aaron Durbin46300aa2017-09-26 16:22:38 -0600372 return -1;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700373
Aaron Durbin46300aa2017-09-26 16:22:38 -0600374 /* look at every 16 bytes */
Aaron Durbincf20c902017-09-28 17:52:59 -0600375 for (i = 0; i <= req_size - sizeof(struct lb_header); i += 16) {
Aaron Durbin46300aa2017-09-26 16:22:38 -0600376 int ret;
Aaron Durbinf2a38222017-09-26 17:44:28 -0600377 const struct lb_header *lbh;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600378 struct mapping table_mapping;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700379
Aaron Durbin46300aa2017-09-26 16:22:38 -0600380 lbh = buf + i;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800381 if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) ||
382 !lbh->header_bytes ||
383 ipchcksum(lbh, sizeof(*lbh))) {
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700384 continue;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700385 }
386
Aaron Durbin46300aa2017-09-26 16:22:38 -0600387 /* Map in the whole table to parse. */
388 if (!map_memory(&table_mapping, address + i + lbh->header_bytes,
389 lbh->table_bytes)) {
390 debug("Couldn't map in table\n");
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700391 continue;
392 }
393
Aaron Durbin46300aa2017-09-26 16:22:38 -0600394 if (ipchcksum(mapping_virt(&table_mapping), lbh->table_bytes) !=
395 lbh->table_checksum) {
396 debug("Signature found, but wrong checksum.\n");
397 unmap_memory(&table_mapping);
398 continue;
399 }
400
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800401 debug("Found!\n");
402
Aaron Durbin46300aa2017-09-26 16:22:38 -0600403 ret = parse_cbtable_entries(&table_mapping);
Aaron Durbin09c0c112015-09-30 12:33:01 -0500404
Aaron Durbin46300aa2017-09-26 16:22:38 -0600405 /* Table parsing failed. */
406 if (ret < 0) {
407 unmap_memory(&table_mapping);
408 continue;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700409 }
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800410
Aaron Durbin46300aa2017-09-26 16:22:38 -0600411 /* Succeeded in parsing the table. Header not needed anymore. */
412 unmap_memory(&header_mapping);
413
414 /*
415 * Table parsing succeeded. If forwarding table not found update
416 * coreboot table mapping for future use.
417 */
418 if (ret == 0)
419 lbtable_mapping = table_mapping;
420 else
421 unmap_memory(&table_mapping);
422
423 return 0;
424 }
425
426 unmap_memory(&header_mapping);
427
428 return -1;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700429}
430
Patrick Georgid00f1802015-07-13 16:53:50 +0200431#if defined(linux) && (defined(__i386__) || defined(__x86_64__))
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700432/*
Aaron Durbin08e920e2016-03-12 08:41:34 +0100433 * read CPU frequency from a sysfs file, return an frequency in Megahertz as
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700434 * an int or exit on any error.
435 */
Aaron Durbinc49014e2015-08-30 21:19:55 -0500436static unsigned long arch_tick_frequency(void)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700437{
438 FILE *cpuf;
439 char freqs[100];
440 int size;
441 char *endp;
442 u64 rv;
443
444 const char* freq_file =
445 "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
446
447 cpuf = fopen(freq_file, "r");
448 if (!cpuf) {
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800449 fprintf(stderr, "Could not open %s: %s\n",
450 freq_file, strerror(errno));
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700451 exit(1);
452 }
453
454 memset(freqs, 0, sizeof(freqs));
455 size = fread(freqs, 1, sizeof(freqs), cpuf);
456 if (!size || (size == sizeof(freqs))) {
457 fprintf(stderr, "Wrong number of bytes(%d) read from %s\n",
458 size, freq_file);
459 exit(1);
460 }
461 fclose(cpuf);
462 rv = strtoull(freqs, &endp, 10);
463
464 if (*endp == '\0' || *endp == '\n')
Aaron Durbin08e920e2016-03-12 08:41:34 +0100465 /* cpuinfo_max_freq is in kHz. Convert it to MHz. */
466 return rv / 1000;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700467 fprintf(stderr, "Wrong formatted value ^%s^ read from %s\n",
468 freqs, freq_file);
469 exit(1);
470}
Patrick Georgid00f1802015-07-13 16:53:50 +0200471#elif defined(__OpenBSD__) && (defined(__i386__) || defined(__x86_64__))
Aaron Durbinc49014e2015-08-30 21:19:55 -0500472static unsigned long arch_tick_frequency(void)
Patrick Georgid00f1802015-07-13 16:53:50 +0200473{
474 int mib[2] = { CTL_HW, HW_CPUSPEED };
475 static int value = 0;
476 size_t value_len = sizeof(value);
477
Aaron Durbinc49014e2015-08-30 21:19:55 -0500478 /* Return 1 MHz when sysctl fails. */
Patrick Georgid00f1802015-07-13 16:53:50 +0200479 if ((value == 0) && (sysctl(mib, 2, &value, &value_len, NULL, 0) == -1))
Aaron Durbinc49014e2015-08-30 21:19:55 -0500480 return 1;
Patrick Georgid00f1802015-07-13 16:53:50 +0200481
Aaron Durbinc49014e2015-08-30 21:19:55 -0500482 return value;
Patrick Georgid00f1802015-07-13 16:53:50 +0200483}
Stefan Reinauerd8ef9e92013-07-31 15:44:37 -0700484#else
Aaron Durbinc49014e2015-08-30 21:19:55 -0500485static unsigned long arch_tick_frequency(void)
Stefan Reinauerd8ef9e92013-07-31 15:44:37 -0700486{
Aaron Durbinc49014e2015-08-30 21:19:55 -0500487 /* 1 MHz = 1us. */
488 return 1;
Stefan Reinauerd8ef9e92013-07-31 15:44:37 -0700489}
490#endif
491
Aaron Durbinc49014e2015-08-30 21:19:55 -0500492static unsigned long tick_freq_mhz;
493
494static void timestamp_set_tick_freq(unsigned long table_tick_freq_mhz)
495{
496 tick_freq_mhz = table_tick_freq_mhz;
497
Martin Rothac9d6b82017-12-11 13:27:56 -0700498 /* Honor table frequency if present. */
499 if (!tick_freq_mhz)
500 tick_freq_mhz = arch_tick_frequency();
Aaron Durbinc49014e2015-08-30 21:19:55 -0500501
502 if (!tick_freq_mhz) {
503 fprintf(stderr, "Cannot determine timestamp tick frequency.\n");
504 exit(1);
505 }
Martin Rothac9d6b82017-12-11 13:27:56 -0700506
507 debug("Timestamp tick frequency: %ld MHz\n", tick_freq_mhz);
Aaron Durbinc49014e2015-08-30 21:19:55 -0500508}
509
Jacob Garber79a2f472019-06-27 17:23:25 -0600510static u64 arch_convert_raw_ts_entry(u64 ts)
Aaron Durbinc49014e2015-08-30 21:19:55 -0500511{
512 return ts / tick_freq_mhz;
513}
514
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700515/*
516 * Print an integer in 'normalized' form - with commas separating every three
Julius Wernera7d92442014-12-02 20:51:19 -0800517 * decimal orders.
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700518 */
Julius Wernera7d92442014-12-02 20:51:19 -0800519static void print_norm(u64 v)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700520{
Julius Wernera7d92442014-12-02 20:51:19 -0800521 if (v >= 1000) {
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700522 /* print the higher order sections first */
Julius Wernera7d92442014-12-02 20:51:19 -0800523 print_norm(v / 1000);
524 printf(",%3.3u", (u32)(v % 1000));
525 } else {
526 printf("%u", (u32)(v % 1000));
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700527 }
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700528}
529
Aaron Durbinfbff3012015-08-30 22:00:12 -0500530static const char *timestamp_name(uint32_t id)
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700531{
Jacob Garber414d5d82019-06-27 16:02:32 -0600532 for (size_t i = 0; i < ARRAY_SIZE(timestamp_ids); i++) {
Aaron Durbinfbff3012015-08-30 22:00:12 -0500533 if (timestamp_ids[i].id == id)
534 return timestamp_ids[i].name;
535 }
536 return "<unknown>";
537}
538
539static uint64_t timestamp_print_parseable_entry(uint32_t id, uint64_t stamp,
540 uint64_t prev_stamp)
541{
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700542 const char *name;
Aaron Durbin799bf782015-08-06 13:52:08 -0500543 uint64_t step_time;
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700544
Aaron Durbinfbff3012015-08-30 22:00:12 -0500545 name = timestamp_name(id);
546
547 step_time = arch_convert_raw_ts_entry(stamp - prev_stamp);
548
549 /* ID<tab>absolute time<tab>relative time<tab>description */
550 printf("%d\t", id);
551 printf("%llu\t", (long long)arch_convert_raw_ts_entry(stamp));
552 printf("%llu\t", (long long)step_time);
553 printf("%s\n", name);
554
555 return step_time;
556}
557
Jacob Garber79a2f472019-06-27 17:23:25 -0600558static uint64_t timestamp_print_entry(uint32_t id, uint64_t stamp, uint64_t prev_stamp)
Aaron Durbinfbff3012015-08-30 22:00:12 -0500559{
560 const char *name;
561 uint64_t step_time;
562
563 name = timestamp_name(id);
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700564
565 printf("%4d:", id);
Julius Wernera7d92442014-12-02 20:51:19 -0800566 printf("%-50s", name);
567 print_norm(arch_convert_raw_ts_entry(stamp));
Aaron Durbin799bf782015-08-06 13:52:08 -0500568 step_time = arch_convert_raw_ts_entry(stamp - prev_stamp);
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700569 if (prev_stamp) {
570 printf(" (");
Aaron Durbin799bf782015-08-06 13:52:08 -0500571 print_norm(step_time);
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700572 printf(")");
573 }
574 printf("\n");
Aaron Durbin799bf782015-08-06 13:52:08 -0500575
576 return step_time;
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700577}
578
Raul E Rangeld4fec682018-05-11 11:08:07 -0600579static int compare_timestamp_entries(const void *a, const void *b)
580{
581 const struct timestamp_entry *tse_a = (struct timestamp_entry *)a;
582 const struct timestamp_entry *tse_b = (struct timestamp_entry *)b;
583
Furquan Shaikh8f567322018-05-17 15:08:03 -0700584 if (tse_a->entry_stamp > tse_b->entry_stamp)
585 return 1;
586 else if (tse_a->entry_stamp < tse_b->entry_stamp)
587 return -1;
588
589 return 0;
Raul E Rangeld4fec682018-05-11 11:08:07 -0600590}
591
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700592/* dump the timestamp table */
Aaron Durbinfbff3012015-08-30 22:00:12 -0500593static void dump_timestamps(int mach_readable)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700594{
Aaron Durbinf2a38222017-09-26 17:44:28 -0600595 const struct timestamp_table *tst_p;
Raul E Rangeld4fec682018-05-11 11:08:07 -0600596 struct timestamp_table *sorted_tst_p;
Aaron Durbinb58f9e32014-10-07 14:56:35 -0500597 size_t size;
Aaron Durbin31540fb2015-07-11 12:44:10 -0500598 uint64_t prev_stamp;
Aaron Durbin799bf782015-08-06 13:52:08 -0500599 uint64_t total_time;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600600 struct mapping timestamp_mapping;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800601
602 if (timestamps.tag != LB_TAG_TIMESTAMPS) {
603 fprintf(stderr, "No timestamps found in coreboot table.\n");
604 return;
605 }
606
Aaron Durbinb58f9e32014-10-07 14:56:35 -0500607 size = sizeof(*tst_p);
Aaron Durbin46300aa2017-09-26 16:22:38 -0600608 tst_p = map_memory(&timestamp_mapping, timestamps.cbmem_addr, size);
609 if (!tst_p)
610 die("Unable to map timestamp header\n");
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700611
Aaron Durbinc49014e2015-08-30 21:19:55 -0500612 timestamp_set_tick_freq(tst_p->tick_freq_mhz);
613
Aaron Durbinfbff3012015-08-30 22:00:12 -0500614 if (!mach_readable)
615 printf("%d entries total:\n\n", tst_p->num_entries);
Aaron Durbinb58f9e32014-10-07 14:56:35 -0500616 size += tst_p->num_entries * sizeof(tst_p->entries[0]);
617
Aaron Durbin46300aa2017-09-26 16:22:38 -0600618 unmap_memory(&timestamp_mapping);
619
620 tst_p = map_memory(&timestamp_mapping, timestamps.cbmem_addr, size);
621 if (!tst_p)
622 die("Unable to map full timestamp table\n");
Aaron Durbinb58f9e32014-10-07 14:56:35 -0500623
Aaron Durbin31540fb2015-07-11 12:44:10 -0500624 /* Report the base time within the table. */
625 prev_stamp = 0;
Aaron Durbinfbff3012015-08-30 22:00:12 -0500626 if (mach_readable)
627 timestamp_print_parseable_entry(0, tst_p->base_time,
628 prev_stamp);
629 else
630 timestamp_print_entry(0, tst_p->base_time, prev_stamp);
Aaron Durbin31540fb2015-07-11 12:44:10 -0500631 prev_stamp = tst_p->base_time;
632
Raul E Rangeld4fec682018-05-11 11:08:07 -0600633 sorted_tst_p = malloc(size);
634 if (!sorted_tst_p)
635 die("Failed to allocate memory");
Julius Wernere3c23912018-11-26 15:57:59 -0800636 aligned_memcpy(sorted_tst_p, tst_p, size);
Raul E Rangeld4fec682018-05-11 11:08:07 -0600637
638 qsort(&sorted_tst_p->entries[0], sorted_tst_p->num_entries,
639 sizeof(struct timestamp_entry), compare_timestamp_entries);
640
Aaron Durbin799bf782015-08-06 13:52:08 -0500641 total_time = 0;
Jacob Garber414d5d82019-06-27 16:02:32 -0600642 for (uint32_t i = 0; i < sorted_tst_p->num_entries; i++) {
Aaron Durbin31540fb2015-07-11 12:44:10 -0500643 uint64_t stamp;
Raul E Rangeld4fec682018-05-11 11:08:07 -0600644 const struct timestamp_entry *tse = &sorted_tst_p->entries[i];
Aaron Durbin31540fb2015-07-11 12:44:10 -0500645
646 /* Make all timestamps absolute. */
Raul E Rangeld4fec682018-05-11 11:08:07 -0600647 stamp = tse->entry_stamp + sorted_tst_p->base_time;
Aaron Durbinfbff3012015-08-30 22:00:12 -0500648 if (mach_readable)
649 total_time +=
650 timestamp_print_parseable_entry(tse->entry_id,
651 stamp, prev_stamp);
652 else
653 total_time += timestamp_print_entry(tse->entry_id,
Aaron Durbin799bf782015-08-06 13:52:08 -0500654 stamp, prev_stamp);
Aaron Durbin31540fb2015-07-11 12:44:10 -0500655 prev_stamp = stamp;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700656 }
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800657
Aaron Durbinfbff3012015-08-30 22:00:12 -0500658 if (!mach_readable) {
659 printf("\nTotal Time: ");
660 print_norm(total_time);
661 printf("\n");
662 }
Aaron Durbin799bf782015-08-06 13:52:08 -0500663
Aaron Durbin46300aa2017-09-26 16:22:38 -0600664 unmap_memory(&timestamp_mapping);
Raul E Rangeld4fec682018-05-11 11:08:07 -0600665 free(sorted_tst_p);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700666}
667
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200668/* dump the tcpa log table */
669static void dump_tcpa_log(void)
670{
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200671 const struct tcpa_table *tclt_p;
672 size_t size;
673 struct mapping tcpa_mapping;
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200674
675 if (tcpa_log.tag != LB_TAG_TCPA_LOG) {
676 fprintf(stderr, "No tcpa log found in coreboot table.\n");
677 return;
678 }
679
680 size = sizeof(*tclt_p);
681 tclt_p = map_memory(&tcpa_mapping, tcpa_log.cbmem_addr, size);
682 if (!tclt_p)
683 die("Unable to map tcpa log header\n");
684
685 size += tclt_p->num_entries * sizeof(tclt_p->entries[0]);
686
687 unmap_memory(&tcpa_mapping);
688
689 tclt_p = map_memory(&tcpa_mapping, tcpa_log.cbmem_addr, size);
690 if (!tclt_p)
691 die("Unable to map full tcpa log table\n");
692
693 printf("coreboot TCPA log:\n\n");
694
Jacob Garber414d5d82019-06-27 16:02:32 -0600695 for (uint16_t i = 0; i < tclt_p->num_entries; i++) {
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200696 const struct tcpa_entry *tce = &tclt_p->entries[i];
697
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +0100698 printf(" PCR-%u ", tce->pcr);
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200699
Jacob Garber414d5d82019-06-27 16:02:32 -0600700 for (uint32_t j = 0; j < tce->digest_length; j++)
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +0100701 printf("%02x", tce->digest[j]);
702
703 printf(" %s [%s]\n", tce->digest_type, tce->name);
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +0200704 }
705
706 unmap_memory(&tcpa_mapping);
707}
708
Julius Wernerd67c6872017-02-02 17:32:00 -0800709struct cbmem_console {
710 u32 size;
711 u32 cursor;
712 u8 body[0];
713} __attribute__ ((__packed__));
714
715#define CBMC_CURSOR_MASK ((1 << 28) - 1)
716#define CBMC_OVERFLOW (1 << 31)
717
Stefan Reinauer19f87562013-01-07 13:37:12 -0800718/* dump the cbmem console */
Julius Wernerb7b64a92017-04-28 16:31:46 -0700719static void dump_console(int one_boot_only)
Stefan Reinauer19f87562013-01-07 13:37:12 -0800720{
Aaron Durbinf2a38222017-09-26 17:44:28 -0600721 const struct cbmem_console *console_p;
Stefan Reinauer19f87562013-01-07 13:37:12 -0800722 char *console_c;
Julius Wernerd67c6872017-02-02 17:32:00 -0800723 size_t size, cursor;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600724 struct mapping console_mapping;
Stefan Reinauer19f87562013-01-07 13:37:12 -0800725
726 if (console.tag != LB_TAG_CBMEM_CONSOLE) {
727 fprintf(stderr, "No console found in coreboot table.\n");
728 return;
729 }
730
Julius Wernerd67c6872017-02-02 17:32:00 -0800731 size = sizeof(*console_p);
Aaron Durbin46300aa2017-09-26 16:22:38 -0600732 console_p = map_memory(&console_mapping, console.cbmem_addr, size);
733 if (!console_p)
734 die("Unable to map console object.\n");
735
Julius Wernerd67c6872017-02-02 17:32:00 -0800736 cursor = console_p->cursor & CBMC_CURSOR_MASK;
737 if (!(console_p->cursor & CBMC_OVERFLOW) && cursor < console_p->size)
Vladimir Serbinenkof4a0d012013-03-30 12:15:12 +0100738 size = cursor;
Julius Wernerd67c6872017-02-02 17:32:00 -0800739 else
740 size = console_p->size;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600741 unmap_memory(&console_mapping);
Julius Wernerd67c6872017-02-02 17:32:00 -0800742
743 console_c = malloc(size + 1);
Stefan Reinauer19f87562013-01-07 13:37:12 -0800744 if (!console_c) {
745 fprintf(stderr, "Not enough memory for console.\n");
746 exit(1);
747 }
Julius Wernerd67c6872017-02-02 17:32:00 -0800748 console_c[size] = '\0';
Stefan Reinauer19f87562013-01-07 13:37:12 -0800749
Aaron Durbin46300aa2017-09-26 16:22:38 -0600750 console_p = map_memory(&console_mapping, console.cbmem_addr,
751 size + sizeof(*console_p));
752
753 if (!console_p)
754 die("Unable to map full console object.\n");
755
Julius Wernerd67c6872017-02-02 17:32:00 -0800756 if (console_p->cursor & CBMC_OVERFLOW) {
757 if (cursor >= size) {
758 printf("cbmem: ERROR: CBMEM console struct is illegal, "
759 "output may be corrupt or out of order!\n\n");
760 cursor = 0;
761 }
762 aligned_memcpy(console_c, console_p->body + cursor,
763 size - cursor);
764 aligned_memcpy(console_c + size - cursor,
765 console_p->body, cursor);
766 } else {
767 aligned_memcpy(console_c, console_p->body, size);
768 }
Stefan Reinauer19f87562013-01-07 13:37:12 -0800769
Julius Wernerd67c6872017-02-02 17:32:00 -0800770 /* Slight memory corruption may occur between reboots and give us a few
771 unprintable characters like '\0'. Replace them with '?' on output. */
772 for (cursor = 0; cursor < size; cursor++)
773 if (!isprint(console_c[cursor]) && !isspace(console_c[cursor]))
774 console_c[cursor] = '?';
Stefan Reinauer19f87562013-01-07 13:37:12 -0800775
Julius Wernerb7b64a92017-04-28 16:31:46 -0700776 /* We detect the last boot by looking for a bootblock, romstage or
777 ramstage banner, in that order (to account for platforms without
778 CONFIG_BOOTBLOCK_CONSOLE and/or CONFIG_EARLY_CONSOLE). Once we find
779 a banner, store the last match for that stage in cursor and stop. */
780 cursor = 0;
781 if (one_boot_only) {
You-Cheng Syu1430b392019-07-01 16:40:25 +0800782#define BANNER_REGEX(stage) \
783 "\n\ncoreboot-[^\n]* " stage " starting.*\\.\\.\\.\n"
Julius Wernerbe3aa042017-06-12 17:35:15 -0700784#define OVERFLOW_REGEX(stage) "\n\\*\\*\\* Pre-CBMEM " stage " console overflow"
Julius Wernerb7b64a92017-04-28 16:31:46 -0700785 const char *regex[] = { BANNER_REGEX("bootblock"),
You-Cheng Syu1430b392019-07-01 16:40:25 +0800786 BANNER_REGEX("verstage"),
Julius Wernerd906bb62017-05-16 13:54:18 -0700787 OVERFLOW_REGEX("romstage"),
Furquan Shaikh35972de2018-02-16 16:12:02 -0800788 BANNER_REGEX("romstage"),
789 OVERFLOW_REGEX("ramstage"),
790 BANNER_REGEX("ramstage") };
Julius Wernerb7b64a92017-04-28 16:31:46 -0700791
Jacob Garber414d5d82019-06-27 16:02:32 -0600792 for (size_t i = 0; !cursor && i < ARRAY_SIZE(regex); i++) {
Julius Wernerb7b64a92017-04-28 16:31:46 -0700793 regex_t re;
794 regmatch_t match;
795 assert(!regcomp(&re, regex[i], 0));
796
797 /* Keep looking for matches so we find the last one. */
798 while (!regexec(&re, console_c + cursor, 1, &match, 0))
799 cursor += match.rm_so + 1;
800 regfree(&re);
801 }
802 }
803
804 puts(console_c + cursor);
Stefan Reinauer19f87562013-01-07 13:37:12 -0800805 free(console_c);
Aaron Durbin46300aa2017-09-26 16:22:38 -0600806 unmap_memory(&console_mapping);
Stefan Reinauer19f87562013-01-07 13:37:12 -0800807}
808
Stefan Reinauera9c83612013-07-16 17:47:35 -0700809static void hexdump(unsigned long memory, int length)
810{
811 int i;
Aaron Durbinf2a38222017-09-26 17:44:28 -0600812 const uint8_t *m;
Stefan Reinauera9c83612013-07-16 17:47:35 -0700813 int all_zero = 0;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600814 struct mapping hexdump_mapping;
Stefan Reinauera9c83612013-07-16 17:47:35 -0700815
Aaron Durbin46300aa2017-09-26 16:22:38 -0600816 m = map_memory(&hexdump_mapping, memory, length);
817 if (!m)
818 die("Unable to map hexdump memory.\n");
Stefan Reinauera9c83612013-07-16 17:47:35 -0700819
820 for (i = 0; i < length; i += 16) {
821 int j;
822
823 all_zero++;
824 for (j = 0; j < 16; j++) {
825 if(m[i+j] != 0) {
826 all_zero = 0;
827 break;
828 }
829 }
830
831 if (all_zero < 2) {
832 printf("%08lx:", memory + i);
833 for (j = 0; j < 16; j++)
834 printf(" %02x", m[i+j]);
835 printf(" ");
836 for (j = 0; j < 16; j++)
837 printf("%c", isprint(m[i+j]) ? m[i+j] : '.');
838 printf("\n");
839 } else if (all_zero == 2) {
840 printf("...\n");
841 }
842 }
843
Aaron Durbin46300aa2017-09-26 16:22:38 -0600844 unmap_memory(&hexdump_mapping);
Stefan Reinauera9c83612013-07-16 17:47:35 -0700845}
846
847static void dump_cbmem_hex(void)
848{
849 if (cbmem.type != LB_MEM_TABLE) {
850 fprintf(stderr, "No coreboot CBMEM area found!\n");
851 return;
852 }
853
854 hexdump(unpack_lb64(cbmem.start), unpack_lb64(cbmem.size));
855}
856
Jacob Garber79a2f472019-06-27 17:23:25 -0600857static void rawdump(uint64_t base, uint64_t size)
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700858{
Aaron Durbinf2a38222017-09-26 17:44:28 -0600859 const uint8_t *m;
Aaron Durbin46300aa2017-09-26 16:22:38 -0600860 struct mapping dump_mapping;
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700861
Aaron Durbin46300aa2017-09-26 16:22:38 -0600862 m = map_memory(&dump_mapping, base, size);
863 if (!m)
864 die("Unable to map rawdump memory\n");
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700865
Jacob Garber414d5d82019-06-27 16:02:32 -0600866 for (uint64_t i = 0 ; i < size; i++)
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700867 printf("%c", m[i]);
Aaron Durbin46300aa2017-09-26 16:22:38 -0600868
869 unmap_memory(&dump_mapping);
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700870}
871
872static void dump_cbmem_raw(unsigned int id)
873{
Aaron Durbinf2a38222017-09-26 17:44:28 -0600874 const uint8_t *table;
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700875 size_t offset;
876 uint64_t base = 0;
877 uint64_t size = 0;
878
Aaron Durbin46300aa2017-09-26 16:22:38 -0600879 table = mapping_virt(&lbtable_mapping);
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700880
881 if (table == NULL)
882 return;
883
884 offset = 0;
885
Aaron Durbin46300aa2017-09-26 16:22:38 -0600886 while (offset < mapping_size(&lbtable_mapping)) {
Aaron Durbinf2a38222017-09-26 17:44:28 -0600887 const struct lb_record *lbr;
888 const struct lb_cbmem_entry *lbe;
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700889
Aaron Durbinf2a38222017-09-26 17:44:28 -0600890 lbr = (const void *)(table + offset);
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700891 offset += lbr->size;
892
893 if (lbr->tag != LB_TAG_CBMEM_ENTRY)
894 continue;
895
Aaron Durbinf2a38222017-09-26 17:44:28 -0600896 lbe = (const void *)lbr;
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700897 if (lbe->id == id) {
898 debug("found id for raw dump %0x", lbe->id);
899 base = lbe->address;
900 size = lbe->entry_size;
901 break;
902 }
903 }
904
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700905 if (!base)
906 fprintf(stderr, "id %0x not found in cbtable\n", id);
907 else
908 rawdump(base, size);
909}
910
Aaron Durbin0dff57d2015-03-05 21:18:33 -0600911struct cbmem_id_to_name {
912 uint32_t id;
913 const char *name;
914};
Vadim Bendebury8b143c52014-05-14 10:12:55 -0700915static const struct cbmem_id_to_name cbmem_ids[] = { CBMEM_ID_TO_NAME_TABLE };
Stefan Reinauerc0199072013-01-07 16:26:10 -0800916
Kyösti Mälkkieab5c122017-09-04 11:10:17 +0300917#define MAX_STAGEx 10
Jacob Garber79a2f472019-06-27 17:23:25 -0600918static void cbmem_print_entry(int n, uint32_t id, uint64_t base, uint64_t size)
Stefan Reinauera9c83612013-07-16 17:47:35 -0700919{
Stefan Reinauera9c83612013-07-16 17:47:35 -0700920 const char *name;
Kyösti Mälkkieab5c122017-09-04 11:10:17 +0300921 char stage_x[20];
Stefan Reinauera9c83612013-07-16 17:47:35 -0700922
923 name = NULL;
Jacob Garber414d5d82019-06-27 16:02:32 -0600924 for (size_t i = 0; i < ARRAY_SIZE(cbmem_ids); i++) {
Stefan Reinauera9c83612013-07-16 17:47:35 -0700925 if (cbmem_ids[i].id == id) {
926 name = cbmem_ids[i].name;
927 break;
928 }
Kyösti Mälkkieab5c122017-09-04 11:10:17 +0300929 if (id >= CBMEM_ID_STAGEx_META &&
930 id < CBMEM_ID_STAGEx_META + MAX_STAGEx) {
931 snprintf(stage_x, sizeof(stage_x), "STAGE%d META",
932 (id - CBMEM_ID_STAGEx_META));
933 name = stage_x;
934 }
935 if (id >= CBMEM_ID_STAGEx_CACHE &&
936 id < CBMEM_ID_STAGEx_CACHE + MAX_STAGEx) {
937 snprintf(stage_x, sizeof(stage_x), "STAGE%d $ ",
938 (id - CBMEM_ID_STAGEx_CACHE));
939 name = stage_x;
940 }
Stefan Reinauera9c83612013-07-16 17:47:35 -0700941 }
942
943 printf("%2d. ", n);
944 if (name == NULL)
Kyösti Mälkkieab5c122017-09-04 11:10:17 +0300945 printf("\t\t%08x", id);
Stefan Reinauera9c83612013-07-16 17:47:35 -0700946 else
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700947 printf("%s\t%08x", name, id);
Stefan Reinauera9c83612013-07-16 17:47:35 -0700948 printf(" %08" PRIx64 " ", base);
949 printf(" %08" PRIx64 "\n", size);
950}
951
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800952static void dump_cbmem_toc(void)
Stefan Reinauerc0199072013-01-07 16:26:10 -0800953{
Aaron Durbin09c0c112015-09-30 12:33:01 -0500954 int i;
Aaron Durbinf2a38222017-09-26 17:44:28 -0600955 const uint8_t *table;
Aaron Durbin09c0c112015-09-30 12:33:01 -0500956 size_t offset;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800957
Aaron Durbin46300aa2017-09-26 16:22:38 -0600958 table = mapping_virt(&lbtable_mapping);
Aaron Durbin09c0c112015-09-30 12:33:01 -0500959
960 if (table == NULL)
Stefan Reinauerc0199072013-01-07 16:26:10 -0800961 return;
Aaron Durbin09c0c112015-09-30 12:33:01 -0500962
963 printf("CBMEM table of contents:\n");
Pratik Prajapatic29e57d2015-09-03 12:58:44 -0700964 printf(" NAME ID START LENGTH\n");
Aaron Durbin09c0c112015-09-30 12:33:01 -0500965
966 i = 0;
967 offset = 0;
968
Aaron Durbin46300aa2017-09-26 16:22:38 -0600969 while (offset < mapping_size(&lbtable_mapping)) {
Aaron Durbinf2a38222017-09-26 17:44:28 -0600970 const struct lb_record *lbr;
971 const struct lb_cbmem_entry *lbe;
Aaron Durbin09c0c112015-09-30 12:33:01 -0500972
Aaron Durbinf2a38222017-09-26 17:44:28 -0600973 lbr = (const void *)(table + offset);
Aaron Durbin09c0c112015-09-30 12:33:01 -0500974 offset += lbr->size;
975
976 if (lbr->tag != LB_TAG_CBMEM_ENTRY)
977 continue;
978
Aaron Durbinf2a38222017-09-26 17:44:28 -0600979 lbe = (const void *)lbr;
Aaron Durbin09c0c112015-09-30 12:33:01 -0500980 cbmem_print_entry(i, lbe->id, lbe->address, lbe->entry_size);
981 i++;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800982 }
Stefan Reinauerc0199072013-01-07 16:26:10 -0800983}
Stefan Reinauer19f87562013-01-07 13:37:12 -0800984
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800985#define COVERAGE_MAGIC 0x584d4153
986struct file {
987 uint32_t magic;
988 uint32_t next;
989 uint32_t filename;
990 uint32_t data;
991 int offset;
992 int len;
993};
994
995static int mkpath(char *path, mode_t mode)
996{
997 assert (path && *path);
998 char *p;
999 for (p = strchr(path+1, '/'); p; p = strchr(p + 1, '/')) {
1000 *p = '\0';
1001 if (mkdir(path, mode) == -1) {
1002 if (errno != EEXIST) {
1003 *p = '/';
1004 return -1;
1005 }
1006 }
1007 *p = '/';
1008 }
1009 return 0;
1010}
1011
1012static void dump_coverage(void)
1013{
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001014 uint64_t start;
Aaron Durbin09c0c112015-09-30 12:33:01 -05001015 size_t size;
Aaron Durbinf2a38222017-09-26 17:44:28 -06001016 const void *coverage;
Aaron Durbin46300aa2017-09-26 16:22:38 -06001017 struct mapping coverage_mapping;
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001018 unsigned long phys_offset;
1019#define phys_to_virt(x) ((void *)(unsigned long)(x) + phys_offset)
1020
Aaron Durbin09c0c112015-09-30 12:33:01 -05001021 if (find_cbmem_entry(CBMEM_ID_COVERAGE, &start, &size)) {
1022 fprintf(stderr, "No coverage information found\n");
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001023 return;
1024 }
1025
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001026 /* Map coverage area */
Aaron Durbin46300aa2017-09-26 16:22:38 -06001027 coverage = map_memory(&coverage_mapping, start, size);
1028 if (!coverage)
1029 die("Unable to map coverage area.\n");
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001030 phys_offset = (unsigned long)coverage - (unsigned long)start;
1031
1032 printf("Dumping coverage data...\n");
1033
1034 struct file *file = (struct file *)coverage;
1035 while (file && file->magic == COVERAGE_MAGIC) {
1036 FILE *f;
1037 char *filename;
1038
1039 debug(" -> %s\n", (char *)phys_to_virt(file->filename));
1040 filename = strdup((char *)phys_to_virt(file->filename));
1041 if (mkpath(filename, 0755) == -1) {
1042 perror("Directory for coverage data could "
1043 "not be created");
1044 exit(1);
1045 }
1046 f = fopen(filename, "wb");
1047 if (!f) {
1048 printf("Could not open %s: %s\n",
1049 filename, strerror(errno));
1050 exit(1);
1051 }
1052 if (fwrite((void *)phys_to_virt(file->data),
1053 file->len, 1, f) != 1) {
1054 printf("Could not write to %s: %s\n",
1055 filename, strerror(errno));
1056 exit(1);
1057 }
1058 fclose(f);
1059 free(filename);
1060
1061 if (file->next)
1062 file = (struct file *)phys_to_virt(file->next);
1063 else
1064 file = NULL;
1065 }
Aaron Durbin46300aa2017-09-26 16:22:38 -06001066 unmap_memory(&coverage_mapping);
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001067}
1068
1069static void print_version(void)
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001070{
1071 printf("cbmem v%s -- ", CBMEM_VERSION);
1072 printf("Copyright (C) 2012 The ChromiumOS Authors. All rights reserved.\n\n");
1073 printf(
1074 "This program is free software: you can redistribute it and/or modify\n"
1075 "it under the terms of the GNU General Public License as published by\n"
1076 "the Free Software Foundation, version 2 of the License.\n\n"
1077 "This program is distributed in the hope that it will be useful,\n"
1078 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1079 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
Martin Rotheb20e602016-01-12 13:30:50 -07001080 "GNU General Public License for more details.\n\n");
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001081}
1082
Martin Roth8448ac42016-09-11 15:43:22 -06001083static void print_usage(const char *name, int exit_code)
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001084{
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +02001085 printf("usage: %s [-cCltTLxVvh?]\n", name);
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001086 printf("\n"
Stefan Reinauer19f87562013-01-07 13:37:12 -08001087 " -c | --console: print cbmem console\n"
Julius Wernerb7b64a92017-04-28 16:31:46 -07001088 " -1 | --oneboot: print cbmem console for last boot only\n"
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001089 " -C | --coverage: dump coverage information\n"
Stefan Reinauerc0199072013-01-07 16:26:10 -08001090 " -l | --list: print cbmem table of contents\n"
Stefan Reinauera9c83612013-07-16 17:47:35 -07001091 " -x | --hexdump: print hexdump of cbmem area\n"
Pratik Prajapatic29e57d2015-09-03 12:58:44 -07001092 " -r | --rawdump ID: print rawdump of specific ID (in hex) of cbtable\n"
Stefan Reinauer19f87562013-01-07 13:37:12 -08001093 " -t | --timestamps: print timestamp information\n"
Aaron Durbinfbff3012015-08-30 22:00:12 -05001094 " -T | --parseable-timestamps: print parseable timestamps\n"
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +02001095 " -L | --tcpa-log print TCPA log\n"
Stefan Reinauer19f87562013-01-07 13:37:12 -08001096 " -V | --verbose: verbose (debugging) output\n"
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001097 " -v | --version: print the version\n"
1098 " -h | --help: print this help\n"
1099 "\n");
Martin Roth8448ac42016-09-11 15:43:22 -06001100 exit(exit_code);
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001101}
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001102
Adam Kallai66c22502018-11-30 11:31:50 +01001103#if defined(__arm__) || defined(__aarch64__)
Julius Werner337de4c2014-06-16 23:02:03 -07001104static void dt_update_cells(const char *name, int *addr_cells_ptr,
1105 int *size_cells_ptr)
1106{
1107 if (*addr_cells_ptr >= 0 && *size_cells_ptr >= 0)
1108 return;
1109
1110 int buffer;
1111 size_t nlen = strlen(name);
1112 char *prop = alloca(nlen + sizeof("/#address-cells"));
1113 strcpy(prop, name);
1114
1115 if (*addr_cells_ptr < 0) {
1116 strcpy(prop + nlen, "/#address-cells");
1117 int fd = open(prop, O_RDONLY);
1118 if (fd < 0 && errno != ENOENT) {
1119 perror(prop);
1120 } else if (fd >= 0) {
1121 if (read(fd, &buffer, sizeof(int)) < 0)
1122 perror(prop);
1123 else
1124 *addr_cells_ptr = ntohl(buffer);
1125 close(fd);
1126 }
1127 }
1128
1129 if (*size_cells_ptr < 0) {
1130 strcpy(prop + nlen, "/#size-cells");
1131 int fd = open(prop, O_RDONLY);
1132 if (fd < 0 && errno != ENOENT) {
1133 perror(prop);
1134 } else if (fd >= 0) {
1135 if (read(fd, &buffer, sizeof(int)) < 0)
1136 perror(prop);
1137 else
1138 *size_cells_ptr = ntohl(buffer);
1139 close(fd);
1140 }
1141 }
1142}
1143
1144static char *dt_find_compat(const char *parent, const char *compat,
1145 int *addr_cells_ptr, int *size_cells_ptr)
1146{
1147 char *ret = NULL;
1148 struct dirent *entry;
1149 DIR *dir;
1150
1151 if (!(dir = opendir(parent))) {
1152 perror(parent);
1153 return NULL;
1154 }
1155
1156 /* Loop through all files in the directory (DT node). */
1157 while ((entry = readdir(dir))) {
1158 /* We only care about compatible props or subnodes. */
1159 if (entry->d_name[0] == '.' || !((entry->d_type & DT_DIR) ||
1160 !strcmp(entry->d_name, "compatible")))
1161 continue;
1162
1163 /* Assemble the file name (on the stack, for speed). */
1164 size_t plen = strlen(parent);
1165 char *name = alloca(plen + strlen(entry->d_name) + 2);
1166
1167 strcpy(name, parent);
1168 name[plen] = '/';
1169 strcpy(name + plen + 1, entry->d_name);
1170
1171 /* If it's a subnode, recurse. */
1172 if (entry->d_type & DT_DIR) {
1173 ret = dt_find_compat(name, compat, addr_cells_ptr,
1174 size_cells_ptr);
1175
1176 /* There is only one matching node to find, abort. */
1177 if (ret) {
1178 /* Gather cells values on the way up. */
1179 dt_update_cells(parent, addr_cells_ptr,
1180 size_cells_ptr);
1181 break;
1182 }
1183 continue;
1184 }
1185
1186 /* If it's a compatible string, see if it's the right one. */
1187 int fd = open(name, O_RDONLY);
1188 int clen = strlen(compat);
1189 char *buffer = alloca(clen + 1);
1190
1191 if (fd < 0) {
1192 perror(name);
1193 continue;
1194 }
1195
1196 if (read(fd, buffer, clen + 1) < 0) {
1197 perror(name);
1198 close(fd);
1199 continue;
1200 }
1201 close(fd);
1202
1203 if (!strcmp(compat, buffer)) {
1204 /* Initialize these to "unset" for the way up. */
1205 *addr_cells_ptr = *size_cells_ptr = -1;
1206
1207 /* Can't leave string on the stack or we'll lose it! */
1208 ret = strdup(parent);
1209 break;
1210 }
1211 }
1212
1213 closedir(dir);
1214 return ret;
1215}
Adam Kallai66c22502018-11-30 11:31:50 +01001216#endif /* defined(__arm__) || defined(__aarch64__) */
Julius Werner337de4c2014-06-16 23:02:03 -07001217
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001218int main(int argc, char** argv)
1219{
Stefan Reinauer19f87562013-01-07 13:37:12 -08001220 int print_defaults = 1;
1221 int print_console = 0;
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001222 int print_coverage = 0;
Stefan Reinauerc0199072013-01-07 16:26:10 -08001223 int print_list = 0;
Stefan Reinauera9c83612013-07-16 17:47:35 -07001224 int print_hexdump = 0;
Pratik Prajapatic29e57d2015-09-03 12:58:44 -07001225 int print_rawdump = 0;
Stefan Reinauer19f87562013-01-07 13:37:12 -08001226 int print_timestamps = 0;
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +02001227 int print_tcpa_log = 0;
Aaron Durbinfbff3012015-08-30 22:00:12 -05001228 int machine_readable_timestamps = 0;
Julius Wernerb7b64a92017-04-28 16:31:46 -07001229 int one_boot_only = 0;
Pratik Prajapatic29e57d2015-09-03 12:58:44 -07001230 unsigned int rawdump_id = 0;
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001231
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001232 int opt, option_index = 0;
1233 static struct option long_options[] = {
Stefan Reinauer19f87562013-01-07 13:37:12 -08001234 {"console", 0, 0, 'c'},
Julius Wernerb7b64a92017-04-28 16:31:46 -07001235 {"oneboot", 0, 0, '1'},
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001236 {"coverage", 0, 0, 'C'},
Stefan Reinauerc0199072013-01-07 16:26:10 -08001237 {"list", 0, 0, 'l'},
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +02001238 {"tcpa-log", 0, 0, 'L'},
Stefan Reinauer19f87562013-01-07 13:37:12 -08001239 {"timestamps", 0, 0, 't'},
Aaron Durbinfbff3012015-08-30 22:00:12 -05001240 {"parseable-timestamps", 0, 0, 'T'},
Stefan Reinauera9c83612013-07-16 17:47:35 -07001241 {"hexdump", 0, 0, 'x'},
Pratik Prajapatic29e57d2015-09-03 12:58:44 -07001242 {"rawdump", required_argument, 0, 'r'},
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001243 {"verbose", 0, 0, 'V'},
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001244 {"version", 0, 0, 'v'},
1245 {"help", 0, 0, 'h'},
1246 {0, 0, 0, 0}
1247 };
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +02001248 while ((opt = getopt_long(argc, argv, "c1CltTLxVvh?r:",
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001249 long_options, &option_index)) != EOF) {
1250 switch (opt) {
Stefan Reinauer19f87562013-01-07 13:37:12 -08001251 case 'c':
1252 print_console = 1;
1253 print_defaults = 0;
1254 break;
Julius Wernerb7b64a92017-04-28 16:31:46 -07001255 case '1':
1256 print_console = 1;
1257 one_boot_only = 1;
1258 print_defaults = 0;
1259 break;
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001260 case 'C':
1261 print_coverage = 1;
1262 print_defaults = 0;
1263 break;
Stefan Reinauerc0199072013-01-07 16:26:10 -08001264 case 'l':
1265 print_list = 1;
1266 print_defaults = 0;
1267 break;
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +02001268 case 'L':
1269 print_tcpa_log = 1;
1270 print_defaults = 0;
1271 break;
Stefan Reinauera9c83612013-07-16 17:47:35 -07001272 case 'x':
1273 print_hexdump = 1;
1274 print_defaults = 0;
1275 break;
Pratik Prajapatic29e57d2015-09-03 12:58:44 -07001276 case 'r':
1277 print_rawdump = 1;
1278 print_defaults = 0;
1279 rawdump_id = strtoul(optarg, NULL, 16);
1280 break;
Stefan Reinauer19f87562013-01-07 13:37:12 -08001281 case 't':
1282 print_timestamps = 1;
1283 print_defaults = 0;
1284 break;
Aaron Durbinfbff3012015-08-30 22:00:12 -05001285 case 'T':
1286 print_timestamps = 1;
1287 machine_readable_timestamps = 1;
1288 print_defaults = 0;
1289 break;
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001290 case 'V':
1291 verbose = 1;
1292 break;
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001293 case 'v':
1294 print_version();
1295 exit(0);
1296 break;
1297 case 'h':
Martin Roth8448ac42016-09-11 15:43:22 -06001298 print_usage(argv[0], 0);
1299 break;
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001300 case '?':
1301 default:
Martin Roth8448ac42016-09-11 15:43:22 -06001302 print_usage(argv[0], 1);
Stefan Reinauer1e0e5562013-01-02 15:43:56 -08001303 break;
1304 }
1305 }
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001306
Arthur Heymans8cd17ea2018-08-01 17:21:32 +02001307 if (optind < argc) {
1308 fprintf(stderr, "Error: Extra parameter found.\n");
1309 print_usage(argv[0], 1);
1310 }
1311
Julius Werner337de4c2014-06-16 23:02:03 -07001312 mem_fd = open("/dev/mem", O_RDONLY, 0);
1313 if (mem_fd < 0) {
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001314 fprintf(stderr, "Failed to gain memory access: %s\n",
1315 strerror(errno));
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001316 return 1;
1317 }
1318
Adam Kallai66c22502018-11-30 11:31:50 +01001319#if defined(__arm__) || defined(__aarch64__)
Julius Werner337de4c2014-06-16 23:02:03 -07001320 int addr_cells, size_cells;
1321 char *coreboot_node = dt_find_compat("/proc/device-tree", "coreboot",
1322 &addr_cells, &size_cells);
Stefan Reinauer7f681502013-06-19 15:39:09 -07001323
Julius Werner337de4c2014-06-16 23:02:03 -07001324 if (!coreboot_node) {
1325 fprintf(stderr, "Could not find 'coreboot' compatible node!\n");
Stefan Reinauer7f681502013-06-19 15:39:09 -07001326 return 1;
1327 }
1328
Julius Werner337de4c2014-06-16 23:02:03 -07001329 if (addr_cells < 0) {
1330 fprintf(stderr, "Warning: no #address-cells node in tree!\n");
1331 addr_cells = 1;
1332 }
1333
1334 int nlen = strlen(coreboot_node);
1335 char *reg = alloca(nlen + sizeof("/reg"));
1336
1337 strcpy(reg, coreboot_node);
1338 strcpy(reg + nlen, "/reg");
1339 free(coreboot_node);
1340
1341 int fd = open(reg, O_RDONLY);
1342 if (fd < 0) {
1343 perror(reg);
Stefan Reinauer7f681502013-06-19 15:39:09 -07001344 return 1;
1345 }
Stefan Reinauer7f681502013-06-19 15:39:09 -07001346
Julius Werner337de4c2014-06-16 23:02:03 -07001347 int i;
Aaron Durbinb58f9e32014-10-07 14:56:35 -05001348 size_t size_to_read = addr_cells * 4 + size_cells * 4;
1349 u8 *dtbuffer = alloca(size_to_read);
1350 if (read(fd, dtbuffer, size_to_read) < 0) {
Julius Werner337de4c2014-06-16 23:02:03 -07001351 perror(reg);
1352 return 1;
1353 }
1354 close(fd);
1355
1356 /* No variable-length byte swap function anywhere in C... how sad. */
1357 u64 baseaddr = 0;
1358 for (i = 0; i < addr_cells * 4; i++) {
1359 baseaddr <<= 8;
Aaron Durbinb58f9e32014-10-07 14:56:35 -05001360 baseaddr |= *dtbuffer;
1361 dtbuffer++;
1362 }
1363 u64 cb_table_size = 0;
1364 for (i = 0; i < size_cells * 4; i++) {
1365 cb_table_size <<= 8;
1366 cb_table_size |= *dtbuffer;
1367 dtbuffer++;
Julius Werner337de4c2014-06-16 23:02:03 -07001368 }
1369
Aaron Durbin46300aa2017-09-26 16:22:38 -06001370 parse_cbtable(baseaddr, cb_table_size);
Stefan Reinauer7f681502013-06-19 15:39:09 -07001371#else
Aaron Durbin46300aa2017-09-26 16:22:38 -06001372 unsigned long long possible_base_addresses[] = { 0, 0xf0000 };
Stefan Reinauer7f681502013-06-19 15:39:09 -07001373
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001374 /* Find and parse coreboot table */
Jacob Garber414d5d82019-06-27 16:02:32 -06001375 for (size_t j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) {
Aaron Durbin46300aa2017-09-26 16:22:38 -06001376 if (!parse_cbtable(possible_base_addresses[j], 0))
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001377 break;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001378 }
Stefan Reinauer7f681502013-06-19 15:39:09 -07001379#endif
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001380
Aaron Durbin46300aa2017-09-26 16:22:38 -06001381 if (mapping_virt(&lbtable_mapping) == NULL)
1382 die("Table not found.\n");
1383
Stefan Reinauer19f87562013-01-07 13:37:12 -08001384 if (print_console)
Julius Wernerb7b64a92017-04-28 16:31:46 -07001385 dump_console(one_boot_only);
Stefan Reinauer19f87562013-01-07 13:37:12 -08001386
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001387 if (print_coverage)
1388 dump_coverage();
1389
Stefan Reinauerc0199072013-01-07 16:26:10 -08001390 if (print_list)
1391 dump_cbmem_toc();
1392
Stefan Reinauera9c83612013-07-16 17:47:35 -07001393 if (print_hexdump)
1394 dump_cbmem_hex();
1395
Pratik Prajapatic29e57d2015-09-03 12:58:44 -07001396 if (print_rawdump)
1397 dump_cbmem_raw(rawdump_id);
1398
Stefan Reinauer19f87562013-01-07 13:37:12 -08001399 if (print_defaults || print_timestamps)
Aaron Durbinfbff3012015-08-30 22:00:12 -05001400 dump_timestamps(machine_readable_timestamps);
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001401
Philipp Deppenwiesefa1f6ff2018-05-13 12:42:42 +02001402 if (print_tcpa_log)
1403 dump_tcpa_log();
1404
Aaron Durbin46300aa2017-09-26 16:22:38 -06001405 unmap_memory(&lbtable_mapping);
1406
Julius Werner337de4c2014-06-16 23:02:03 -07001407 close(mem_fd);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001408 return 0;
1409}