13 #include "eepromread.h"
16 * Attempt to read the board info from an eeprom on this board.
19 static int board_info_beaglebone(int fd
, i2c_addr_t address
, int flags
,
20 enum device_types device_type
);
21 static int board_info_cape_a0(int fd
, i2c_addr_t address
, int flags
,
22 enum device_types device_type
);
23 static int board_info_cape_a1(int fd
, i2c_addr_t address
, int flags
,
24 enum device_types device_type
);
26 /* Memory Layout of the BeagleBone and BeagleBone Black EEPROM */
27 typedef struct beaglebone_info
29 uint8_t magic_number
[4]; /* Should be 0xaa 0x55 0x33 0xee */
30 char board_name
[8]; /* Warning: strings not NULL terminated */
32 char serial_number
[12];
33 char config
[32]; /* All 0x00 on BeagleBone White */
34 char mac_addrs
[3][6]; /* Not set on BeagleBone White */
37 /* Memory Layout of the Cape EEPROM (A0 Format) - Defined in BBW SRM Rev A5.3 */
38 typedef struct cape_info_a0
40 uint8_t magic_number
[4]; /* Should be 0xaa 0x55 0x33 0xee */
41 char revision
[2]; /* Should be 'A' '0' */
42 char board_name
[32]; /* Warning: strings not NULL terminated */
44 char manufacturer
[16];
55 /* Memory Layout of the Cape EEPROM (A1 Format) - Defined in BBB SRM Rev A5.3 */
56 typedef struct cape_info_a1
58 uint8_t magic_number
[4]; /* Should be 0xaa 0x55 0x33 0xee */
59 char revision
[2]; /* Should be 'A' '1' */
60 char board_name
[32]; /* Warning: strings not NULL terminated */
62 char manufacturer
[16];
74 board_info_beaglebone(int fd
, i2c_addr_t address
, int flags
,
75 enum device_types device_type
)
80 beaglebone_info_t boneinfo
;
82 r
= eeprom_read(fd
, address
, 0x0000, &boneinfo
,
83 sizeof(beaglebone_info_t
), flags
, device_type
);
85 fprintf(stderr
, "Failed to read BeagleBone info r=%d\n", r
);
89 fprintf(stdout
, "%-16s: 0x%x%x%x%x\n", "MAGIC_NUMBER",
90 boneinfo
.magic_number
[0], boneinfo
.magic_number
[1],
91 boneinfo
.magic_number
[2], boneinfo
.magic_number
[3]);
94 memcpy(s
, boneinfo
.board_name
, 8);
95 fprintf(stdout
, "%-16s: %s\n", "BOARD_NAME", s
);
98 memcpy(s
, boneinfo
.version
, 4);
99 fprintf(stdout
, "%-16s: %s\n", "VERSION", s
);
102 memcpy(s
, boneinfo
.serial_number
, 12);
103 fprintf(stdout
, "%-16s: %s\n", "SERIAL_NUMBER", s
);
109 board_info_cape_a0(int fd
, i2c_addr_t address
, int flags
,
110 enum device_types device_type
)
115 cape_info_a0_t capeinfo
;
117 r
= eeprom_read(fd
, address
, 0x0000, &capeinfo
,
118 sizeof(cape_info_a0_t
), flags
, device_type
);
120 fprintf(stderr
, "failed to read cape A0 info r=%d\n", r
);
124 fprintf(stdout
, "%-16s: 0x%x%x%x%x\n", "MAGIC_NUMBER",
125 capeinfo
.magic_number
[0], capeinfo
.magic_number
[1],
126 capeinfo
.magic_number
[2], capeinfo
.magic_number
[3]);
129 memcpy(s
, capeinfo
.revision
, 2);
130 fprintf(stdout
, "%-16s: %s\n", "REVISION", s
);
133 memcpy(s
, capeinfo
.board_name
, 32);
134 fprintf(stdout
, "%-16s: %s\n", "BOARD_NAME", s
);
137 memcpy(s
, capeinfo
.version
, 4);
138 fprintf(stdout
, "%-16s: %s\n", "VERSION", s
);
141 memcpy(s
, capeinfo
.manufacturer
, 16);
142 fprintf(stdout
, "%-16s: %s\n", "MANUFACTURER", s
);
145 memcpy(s
, capeinfo
.partno
, 16);
146 fprintf(stdout
, "%-16s: %s\n", "PART_NUMBER", s
);
149 memcpy(s
, capeinfo
.serial
, 12);
150 fprintf(stdout
, "%-16s: %s\n", "SERIAL", s
);
156 board_info_cape_a1(int fd
, i2c_addr_t address
, int flags
,
157 enum device_types device_type
)
162 cape_info_a1_t capeinfo
;
164 r
= eeprom_read(fd
, address
, 0x0000, &capeinfo
,
165 sizeof(cape_info_a1_t
), flags
, device_type
);
167 fprintf(stderr
, "failed to read cape A0 info r=%d\n", r
);
171 fprintf(stdout
, "%-16s: 0x%x%x%x%x\n", "MAGIC_NUMBER",
172 capeinfo
.magic_number
[0], capeinfo
.magic_number
[1],
173 capeinfo
.magic_number
[2], capeinfo
.magic_number
[3]);
176 memcpy(s
, capeinfo
.revision
, 2);
177 fprintf(stdout
, "%-16s: %s\n", "REVISION", s
);
180 memcpy(s
, capeinfo
.board_name
, 32);
181 fprintf(stdout
, "%-16s: %s\n", "BOARD_NAME", s
);
184 memcpy(s
, capeinfo
.version
, 4);
185 fprintf(stdout
, "%-16s: %s\n", "VERSION", s
);
188 memcpy(s
, capeinfo
.manufacturer
, 16);
189 fprintf(stdout
, "%-16s: %s\n", "MANUFACTURER", s
);
192 memcpy(s
, capeinfo
.partno
, 16);
193 fprintf(stdout
, "%-16s: %s\n", "PART_NUMBER", s
);
196 memcpy(s
, capeinfo
.serial
, 12);
197 fprintf(stdout
, "%-16s: %s\n", "SERIAL", s
);
203 board_info(int fd
, i2c_addr_t address
, int flags
,
204 enum device_types device_type
)
207 uint8_t magic_number
[6];
209 r
= eeprom_read(fd
, address
, 0x0000, &magic_number
, 6, flags
,
212 printf("%-16s: %s\n", "BOARD_NAME", "UNKNOWN");
216 /* Check for BeagleBone/BeagleBone Black/Cape Magic Number */
217 if (magic_number
[0] == 0xaa && magic_number
[1] == 0x55 &&
218 magic_number
[2] == 0x33 && magic_number
[3] == 0xee) {
220 /* Check if Cape Rev A0, Cape Rev A1, or on-board EEPROM */
221 if (magic_number
[4] == 'A' && magic_number
[5] == '0') {
222 board_info_cape_a0(fd
, address
, flags
, device_type
);
223 } else if (magic_number
[4] == 'A' && magic_number
[5] == '1') {
224 board_info_cape_a1(fd
, address
, flags
, device_type
);
226 board_info_beaglebone(fd
, address
, flags
, device_type
);
229 printf("%-16s: %s\n", "BOARD_NAME", "UNKNOWN");