• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
4  *   Copyright 2010 Intel Corporation; author: H. Peter Anvin
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9  *   Boston MA 02111-1307, USA; either version 2 of the License, or
10  *   (at your option) any later version; incorporated herein by reference.
11  *
12  * ----------------------------------------------------------------------- */
13 
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
17 #include <stdbool.h>
18 #include <inttypes.h>
19 #include <dprintf.h>
20 #include <console.h>
21 #include <sys/cpu.h>
22 #include <version.h>
23 #include "sysdump.h"
24 
25 const char program[] = "sysdump";
26 const char version[] = "SYSDUMP " VERSION_STR " " DATE "\n";
27 
die(const char * msg)28 __noreturn die(const char *msg)
29 {
30     printf("%s: %s\n", program, msg);
31     exit(1);
32 }
33 
dump_all(struct upload_backend * be,const char * argv[])34 static void dump_all(struct upload_backend *be, const char *argv[])
35 {
36     cpio_init(be, argv);
37 
38     cpio_writefile(be, "sysdump", version, sizeof version-1);
39 
40     dump_memory_map(be);
41     dump_memory(be);
42     dump_dmi(be);
43     dump_acpi(be);
44     dump_cpuid(be);
45     dump_pci(be);
46     dump_vesa_tables(be);
47 
48     cpio_close(be);
49     flush_data(be);
50 }
51 
52 static struct upload_backend *upload_backends[] =
53 {
54     &upload_tftp,
55     &upload_ymodem,
56     &upload_srec,
57     NULL
58 };
59 
usage(void)60 __noreturn usage(void)
61 {
62     struct upload_backend **bep, *be;
63 
64     printf("Usage:\n");
65     for (bep = upload_backends ; (be = *bep) ; bep++)
66 	printf("    %s %s %s\n", program, be->name, be->helpmsg);
67 
68     exit(1);
69 }
70 
main(int argc,char * argv[])71 int main(int argc, char *argv[])
72 {
73     struct upload_backend **bep, *be;
74 
75     fputs(version, stdout);
76 
77     if (argc < 2)
78 	usage();
79 
80     for (bep = upload_backends ; (be = *bep) ; bep++) {
81 	if (!strcmp(be->name, argv[1]))
82 	    break;
83     }
84 
85     if (!be || argc < be->minargs + 2)
86 	usage();
87 
88     /* Do this as early as possible */
89     snapshot_lowmem();
90 
91     printf("Backend: %s\n", be->name);
92 
93     /* Do the actual data dump */
94     dump_all(be, (const char **)argv + 2);
95 
96     return 0;
97 }
98