@@ -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
217283void 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}
0 commit comments