樹莓派 HATs ︰ eepmake 之《補充》

原本並不打算說此『立意未明』之選項︰

pi@raspberrypi:~/hats/eepromutils $ ./eepmake -h
Wrong input format.
Try ‘eepmake input_file output_file [dt_file] [-c custom_file_1 … custom_file_n]

 

但思即使『揣測錯誤』,或許亦能嘉惠讀者??故而姑妄言之,也請讀者姑妄聽之!!

若是考之以原始碼︰

# line 521
int read_custom(char* in) {
        FILE * fp;
        unsigned long size = 0;

        printf("Opening custom data file %s for read\n", in);

        fp = fopen(in, "r");
        if (fp == NULL) {
                printf("Error opening input file\n");
                return -1;
        }
        
        fseek(fp, 0L, SEEK_END);
        size = ftell(fp);
        fseek(fp, 0L, SEEK_SET);
        
        printf("Adding %lu bytes of custom data\n", size);

        total_size+=ATOM_SIZE+size;
        
        custom_atom[custom_ct].type = ATOM_CUSTOM_TYPE;
        custom_atom[custom_ct].count = 3+custom_ct;
        custom_atom[custom_ct].dlen = size+CRC_SIZE;

        custom_atom[custom_ct].data = (char *) malloc(size);
        if (!fread(custom_atom[custom_ct].data, size, 1, fp)) goto err;

        custom_ct++;

        fp = fopen(in, "r");
        if (fp == NULL) {
                printf("Error opening input file\n");
                return -1;
        }
        
        fseek(fp, 0L, SEEK_END);
        size = ftell(fp);
        fseek(fp, 0L, SEEK_SET);
        
        printf("Adding %lu bytes of custom data\n", size);

        total_size+=ATOM_SIZE+size;
        
        custom_atom[custom_ct].type = ATOM_CUSTOM_TYPE;
        custom_atom[custom_ct].count = 3+custom_ct;
        custom_atom[custom_ct].dlen = size+CRC_SIZE;

        custom_atom[custom_ct].data = (char *) malloc(size);
        if (!fread(custom_atom[custom_ct].data, size, 1, fp)) goto err;

        custom_ct++;

        fclose(fp);
        return 0;

err:
        printf("Unexpected EOF or error occurred\n");
        fclose(fp);
        return 0;

}

 

eepmake 只是將『客制檔』 custom_file_n 抄錄至 ID EEPROM 而已 。因此作者認為可以用於一般應用系統/軟體之特定『組構檔』或是『預設檔』。簡單例釋如下︰

pi@raspberrypi:~/hats/eepromutils $ cat custom_file.cfg

/* This is a test of custom file. */

user_name=freesandal
user_passwd=freesandal

default=0

 

pi@raspberrypi:~/hats/eepromutils $ ./eepmake eeprom_settings.txt allo-piano-dac-pcm512x-audio-overlay-ct.eep allo-piano-dac-pcm512x-audio-overlay.dtbo -c custom_file.cfg

Opening file eeprom_settings.txt for read
UUID=585288a1-8c0f-4f7e-b43c-498e590639a7
Done reading
Opening DT file allo-piano-dac-pcm512x-audio-overlay.dtbo for read
Adding 1033 bytes of DT data
Opening custom data file custom_file.cfg for read
Adding 93 bytes of custom data
Writing out…
Writing out DT…
Done.

 

pi@raspberrypi:~/hats/eepromutils $ ./eepdump allo-piano-dac-pcm512x-audio-overlay-ct.eep allo-piano-dac-pcm512x-audio-overlay-ct.txt
Reading atom 0…
CRC OK
Reading atom 1…
CRC OK
Reading atom 2…
CRC OK
Reading atom 3…
CRC OK
Done.

 

pi@raspberrypi:~/hats/eepromutils $ cat allo-piano-dac-pcm512x-audio-overlay-ct.txt

# ———- Dump generated by eepdump handling format version 0x01 ———-
#
# –Header–
# signature=0x69502d52
# version=0x01
# reserved=0
# numatoms=4
# eeplen=1262
# ———-
# Start of atom #0 of type 0x0001 and length 56
# Vendor info
product_uuid 585288a1-8c0f-4f7e-b43c-498e590639a7
product_id 0x0001
product_ver 0x0001
vendor “www.freesandal.org” # length=18
product “ID EEPROM test” # length=14
# End of atom. CRC16=0x9ee5

……

# Start of atom #3 of type 0x0004 and length 95
custom_data
2F 2A 20 54 68 69 73 20 69 73 20 61 20 74 65 73
74 20 6F 66 20 63 75 73 74 6F 6D 20 66 69 6C 65
2E 20 2A 2F 0A 0A 75 73 65 72 5F 6E 61 6D 65 3D
66 72 65 65 73 61 6E 64 61 6C 0A 75 73 65 72 5F
70 61 73 73 77 64 3D 66 72 65 65 73 61 6E 64 61
6C 0A 0A 64 65 66 61 75 6C 74 3D 30 0A
# End of atom. CRC16=0x6095

 

pi@raspberrypi:~/hats/eepromutils $ hexedit allo-piano-dac-pcm512x-audio-overlay-ct.eep

eepmake-ct

 

若問可能之用途,端賴想像的乎☆