@@ -213,6 +213,72 @@ static struct default_ssd_cfg ssd_cfg = {
213
213
.gpu_3v_5v_en = {.gpio = GPU_3V_5V_EN , .function = GPIO_FUNC_HIGH , .flags = GPIO_OUTPUT_LOW , .power_domain = POWER_S5 },
214
214
};
215
215
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
+ }
216
282
217
283
void program_eeprom (const char * serial , struct gpu_cfg_descriptor * descriptor , size_t len , const char * outpath )
218
284
{
@@ -233,8 +299,8 @@ void program_eeprom(const char * serial, struct gpu_cfg_descriptor * descriptor,
233
299
printf ("writing EEPROM to %s\n" , outpath );
234
300
235
301
fptr = fopen (outpath ,"wb" );
236
- fwrite (descriptor , len , 1 , fptr );
237
- fclose (fptr );
302
+ fwrite (descriptor , len , 1 , fptr );
303
+ fclose (fptr );
238
304
239
305
}
240
306
@@ -244,11 +310,12 @@ int main(int argc, char *argv[]) {
244
310
char * serialvalue = NULL ;
245
311
char * pcbvalue = NULL ;
246
312
char * outfilename = "eeprom.bin" ;
313
+ char * infilename = NULL ;
247
314
int c ;
248
315
249
316
opterr = 0 ;
250
317
251
- while ((c = getopt (argc , argv , "gds:p:o:" )) != -1 )
318
+ while ((c = getopt (argc , argv , "gds:p:o:i: " )) != -1 )
252
319
switch (c )
253
320
{
254
321
case 'g' :
@@ -266,6 +333,9 @@ int main(int argc, char *argv[]) {
266
333
case 'o' :
267
334
outfilename = optarg ;
268
335
break ;
336
+ case 'i' :
337
+ infilename = optarg ;
338
+ break ;
269
339
case '?' :
270
340
if (optopt == 'c' )
271
341
fprintf (stderr , "Option -%c requires an argument.\n" , optopt );
@@ -280,10 +350,16 @@ int main(int argc, char *argv[]) {
280
350
abort ();
281
351
}
282
352
printf ("Build: %s %s\n" , __DATE__ , __TIME__ );
353
+
354
+ if (infilename ) {
355
+ read_eeprom (infilename );
356
+ return 0 ;
357
+ }
358
+
283
359
printf ("Descriptor Version: %d %d\n" , 0 , 1 );
284
360
285
361
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 );
287
363
288
364
if (gpuflag ) {
289
365
if (pcbvalue ) {
@@ -295,4 +371,6 @@ int main(int argc, char *argv[]) {
295
371
if (ssdflag ) {
296
372
program_eeprom (serialvalue , (void * )& ssd_cfg , sizeof (ssd_cfg ), outfilename );
297
373
}
374
+
375
+ return 0 ;
298
376
}
0 commit comments