syslinux/com32/sysdump/main.c
<<
>>
Prefs
   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
  25const char program[] = "sysdump";
  26const char version[] = "SYSDUMP " VERSION_STR " " DATE "\n";
  27
  28__noreturn die(const char *msg)
  29{
  30    printf("%s: %s\n", program, msg);
  31    exit(1);
  32}
  33
  34static 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
  52static struct upload_backend *upload_backends[] =
  53{
  54    &upload_tftp,
  55    &upload_ymodem,
  56    &upload_srec,
  57    NULL
  58};
  59
  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
  71int main(int argc, char *argv[])
  72{
  73    struct upload_backend **bep, *be;
  74
  75    openconsole(&dev_null_r, &dev_stdcon_w);
  76    fputs(version, stdout);
  77
  78    if (argc < 2)
  79        usage();
  80
  81    for (bep = upload_backends ; (be = *bep) ; bep++) {
  82        if (!strcmp(be->name, argv[1]))
  83            break;
  84    }
  85
  86    if (!be || argc < be->minargs + 2)
  87        usage();
  88
  89    /* Do this as early as possible */
  90    snapshot_lowmem();
  91
  92    printf("Backend: %s\n", be->name);
  93
  94    /* Do the actual data dump */
  95    dump_all(be, (const char **)argv + 2);
  96
  97    return 0;
  98}
  99
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.