blob: aa9fa1359282ccb495e14b50bb83b775e12c44da [file] [log] [blame]
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauera9c83612013-07-16 17:47:35 -07004 * Copyright 2012 Google Inc.
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07005 *
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 Huber8e4bb9282013-05-26 18:17:54 +020020#include <inttypes.h>
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070021#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
Stefan Reinauer1e0e5562013-01-02 15:43:56 -080024#include <unistd.h>
Stefan Reinauer8c594772013-04-19 14:22:29 -070025#include <inttypes.h>
Stefan Reinauer1e0e5562013-01-02 15:43:56 -080026#include <getopt.h>
Julius Werner337de4c2014-06-16 23:02:03 -070027#include <dirent.h>
Stefan Reinauer05cbce62013-01-03 14:30:33 -080028#include <errno.h>
29#include <fcntl.h>
Stefan Reinauera9c83612013-07-16 17:47:35 -070030#include <ctype.h>
Stefan Reinauer7f681502013-06-19 15:39:09 -070031#include <arpa/inet.h>
Stefan Reinauer05cbce62013-01-03 14:30:33 -080032#include <sys/types.h>
33#include <sys/stat.h>
34#include <sys/mman.h>
Stefan Reinauerd37ab452012-12-18 16:23:28 -080035#include <libgen.h>
36#include <assert.h>
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070037
Stefan Reinauer05cbce62013-01-03 14:30:33 -080038#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
39#define MAP_BYTES (1024*1024)
Kyösti Mälkkib3594ab2014-06-18 00:43:35 +030040#define IS_ENABLED(x) (defined (x) && (x))
Stefan Reinauer05cbce62013-01-03 14:30:33 -080041
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070042#include "boot/coreboot_tables.h"
43
Julius Werner337de4c2014-06-16 23:02:03 -070044typedef uint8_t u8;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070045typedef uint16_t u16;
46typedef uint32_t u32;
47typedef uint64_t u64;
48
49#include "cbmem.h"
50#include "timestamp.h"
51
Stefan Reinauera9c83612013-07-16 17:47:35 -070052#define CBMEM_VERSION "1.1"
Stefan Reinauer1e0e5562013-01-02 15:43:56 -080053
Stefan Reinauer05cbce62013-01-03 14:30:33 -080054/* verbose output? */
55static int verbose = 0;
56#define debug(x...) if(verbose) printf(x)
57
58/* File handle used to access /dev/mem */
Julius Werner337de4c2014-06-16 23:02:03 -070059static int mem_fd;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -070060
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 */
65static 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 Reinauer05cbce62013-01-03 14:30:33 -080081 * 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 Bendebury6d18fd02012-09-27 19:24:07 -070083 */
Stefan Reinauer05cbce62013-01-03 14:30:33 -080084static void *mapped_virtual;
Aaron Durbinab180d82014-03-31 11:59:58 -050085static size_t mapped_size;
86
87static inline size_t size_to_mib(size_t sz)
88{
89 return sz >> 20;
90}
91
92static 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
105static void *map_memory_size(u64 physical, size_t size)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700106{
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800107 void *v;
108 off_t p;
Stefan Reinauer7f681502013-06-19 15:39:09 -0700109 u64 page = getpagesize();
Aaron Durbinab180d82014-03-31 11:59:58 -0500110 size_t padding;
111
112 if (mapped_virtual != NULL)
113 unmap_memory();
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800114
115 /* Mapped memory must be aligned to page size */
116 p = physical & ~(page - 1);
Aaron Durbinab180d82014-03-31 11:59:58 -0500117 padding = physical & (page-1);
118 size += padding;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800119
Aaron Durbinab180d82014-03-31 11:59:58 -0500120 debug("Mapping %zuMB of physical memory at 0x%jx.\n",
121 size_to_mib(size), (intmax_t)p);
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800122
Julius Werner337de4c2014-06-16 23:02:03 -0700123 v = mmap(NULL, size, PROT_READ, MAP_SHARED, mem_fd, p);
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800124
125 if (v == MAP_FAILED) {
126 fprintf(stderr, "Failed to mmap /dev/mem: %s\n",
127 strerror(errno));
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700128 exit(1);
129 }
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800130
131 /* Remember what we actually mapped ... */
132 mapped_virtual = v;
Aaron Durbinab180d82014-03-31 11:59:58 -0500133 mapped_size = size;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800134
135 /* ... but return address to the physical memory that was requested */
Stefan Reinauera9c83612013-07-16 17:47:35 -0700136 if (padding)
Aaron Durbinab180d82014-03-31 11:59:58 -0500137 debug(" ... padding virtual address with 0x%zx bytes.\n",
Stefan Reinauera9c83612013-07-16 17:47:35 -0700138 padding);
139 v += padding;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800140
141 return v;
142}
143
Aaron Durbinab180d82014-03-31 11:59:58 -0500144static void *map_memory(u64 physical)
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800145{
Aaron Durbinab180d82014-03-31 11:59:58 -0500146 return map_memory_size(physical, MAP_BYTES);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700147}
148
149/*
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800150 * 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 Bendebury6d18fd02012-09-27 19:24:07 -0700153 *
154 * Returns pointer to a memory buffer containg the timestamp table or zero if
155 * none found.
156 */
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800157
158static struct lb_cbmem_ref timestamps;
159static struct lb_cbmem_ref console;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800160static struct lb_memory_range cbmem;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800161
Stefan Reinauer8c594772013-04-19 14:22:29 -0700162/* 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 */
169static 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 Reinauera9c83612013-07-16 17:47:35 -0700178 debug(" cbmem_addr = %" PRIx64 "\n", ret.cbmem_addr);
179
Stefan Reinauer8c594772013-04-19 14:22:29 -0700180 return ret;
181}
182
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800183static int parse_cbtable(u64 address)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700184{
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800185 int i, found = 0;
186 void *buf;
187
Nico Huber8e4bb9282013-05-26 18:17:54 +0200188 debug("Looking for coreboot table at %" PRIx64 "\n", address);
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800189 buf = map_memory(address);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700190
191 /* look at every 16 bytes within 4K of the base */
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800192
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700193 for (i = 0; i < 0x1000; i += 0x10) {
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800194 struct lb_header *lbh;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700195 struct lb_record* lbr_p;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800196 void *lbtable;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700197 int j;
198
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800199 lbh = (struct lb_header *)(buf + i);
200 if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) ||
201 !lbh->header_bytes ||
202 ipchcksum(lbh, sizeof(*lbh))) {
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700203 continue;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700204 }
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800205 lbtable = buf + i + lbh->header_bytes;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700206
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800207 if (ipchcksum(lbtable, lbh->table_bytes) !=
208 lbh->table_checksum) {
209 debug("Signature found, but wrong checksum.\n");
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700210 continue;
211 }
212
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800213 found = 1;
214 debug("Found!\n");
215
216 for (j = 0; j < lbh->table_bytes; j += lbr_p->size) {
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800217 lbr_p = (struct lb_record*) ((char *)lbtable + j);
218 debug(" coreboot table entry 0x%02x\n", lbr_p->tag);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700219 switch (lbr_p->tag) {
Stefan Reinauerc0199072013-01-07 16:26:10 -0800220 case LB_TAG_MEMORY: {
221 int i = 0;
222 debug(" Found memory map.\n");
223 struct lb_memory *memory =
224 (struct lb_memory *)lbr_p;
Paul Menzel747c07f2014-10-17 13:46:12 +0200225 while ((char *)&memory->map[i] < ((char *)lbr_p
Stefan Reinauerc0199072013-01-07 16:26:10 -0800226 + lbr_p->size)) {
227 if (memory->map[i].type == LB_MEM_TABLE) {
228 debug(" LB_MEM_TABLE found.\n");
229 /* The last one found is CBMEM */
230 cbmem = memory->map[i];
231 }
232 i++;
233 }
234 continue;
235 }
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700236 case LB_TAG_TIMESTAMPS: {
Stefan Reinauerd7144dc2013-01-07 15:25:37 -0800237 debug(" Found timestamp table.\n");
Stefan Reinauer8c594772013-04-19 14:22:29 -0700238 timestamps = parse_cbmem_ref((struct lb_cbmem_ref *) lbr_p);
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800239 continue;
240 }
241 case LB_TAG_CBMEM_CONSOLE: {
Stefan Reinauerd7144dc2013-01-07 15:25:37 -0800242 debug(" Found cbmem console.\n");
Stefan Reinauer8c594772013-04-19 14:22:29 -0700243 console = parse_cbmem_ref((struct lb_cbmem_ref *) lbr_p);
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800244 continue;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700245 }
246 case LB_TAG_FORWARD: {
247 /*
248 * This is a forwarding entry - repeat the
249 * search at the new address.
250 */
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800251 struct lb_forward lbf_p =
252 *(struct lb_forward *) lbr_p;
Stefan Reinauerd7144dc2013-01-07 15:25:37 -0800253 debug(" Found forwarding entry.\n");
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800254 unmap_memory();
255 return parse_cbtable(lbf_p.forward);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700256 }
257 default:
258 break;
259 }
260
261 }
262 }
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800263 unmap_memory();
264
265 return found;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700266}
267
Stefan Reinauerd8ef9e92013-07-31 15:44:37 -0700268#if defined(__i386__) || defined(__x86_64__)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700269/*
270 * read CPU frequency from a sysfs file, return an frequency in Kilohertz as
271 * an int or exit on any error.
272 */
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800273static u64 get_cpu_freq_KHz(void)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700274{
275 FILE *cpuf;
276 char freqs[100];
277 int size;
278 char *endp;
279 u64 rv;
280
281 const char* freq_file =
282 "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
283
284 cpuf = fopen(freq_file, "r");
285 if (!cpuf) {
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800286 fprintf(stderr, "Could not open %s: %s\n",
287 freq_file, strerror(errno));
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700288 exit(1);
289 }
290
291 memset(freqs, 0, sizeof(freqs));
292 size = fread(freqs, 1, sizeof(freqs), cpuf);
293 if (!size || (size == sizeof(freqs))) {
294 fprintf(stderr, "Wrong number of bytes(%d) read from %s\n",
295 size, freq_file);
296 exit(1);
297 }
298 fclose(cpuf);
299 rv = strtoull(freqs, &endp, 10);
300
301 if (*endp == '\0' || *endp == '\n')
302 return rv;
303 fprintf(stderr, "Wrong formatted value ^%s^ read from %s\n",
304 freqs, freq_file);
305 exit(1);
306}
307
Stefan Reinauerd8ef9e92013-07-31 15:44:37 -0700308/* On x86 platforms timestamps are stored
309 * in CPU cycles (from rdtsc). Hence the
310 * timestamp divider is the CPU frequency
311 * in MHz.
312 */
313u64 arch_convert_raw_ts_entry(u64 ts)
314{
315 static u64 cpu_freq_mhz = 0;
316
317 if (!cpu_freq_mhz)
318 cpu_freq_mhz = get_cpu_freq_KHz() / 1000;
319
320 return ts / cpu_freq_mhz;
321}
322
323#else
324
325/* On non-x86 platforms the timestamp entries
326 * are not in clock cycles but in usecs
327 */
328u64 arch_convert_raw_ts_entry(u64 ts)
329{
330 return ts;
331}
332#endif
333
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700334/*
335 * Print an integer in 'normalized' form - with commas separating every three
336 * decimal orders. The 'comma' parameter indicates if a comma is needed after
337 * the value is printed.
338 */
339static void print_norm(u64 v, int comma)
340{
341 int first_triple = 1;
342
343 if (v > 1000) {
344 /* print the higher order sections first */
345 print_norm(v / 1000, 1);
346 first_triple = 0;
347 }
348 if (first_triple)
349 printf("%d", (u32)(v % 1000));
350 else
351 printf("%3.3d", (u32)(v % 1000));
352 if (comma)
353 printf(",");
354}
355
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700356enum additional_timestamp_id {
357 // Depthcharge entry IDs start at 1000.
358 TS_DC_START = 1000,
359
360 TS_RO_PARAMS_INIT = 1001,
361 TS_RO_VB_INIT = 1002,
362 TS_RO_VB_SELECT_FIRMWARE = 1003,
363 TS_RO_VB_SELECT_AND_LOAD_KERNEL = 1004,
364
365 TS_RW_VB_SELECT_AND_LOAD_KERNEL = 1010,
366
367 TS_VB_SELECT_AND_LOAD_KERNEL = 1020,
368
369 TS_CROSSYSTEM_DATA = 1100,
370 TS_START_KERNEL = 1101
371};
372
373static const struct timestamp_id_to_name {
374 u32 id;
375 const char *name;
376} timestamp_ids[] = {
377 { TS_START_ROMSTAGE, "start of rom stage" },
378 { TS_BEFORE_INITRAM, "before ram initialization" },
379 { TS_AFTER_INITRAM, "after ram initialization" },
380 { TS_END_ROMSTAGE, "end of romstage" },
381 { TS_START_VBOOT, "start of verified boot" },
382 { TS_END_VBOOT, "end of verified boot" },
383 { TS_START_COPYRAM, "start of copying ram stage" },
384 { TS_END_COPYRAM, "end of copying ram stage" },
385 { TS_START_RAMSTAGE, "start of ramstage" },
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" },
396 { TS_DC_START, "depthcharge start" },
397 { TS_RO_PARAMS_INIT, "RO parameter init" },
398 { TS_RO_VB_INIT, "RO vboot init" },
399 { TS_RO_VB_SELECT_FIRMWARE, "RO vboot select firmware" },
400 { TS_RO_VB_SELECT_AND_LOAD_KERNEL, "RO vboot select&load kernel" },
401 { TS_RW_VB_SELECT_AND_LOAD_KERNEL, "RW vboot select&load kernel" },
402 { TS_VB_SELECT_AND_LOAD_KERNEL, "vboot select&load kernel" },
403 { TS_CROSSYSTEM_DATA, "crossystem data" },
404 { TS_START_KERNEL, "start kernel" }
405};
406
407void timestamp_print_entry(uint32_t id, uint64_t stamp, uint64_t prev_stamp)
408{
409 int i;
410 const char *name;
411
412 name = "<unknown>";
413 for (i = 0; i < ARRAY_SIZE(timestamp_ids); i++) {
414 if (timestamp_ids[i].id == id) {
415 name = timestamp_ids[i].name;
416 break;
417 }
418 }
419
420 printf("%4d:", id);
421 printf("%-30s", name);
422 print_norm(arch_convert_raw_ts_entry(stamp), 0);
423 if (prev_stamp) {
424 printf(" (");
425 print_norm(arch_convert_raw_ts_entry(stamp
426 - prev_stamp), 0);
427 printf(")");
428 }
429 printf("\n");
430}
431
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700432/* dump the timestamp table */
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800433static void dump_timestamps(void)
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700434{
435 int i;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800436 struct timestamp_table *tst_p;
437
438 if (timestamps.tag != LB_TAG_TIMESTAMPS) {
439 fprintf(stderr, "No timestamps found in coreboot table.\n");
440 return;
441 }
442
443 tst_p = (struct timestamp_table *)
444 map_memory((unsigned long)timestamps.cbmem_addr);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700445
446 printf("%d entries total:\n\n", tst_p->num_entries);
447 for (i = 0; i < tst_p->num_entries; i++) {
448 const struct timestamp_entry *tse_p = tst_p->entries + i;
Stefan Reinauer0db924d2013-08-09 11:06:11 -0700449 timestamp_print_entry(tse_p->entry_id, tse_p->entry_stamp,
450 i ? tse_p[-1].entry_stamp : 0);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700451 }
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800452
453 unmap_memory();
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700454}
455
Stefan Reinauer19f87562013-01-07 13:37:12 -0800456/* dump the cbmem console */
457static void dump_console(void)
458{
459 void *console_p;
460 char *console_c;
461 uint32_t size;
Vladimir Serbinenkof4a0d012013-03-30 12:15:12 +0100462 uint32_t cursor;
Stefan Reinauer19f87562013-01-07 13:37:12 -0800463
464 if (console.tag != LB_TAG_CBMEM_CONSOLE) {
465 fprintf(stderr, "No console found in coreboot table.\n");
466 return;
467 }
468
469 console_p = map_memory((unsigned long)console.cbmem_addr);
470 /* The in-memory format of the console area is:
471 * u32 size
472 * u32 cursor
473 * char console[size]
474 * Hence we have to add 8 to get to the actual console string.
475 */
Gabe Black06b13a32013-08-09 00:40:06 -0700476 size = ((uint32_t *)console_p)[0];
477 cursor = ((uint32_t *)console_p)[1];
Vladimir Serbinenkof4a0d012013-03-30 12:15:12 +0100478 /* Cursor continues to go on even after no more data fits in
479 * the buffer but the data is dropped in this case.
480 */
481 if (size > cursor)
482 size = cursor;
Stefan Reinauer19f87562013-01-07 13:37:12 -0800483 console_c = malloc(size + 1);
484 if (!console_c) {
485 fprintf(stderr, "Not enough memory for console.\n");
486 exit(1);
487 }
488
Aaron Durbinab180d82014-03-31 11:59:58 -0500489 console_p = map_memory_size((unsigned long)console.cbmem_addr,
490 size + sizeof(size) + sizeof(cursor));
Stefan Reinauer19f87562013-01-07 13:37:12 -0800491 memcpy(console_c, console_p + 8, size);
492 console_c[size] = 0;
Gabe Black06b13a32013-08-09 00:40:06 -0700493 console_c[cursor] = 0;
Stefan Reinauer19f87562013-01-07 13:37:12 -0800494
Vladimir Serbinenkof4a0d012013-03-30 12:15:12 +0100495 printf("%s\n", console_c);
496 if (size < cursor)
497 printf("%d %s lost\n", cursor - size,
498 (cursor - size) == 1 ? "byte":"bytes");
Stefan Reinauer19f87562013-01-07 13:37:12 -0800499
500 free(console_c);
501
502 unmap_memory();
503}
504
Stefan Reinauera9c83612013-07-16 17:47:35 -0700505static void hexdump(unsigned long memory, int length)
506{
507 int i;
508 uint8_t *m;
509 int all_zero = 0;
510
511 m = map_memory((intptr_t)memory);
512
513 if (length > MAP_BYTES) {
514 printf("Truncating hex dump from %d to %d bytes\n\n",
515 length, MAP_BYTES);
516 length = MAP_BYTES;
517 }
518
519 for (i = 0; i < length; i += 16) {
520 int j;
521
522 all_zero++;
523 for (j = 0; j < 16; j++) {
524 if(m[i+j] != 0) {
525 all_zero = 0;
526 break;
527 }
528 }
529
530 if (all_zero < 2) {
531 printf("%08lx:", memory + i);
532 for (j = 0; j < 16; j++)
533 printf(" %02x", m[i+j]);
534 printf(" ");
535 for (j = 0; j < 16; j++)
536 printf("%c", isprint(m[i+j]) ? m[i+j] : '.');
537 printf("\n");
538 } else if (all_zero == 2) {
539 printf("...\n");
540 }
541 }
542
543 unmap_memory();
544}
545
546static void dump_cbmem_hex(void)
547{
548 if (cbmem.type != LB_MEM_TABLE) {
549 fprintf(stderr, "No coreboot CBMEM area found!\n");
550 return;
551 }
552
553 hexdump(unpack_lb64(cbmem.start), unpack_lb64(cbmem.size));
554}
555
556/* The root region is at least DYN_CBMEM_ALIGN_SIZE . */
557#define DYN_CBMEM_ALIGN_SIZE (4096)
558#define ROOT_MIN_SIZE DYN_CBMEM_ALIGN_SIZE
559#define CBMEM_POINTER_MAGIC 0xc0389479
560#define CBMEM_ENTRY_MAGIC ~(CBMEM_POINTER_MAGIC)
561
562struct cbmem_root_pointer {
563 uint32_t magic;
564 uint32_t root;
565} __attribute__((packed));
566
567struct dynamic_cbmem_entry {
568 uint32_t magic;
569 uint32_t start;
570 uint32_t size;
571 uint32_t id;
572} __attribute__((packed));
573
574struct cbmem_root {
575 uint32_t max_entries;
576 uint32_t num_entries;
577 uint32_t locked;
578 uint32_t size;
579 struct dynamic_cbmem_entry entries[0];
580} __attribute__((packed));
581
Stefan Reinauerc0199072013-01-07 16:26:10 -0800582#define CBMEM_MAGIC 0x434f5245
583#define MAX_CBMEM_ENTRIES 16
584
585struct cbmem_entry {
586 uint32_t magic;
587 uint32_t id;
588 uint64_t base;
589 uint64_t size;
Stefan Reinauera9c83612013-07-16 17:47:35 -0700590} __attribute__((packed));
591
Vadim Bendebury8b143c52014-05-14 10:12:55 -0700592static const struct cbmem_id_to_name cbmem_ids[] = { CBMEM_ID_TO_NAME_TABLE };
Stefan Reinauerc0199072013-01-07 16:26:10 -0800593
Stefan Reinauera9c83612013-07-16 17:47:35 -0700594void cbmem_print_entry(int n, uint32_t id, uint64_t base, uint64_t size)
595{
596 int i;
597 const char *name;
598
599 name = NULL;
600 for (i = 0; i < ARRAY_SIZE(cbmem_ids); i++) {
601 if (cbmem_ids[i].id == id) {
602 name = cbmem_ids[i].name;
603 break;
604 }
605 }
606
607 printf("%2d. ", n);
608 if (name == NULL)
609 printf("%08x ", id);
610 else
611 printf("%s", name);
612 printf(" %08" PRIx64 " ", base);
613 printf(" %08" PRIx64 "\n", size);
614}
615
616static void dump_static_cbmem_toc(struct cbmem_entry *entries)
617{
618 int i;
619
620 printf("CBMEM table of contents:\n");
621 printf(" ID START LENGTH\n");
622
623 for (i=0; i<MAX_CBMEM_ENTRIES; i++) {
624 if (entries[i].magic != CBMEM_MAGIC)
625 break;
626 cbmem_print_entry(i, entries[i].id,
627 entries[i].base, entries[i].size);
628 }
629}
630
631static void dump_dynamic_cbmem_toc(struct cbmem_root *root)
632{
633 int i;
634 debug("CBMEM: max_entries=%d num_entries=%d locked=0x%x, size=%d\n\n",
635 root->max_entries, root->num_entries, root->locked, root->size);
636
637 printf("CBMEM table of contents:\n");
638 printf(" ID START LENGTH\n");
639
640 for (i = 0; i < root->num_entries; i++) {
641 if(root->entries[i].magic != CBMEM_ENTRY_MAGIC)
642 break;
643 cbmem_print_entry(i, root->entries[i].id,
644 root->entries[i].start, root->entries[i].size);
645 }
646}
647
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800648static void dump_cbmem_toc(void)
Stefan Reinauerc0199072013-01-07 16:26:10 -0800649{
Stefan Reinauerc0199072013-01-07 16:26:10 -0800650 uint64_t start;
Stefan Reinauera9c83612013-07-16 17:47:35 -0700651 void *cbmem_area;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800652 struct cbmem_entry *entries;
653
654 if (cbmem.type != LB_MEM_TABLE) {
Stefan Reinauera9c83612013-07-16 17:47:35 -0700655 fprintf(stderr, "No coreboot CBMEM area found!\n");
Stefan Reinauerc0199072013-01-07 16:26:10 -0800656 return;
657 }
658
659 start = unpack_lb64(cbmem.start);
660
Stefan Reinauera9c83612013-07-16 17:47:35 -0700661 cbmem_area = map_memory(start);
662 entries = (struct cbmem_entry *)cbmem_area;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800663
Stefan Reinauera9c83612013-07-16 17:47:35 -0700664 if (entries[0].magic == CBMEM_MAGIC) {
665 dump_static_cbmem_toc(entries);
666 } else {
667 uint64_t rootptr;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800668
Stefan Reinauera9c83612013-07-16 17:47:35 -0700669 rootptr = unpack_lb64(cbmem.start) + unpack_lb64(cbmem.size);
670 rootptr &= ~(DYN_CBMEM_ALIGN_SIZE - 1);
671 rootptr -= sizeof(struct cbmem_root_pointer);
672 unmap_memory();
673 struct cbmem_root_pointer *r =
674 (struct cbmem_root_pointer *)map_memory(rootptr);
675 if (r->magic == CBMEM_POINTER_MAGIC) {
676 struct cbmem_root *root;
677 uint64_t rootaddr = r->root;
678 unmap_memory();
679 /* Note that this only works because our default mmap
680 * size is 1MiB which happens to be larger than the
681 * root entry size which is default to be 4KiB.
682 */
683 root = (struct cbmem_root *)map_memory(rootaddr);
684 dump_dynamic_cbmem_toc(root);
685 } else
686 fprintf(stderr, "No valid coreboot CBMEM root pointer found.\n");
Stefan Reinauerc0199072013-01-07 16:26:10 -0800687 }
Stefan Reinauera9c83612013-07-16 17:47:35 -0700688
Stefan Reinauerc0199072013-01-07 16:26:10 -0800689 unmap_memory();
690}
Stefan Reinauer19f87562013-01-07 13:37:12 -0800691
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800692#define COVERAGE_MAGIC 0x584d4153
693struct file {
694 uint32_t magic;
695 uint32_t next;
696 uint32_t filename;
697 uint32_t data;
698 int offset;
699 int len;
700};
701
702static int mkpath(char *path, mode_t mode)
703{
704 assert (path && *path);
705 char *p;
706 for (p = strchr(path+1, '/'); p; p = strchr(p + 1, '/')) {
707 *p = '\0';
708 if (mkdir(path, mode) == -1) {
709 if (errno != EEXIST) {
710 *p = '/';
711 return -1;
712 }
713 }
714 *p = '/';
715 }
716 return 0;
717}
718
719static void dump_coverage(void)
720{
721 int i, found = 0;
722 uint64_t start;
723 struct cbmem_entry *entries;
724 void *coverage;
725 unsigned long phys_offset;
726#define phys_to_virt(x) ((void *)(unsigned long)(x) + phys_offset)
727
728 if (cbmem.type != LB_MEM_TABLE) {
729 fprintf(stderr, "No coreboot table area found!\n");
730 return;
731 }
732
733 start = unpack_lb64(cbmem.start);
734
735 entries = (struct cbmem_entry *)map_memory(start);
736
737 for (i=0; i<MAX_CBMEM_ENTRIES; i++) {
738 if (entries[i].magic != CBMEM_MAGIC)
739 break;
740 if (entries[i].id == CBMEM_ID_COVERAGE) {
741 found = 1;
742 break;
743 }
744 }
745
746 if (!found) {
747 unmap_memory();
748 fprintf(stderr, "No coverage information found in"
749 " CBMEM area.\n");
750 return;
751 }
752
753 start = entries[i].base;
754 unmap_memory();
755 /* Map coverage area */
756 coverage = map_memory(start);
757 phys_offset = (unsigned long)coverage - (unsigned long)start;
758
759 printf("Dumping coverage data...\n");
760
761 struct file *file = (struct file *)coverage;
762 while (file && file->magic == COVERAGE_MAGIC) {
763 FILE *f;
764 char *filename;
765
766 debug(" -> %s\n", (char *)phys_to_virt(file->filename));
767 filename = strdup((char *)phys_to_virt(file->filename));
768 if (mkpath(filename, 0755) == -1) {
769 perror("Directory for coverage data could "
770 "not be created");
771 exit(1);
772 }
773 f = fopen(filename, "wb");
774 if (!f) {
775 printf("Could not open %s: %s\n",
776 filename, strerror(errno));
777 exit(1);
778 }
779 if (fwrite((void *)phys_to_virt(file->data),
780 file->len, 1, f) != 1) {
781 printf("Could not write to %s: %s\n",
782 filename, strerror(errno));
783 exit(1);
784 }
785 fclose(f);
786 free(filename);
787
788 if (file->next)
789 file = (struct file *)phys_to_virt(file->next);
790 else
791 file = NULL;
792 }
793 unmap_memory();
794}
795
796static void print_version(void)
Stefan Reinauer1e0e5562013-01-02 15:43:56 -0800797{
798 printf("cbmem v%s -- ", CBMEM_VERSION);
799 printf("Copyright (C) 2012 The ChromiumOS Authors. All rights reserved.\n\n");
800 printf(
801 "This program is free software: you can redistribute it and/or modify\n"
802 "it under the terms of the GNU General Public License as published by\n"
803 "the Free Software Foundation, version 2 of the License.\n\n"
804 "This program is distributed in the hope that it will be useful,\n"
805 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
806 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
807 "GNU General Public License for more details.\n\n"
808 "You should have received a copy of the GNU General Public License\n"
809 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
810}
811
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800812static void print_usage(const char *name)
Stefan Reinauer1e0e5562013-01-02 15:43:56 -0800813{
Stefan Reinauera9c83612013-07-16 17:47:35 -0700814 printf("usage: %s [-cCltxVvh?]\n", name);
Stefan Reinauer1e0e5562013-01-02 15:43:56 -0800815 printf("\n"
Stefan Reinauer19f87562013-01-07 13:37:12 -0800816 " -c | --console: print cbmem console\n"
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800817 " -C | --coverage: dump coverage information\n"
Stefan Reinauerc0199072013-01-07 16:26:10 -0800818 " -l | --list: print cbmem table of contents\n"
Stefan Reinauera9c83612013-07-16 17:47:35 -0700819 " -x | --hexdump: print hexdump of cbmem area\n"
Stefan Reinauer19f87562013-01-07 13:37:12 -0800820 " -t | --timestamps: print timestamp information\n"
821 " -V | --verbose: verbose (debugging) output\n"
Stefan Reinauer1e0e5562013-01-02 15:43:56 -0800822 " -v | --version: print the version\n"
823 " -h | --help: print this help\n"
824 "\n");
825 exit(1);
826}
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700827
Julius Werner337de4c2014-06-16 23:02:03 -0700828#ifdef __arm__
829static void dt_update_cells(const char *name, int *addr_cells_ptr,
830 int *size_cells_ptr)
831{
832 if (*addr_cells_ptr >= 0 && *size_cells_ptr >= 0)
833 return;
834
835 int buffer;
836 size_t nlen = strlen(name);
837 char *prop = alloca(nlen + sizeof("/#address-cells"));
838 strcpy(prop, name);
839
840 if (*addr_cells_ptr < 0) {
841 strcpy(prop + nlen, "/#address-cells");
842 int fd = open(prop, O_RDONLY);
843 if (fd < 0 && errno != ENOENT) {
844 perror(prop);
845 } else if (fd >= 0) {
846 if (read(fd, &buffer, sizeof(int)) < 0)
847 perror(prop);
848 else
849 *addr_cells_ptr = ntohl(buffer);
850 close(fd);
851 }
852 }
853
854 if (*size_cells_ptr < 0) {
855 strcpy(prop + nlen, "/#size-cells");
856 int fd = open(prop, O_RDONLY);
857 if (fd < 0 && errno != ENOENT) {
858 perror(prop);
859 } else if (fd >= 0) {
860 if (read(fd, &buffer, sizeof(int)) < 0)
861 perror(prop);
862 else
863 *size_cells_ptr = ntohl(buffer);
864 close(fd);
865 }
866 }
867}
868
869static char *dt_find_compat(const char *parent, const char *compat,
870 int *addr_cells_ptr, int *size_cells_ptr)
871{
872 char *ret = NULL;
873 struct dirent *entry;
874 DIR *dir;
875
876 if (!(dir = opendir(parent))) {
877 perror(parent);
878 return NULL;
879 }
880
881 /* Loop through all files in the directory (DT node). */
882 while ((entry = readdir(dir))) {
883 /* We only care about compatible props or subnodes. */
884 if (entry->d_name[0] == '.' || !((entry->d_type & DT_DIR) ||
885 !strcmp(entry->d_name, "compatible")))
886 continue;
887
888 /* Assemble the file name (on the stack, for speed). */
889 size_t plen = strlen(parent);
890 char *name = alloca(plen + strlen(entry->d_name) + 2);
891
892 strcpy(name, parent);
893 name[plen] = '/';
894 strcpy(name + plen + 1, entry->d_name);
895
896 /* If it's a subnode, recurse. */
897 if (entry->d_type & DT_DIR) {
898 ret = dt_find_compat(name, compat, addr_cells_ptr,
899 size_cells_ptr);
900
901 /* There is only one matching node to find, abort. */
902 if (ret) {
903 /* Gather cells values on the way up. */
904 dt_update_cells(parent, addr_cells_ptr,
905 size_cells_ptr);
906 break;
907 }
908 continue;
909 }
910
911 /* If it's a compatible string, see if it's the right one. */
912 int fd = open(name, O_RDONLY);
913 int clen = strlen(compat);
914 char *buffer = alloca(clen + 1);
915
916 if (fd < 0) {
917 perror(name);
918 continue;
919 }
920
921 if (read(fd, buffer, clen + 1) < 0) {
922 perror(name);
923 close(fd);
924 continue;
925 }
926 close(fd);
927
928 if (!strcmp(compat, buffer)) {
929 /* Initialize these to "unset" for the way up. */
930 *addr_cells_ptr = *size_cells_ptr = -1;
931
932 /* Can't leave string on the stack or we'll lose it! */
933 ret = strdup(parent);
934 break;
935 }
936 }
937
938 closedir(dir);
939 return ret;
940}
941#endif /* __arm__ */
942
Vadim Bendebury6d18fd02012-09-27 19:24:07 -0700943int main(int argc, char** argv)
944{
Stefan Reinauer19f87562013-01-07 13:37:12 -0800945 int print_defaults = 1;
946 int print_console = 0;
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800947 int print_coverage = 0;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800948 int print_list = 0;
Stefan Reinauera9c83612013-07-16 17:47:35 -0700949 int print_hexdump = 0;
Stefan Reinauer19f87562013-01-07 13:37:12 -0800950 int print_timestamps = 0;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800951
Stefan Reinauer1e0e5562013-01-02 15:43:56 -0800952 int opt, option_index = 0;
953 static struct option long_options[] = {
Stefan Reinauer19f87562013-01-07 13:37:12 -0800954 {"console", 0, 0, 'c'},
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800955 {"coverage", 0, 0, 'C'},
Stefan Reinauerc0199072013-01-07 16:26:10 -0800956 {"list", 0, 0, 'l'},
Stefan Reinauer19f87562013-01-07 13:37:12 -0800957 {"timestamps", 0, 0, 't'},
Stefan Reinauera9c83612013-07-16 17:47:35 -0700958 {"hexdump", 0, 0, 'x'},
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800959 {"verbose", 0, 0, 'V'},
Stefan Reinauer1e0e5562013-01-02 15:43:56 -0800960 {"version", 0, 0, 'v'},
961 {"help", 0, 0, 'h'},
962 {0, 0, 0, 0}
963 };
Stefan Reinauera9c83612013-07-16 17:47:35 -0700964 while ((opt = getopt_long(argc, argv, "cCltxVvh?",
Stefan Reinauer1e0e5562013-01-02 15:43:56 -0800965 long_options, &option_index)) != EOF) {
966 switch (opt) {
Stefan Reinauer19f87562013-01-07 13:37:12 -0800967 case 'c':
968 print_console = 1;
969 print_defaults = 0;
970 break;
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800971 case 'C':
972 print_coverage = 1;
973 print_defaults = 0;
974 break;
Stefan Reinauerc0199072013-01-07 16:26:10 -0800975 case 'l':
976 print_list = 1;
977 print_defaults = 0;
978 break;
Stefan Reinauera9c83612013-07-16 17:47:35 -0700979 case 'x':
980 print_hexdump = 1;
981 print_defaults = 0;
982 break;
Stefan Reinauer19f87562013-01-07 13:37:12 -0800983 case 't':
984 print_timestamps = 1;
985 print_defaults = 0;
986 break;
Stefan Reinauer05cbce62013-01-03 14:30:33 -0800987 case 'V':
988 verbose = 1;
989 break;
Stefan Reinauer1e0e5562013-01-02 15:43:56 -0800990 case 'v':
991 print_version();
992 exit(0);
993 break;
994 case 'h':
995 case '?':
996 default:
997 print_usage(argv[0]);
998 exit(0);
999 break;
1000 }
1001 }
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001002
Julius Werner337de4c2014-06-16 23:02:03 -07001003 mem_fd = open("/dev/mem", O_RDONLY, 0);
1004 if (mem_fd < 0) {
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001005 fprintf(stderr, "Failed to gain memory access: %s\n",
1006 strerror(errno));
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001007 return 1;
1008 }
1009
Stefan Reinauer7f681502013-06-19 15:39:09 -07001010#ifdef __arm__
Julius Werner337de4c2014-06-16 23:02:03 -07001011 int addr_cells, size_cells;
1012 char *coreboot_node = dt_find_compat("/proc/device-tree", "coreboot",
1013 &addr_cells, &size_cells);
Stefan Reinauer7f681502013-06-19 15:39:09 -07001014
Julius Werner337de4c2014-06-16 23:02:03 -07001015 if (!coreboot_node) {
1016 fprintf(stderr, "Could not find 'coreboot' compatible node!\n");
Stefan Reinauer7f681502013-06-19 15:39:09 -07001017 return 1;
1018 }
1019
Julius Werner337de4c2014-06-16 23:02:03 -07001020 if (addr_cells < 0) {
1021 fprintf(stderr, "Warning: no #address-cells node in tree!\n");
1022 addr_cells = 1;
1023 }
1024
1025 int nlen = strlen(coreboot_node);
1026 char *reg = alloca(nlen + sizeof("/reg"));
1027
1028 strcpy(reg, coreboot_node);
1029 strcpy(reg + nlen, "/reg");
1030 free(coreboot_node);
1031
1032 int fd = open(reg, O_RDONLY);
1033 if (fd < 0) {
1034 perror(reg);
Stefan Reinauer7f681502013-06-19 15:39:09 -07001035 return 1;
1036 }
Stefan Reinauer7f681502013-06-19 15:39:09 -07001037
Julius Werner337de4c2014-06-16 23:02:03 -07001038 int i;
1039 u8 *baseaddr_buffer = alloca(addr_cells * 4);
1040 if (read(fd, baseaddr_buffer, addr_cells * 4) < 0) {
1041 perror(reg);
1042 return 1;
1043 }
1044 close(fd);
1045
1046 /* No variable-length byte swap function anywhere in C... how sad. */
1047 u64 baseaddr = 0;
1048 for (i = 0; i < addr_cells * 4; i++) {
1049 baseaddr <<= 8;
1050 baseaddr |= baseaddr_buffer[i];
1051 }
1052
1053 parse_cbtable(baseaddr);
Stefan Reinauer7f681502013-06-19 15:39:09 -07001054#else
1055 int j;
1056 static const int possible_base_addresses[] = { 0, 0xf0000 };
1057
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001058 /* Find and parse coreboot table */
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001059 for (j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) {
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001060 if (parse_cbtable(possible_base_addresses[j]))
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001061 break;
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001062 }
Stefan Reinauer7f681502013-06-19 15:39:09 -07001063#endif
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001064
Stefan Reinauer19f87562013-01-07 13:37:12 -08001065 if (print_console)
1066 dump_console();
1067
Stefan Reinauerd37ab452012-12-18 16:23:28 -08001068 if (print_coverage)
1069 dump_coverage();
1070
Stefan Reinauerc0199072013-01-07 16:26:10 -08001071 if (print_list)
1072 dump_cbmem_toc();
1073
Stefan Reinauera9c83612013-07-16 17:47:35 -07001074 if (print_hexdump)
1075 dump_cbmem_hex();
1076
Stefan Reinauer19f87562013-01-07 13:37:12 -08001077 if (print_defaults || print_timestamps)
Stefan Reinauer05cbce62013-01-03 14:30:33 -08001078 dump_timestamps();
1079
Julius Werner337de4c2014-06-16 23:02:03 -07001080 close(mem_fd);
Vadim Bendebury6d18fd02012-09-27 19:24:07 -07001081 return 0;
1082}