Skip to content

Commit 47c0530

Browse files
committed
Allow reading back and dumping EEPROM binary
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 02e14b8 commit 47c0530

File tree

3 files changed

+112
-11
lines changed

3 files changed

+112
-11
lines changed

config_definition.h

+14-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525

2626
#define __packed __attribute__((packed))
2727

28+
/**
29+
* The main struct (header)
30+
* Contained in either either
31+
* - default_gpu_cfg
32+
* - default_ssd_cfg
33+
*/
2834
struct gpu_cfg_descriptor {
2935
/* Expansion bay card magic value that is unique */
3036
char magic[4];
@@ -49,12 +55,13 @@ struct gpu_cfg_descriptor {
4955
uint32_t crc32;
5056
} __packed;
5157

52-
struct gpu_config_header {
53-
union {
54-
struct gpu_cfg_descriptor header;
55-
uint8_t bytes[0x2B];
56-
};
57-
} __packed;
58+
// Unused structure
59+
//struct gpu_config_header {
60+
// union {
61+
// struct gpu_cfg_descriptor header;
62+
// uint8_t bytes[0x2B];
63+
// };
64+
//} __packed;
5865

5966
struct gpu_block_header {
6067
uint8_t block_type;
@@ -227,4 +234,4 @@ struct gpu_subsys_pd {
227234
uint8_t power_domain;
228235
uint8_t gpio_hpd;
229236
uint8_t gpio_interrupt;
230-
} __packed;
237+
} __packed;

gpu_cfg_generator.c

+82-4
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,72 @@ static struct default_ssd_cfg ssd_cfg = {
213213
.gpu_3v_5v_en = {.gpio = GPU_3V_5V_EN, .function = GPIO_FUNC_HIGH, .flags = GPIO_OUTPUT_LOW, .power_domain = POWER_S5},
214214
};
215215

216+
void dump_descriptor(struct gpu_cfg_descriptor *desc)
217+
{
218+
219+
// Just for debugging
220+
// printf("Descriptor\n");
221+
// printf(" Magic %02X%02X%02X%02X\n", (uint8_t)desc->magic[0], (uint8_t)desc->magic[1], (uint8_t)desc->magic[2], (uint8_t)desc->magic[3]);
222+
// printf(" Length: %d\n", desc->length);
223+
// printf(" Desc Length: %d\n", desc->descriptor_length);
224+
// printf(" Desc CRC32: %08X\n", desc->descriptor_crc32);
225+
// printf(" CRC32: %08X\n", desc->crc32);
226+
// printf(" Desc Version: %d.%d\n", desc->descriptor_version_major, desc->descriptor_version_minor);
227+
// printf(" HW Version: %04X\n", desc->hardware_version);
228+
// printf(" HW Rev: %d\n", desc->hardware_revision);
229+
// printf(" Serialnum: %s\n", desc->serial);
230+
231+
printf("Serialnum: %s\n", desc->serial);
232+
}
233+
234+
void dump_gpu(struct default_gpu_cfg* gpu_cfg)
235+
{
236+
printf("Type: GPU\n");
237+
switch (gpu_cfg->pcba_serial.gpu_subsys) {
238+
case GPU_PCB:
239+
printf("PCBA Serial: %s\n", gpu_cfg->pcba_serial.serial);
240+
break;
241+
case GPU_LEFT_FAN:
242+
printf("Left Fan SN: %s\n", gpu_cfg->pcba_serial.serial);
243+
break;
244+
case GPU_RIGHT_FAN:
245+
printf("Right Fan SN: %s\n", gpu_cfg->pcba_serial.serial);
246+
break;
247+
case GPU_HOUSING:
248+
printf("Housing SN: %s\n", gpu_cfg->pcba_serial.serial);
249+
break;
250+
default:
251+
printf("??? Serial: %s\n", gpu_cfg->pcba_serial.serial);
252+
break;
253+
}
254+
}
255+
256+
void dump_ssd(struct default_ssd_cfg* ssd_cfg)
257+
{
258+
printf("Type: SSD\n");
259+
}
260+
261+
void read_eeprom(const char * infilename)
262+
{
263+
FILE *fptr;
264+
fptr = fopen(infilename,"rb");
265+
// TODO: gpu_cfg is bigger than ssd_cfg, that's why I read it into there.
266+
// Should make it safer so that if we change the structures, the same still holds.
267+
fread((void *)&gpu_cfg, sizeof(gpu_cfg), 1, fptr);
268+
fclose(fptr);
269+
270+
uint32_t len = gpu_cfg.descriptor.descriptor_length + sizeof(struct gpu_cfg_descriptor);
271+
// TODO: Length comparison won't work if newer versions of the descriptors have different sizes
272+
if (len == sizeof(struct default_gpu_cfg)) {
273+
dump_descriptor((struct gpu_cfg_descriptor *)&gpu_cfg);
274+
dump_gpu((struct default_gpu_cfg*) &gpu_cfg);
275+
} else if (len == sizeof(struct default_ssd_cfg)) {
276+
dump_descriptor((struct gpu_cfg_descriptor *)&gpu_cfg);
277+
dump_ssd((struct default_ssd_cfg*) &gpu_cfg);
278+
} else {
279+
printf("Invalid descriptor. No body found (Len %d)\n", len);
280+
}
281+
}
216282

217283
void program_eeprom(const char * serial, struct gpu_cfg_descriptor * descriptor, size_t len, const char * outpath)
218284
{
@@ -233,8 +299,8 @@ void program_eeprom(const char * serial, struct gpu_cfg_descriptor * descriptor,
233299
printf("writing EEPROM to %s\n", outpath);
234300

235301
fptr = fopen(outpath,"wb");
236-
fwrite(descriptor, len, 1, fptr);
237-
fclose(fptr);
302+
fwrite(descriptor, len, 1, fptr);
303+
fclose(fptr);
238304

239305
}
240306

@@ -244,11 +310,12 @@ int main(int argc, char *argv[]) {
244310
char *serialvalue = NULL;
245311
char *pcbvalue = NULL;
246312
char *outfilename = "eeprom.bin";
313+
char *infilename = NULL;
247314
int c;
248315

249316
opterr = 0;
250317

251-
while ((c = getopt (argc, argv, "gds:p:o:")) != -1)
318+
while ((c = getopt (argc, argv, "gds:p:o:i:")) != -1)
252319
switch (c)
253320
{
254321
case 'g':
@@ -266,6 +333,9 @@ int main(int argc, char *argv[]) {
266333
case 'o':
267334
outfilename = optarg;
268335
break;
336+
case 'i':
337+
infilename = optarg;
338+
break;
269339
case '?':
270340
if (optopt == 'c')
271341
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
@@ -280,10 +350,16 @@ int main(int argc, char *argv[]) {
280350
abort ();
281351
}
282352
printf("Build: %s %s\n", __DATE__, __TIME__);
353+
354+
if (infilename) {
355+
read_eeprom(infilename);
356+
return 0;
357+
}
358+
283359
printf("Descriptor Version: %d %d\n", 0, 1);
284360

285361
printf ("gpu = %d, ssd = %d, module SN = %s pcb SN = %s output file = %s\n",
286-
gpuflag, ssdflag, serialvalue, pcbvalue, outfilename);
362+
gpuflag, ssdflag, serialvalue, pcbvalue, outfilename, infilename);
287363

288364
if (gpuflag) {
289365
if (pcbvalue) {
@@ -295,4 +371,6 @@ int main(int argc, char *argv[]) {
295371
if (ssdflag) {
296372
program_eeprom(serialvalue, (void *)&ssd_cfg, sizeof(ssd_cfg), outfilename);
297373
}
374+
375+
return 0;
298376
}

readme.md

+16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ The application will generate a `.bin` file in the same directory with the EEPRO
2929
./gpu_cfg_gen -d -s FRAKMBCP81331ASSY0
3030
```
3131

32+
## Different file name
33+
34+
By default the generated fiel is called `eeprom.bin`, here's how to use a different one:
35+
36+
```
37+
./gpu_cfg_gen -d -s FRAKMBCP81331ASSY0 -o ssd.bin
38+
```
39+
40+
## Read EEPROM binary
41+
42+
To double-check you can read the binary back from EEPROM and analyze it with the tool:
43+
44+
```sh
45+
./gpu_cfg_gen -i eeprom.bin
46+
```
47+
3248
# Build natively
3349

3450
While the regular build builds a single executable that runs on Linux and

0 commit comments

Comments
 (0)