Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
/*
2
 * Simple tool to dump the AP_Var contents from an EEPROM dump
3
 */
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <stdint.h>
7
 
8
uint8_t eeprom[0x1000];
9
 
10
#pragma pack(1)
11
 
12
struct EEPROM_header {
13
  uint16_t    magic;
14
  uint8_t     revision;
15
  uint8_t     spare;
16
};
17
 
18
static const uint16_t   k_EEPROM_magic      = 0x5041;
19
static const uint16_t   k_EEPROM_revision   = 2;
20
 
21
struct Var_header {
22
  uint8_t    size:6;
23
  uint8_t    spare:2;
24
  uint8_t    key;
25
};
26
 
27
static const uint8_t k_key_sentinel = 0xff;
28
 
29
void
30
fail(const char *why)
31
{
32
  fprintf(stderr, "ERROR: %s\n", why);
33
  exit(1);
34
}
35
 
36
int
37
main(int argc, char *argv[])
38
{
39
  FILE                  *fp;
40
  struct EEPROM_header  *header;
41
  struct Var_header     *var;
42
  unsigned              index;
43
  unsigned              i;
44
 
45
  if (argc != 2) {
46
    fail("missing EEPROM file name");
47
  }
48
  if (NULL == (fp = fopen(argv[1], "rb"))) {
49
    fail("can't open EEPROM file");
50
  }
51
  if (1 != fread(eeprom, sizeof(eeprom), 1, fp)) {
52
    fail("can't read EEPROM file");
53
  }
54
  fclose(fp);
55
 
56
  header = (struct EEPROM_header *)&eeprom[0];
57
  if (header->magic != k_EEPROM_magic) {
58
    fail("bad magic in EEPROM file");
59
  }
60
  if (header->revision != 2) {
61
    fail("unsupported EEPROM format revision");
62
  }
63
  printf("Header OK\n");
64
 
65
  index = sizeof(*header);
66
  for (;;) {
67
    var = (struct Var_header *)&eeprom[index];
68
    if (var->key == k_key_sentinel) {
69
      printf("end sentinel at %u\n", index);
70
      break;
71
    }
72
    printf("%04x: key %u size %d\n ", index, var->key, var->size + 1);
73
    index += sizeof(*var);
74
    for (i = 0; i <= var->size; i++) {
75
      printf(" %02x", eeprom[index + i]);
76
    }
77
    printf("\n");
78
    index += var->size + 1;
79
    if (index >= sizeof(eeprom)) {
80
      fflush(stdout);
81
      fail("missing end sentinel");
82
    }
83
  }
84
}