樹莓派 HATs ︰ 初探怎解碼

假使有 ID EEPROM 軟體解碼工具,解讀 test.eep

pi@raspberrypi:~/hats/eepromutils hexdump test.eep  0000000 2d52 6950 0001 0002 0079 0000 0001 0000 0000010 003d 0000 f83d 7e93 216a b578 46d2 c7d9 0000020 e230 622a 3141 0001 0e17 6948 6946 6542 0000030 7272 2079 4d28 646f 6c75 3920 4c20 434c 0000040 4829 4669 4269 7265 7972 4420 4341 4b2b 0000050 02e8 0100 2000 0000 0000 0000 a400 00a4 0000060 0000 0000 0000 0000 0000 e000 8400 8484 0000070 0084 0000 0000 8200 ff69 ffff ffff ffff 0000080 ffff ffff ffff ffff ffff ffff ffff ffff * 0001000 pi@raspberrypi:~/hats/eepromutils

 

自然輕鬆快意!!既使沒有 ID EEPROM 軟體解碼工具,閱讀文件

B+ HAT ID EEPROM FORMAT SPECIFICATION

CURRENTLY THIS SPEC IS PRELIMINARY AND THEREFORE STILL LIKELEY TO CHANGE

Note that there are software tools for creation of EEPROM images and for flashing / dumping images from attached HATs.

EEPROM Structure

  HEADER  <- EEPROM header (Required)
  ATOM1   <- Vendor info atom (Required)
  ATOM2   <- GPIO map atom (Required)
  ATOM3   <- DT blob atom (Required for compliance with the HAT specification)
  ...
  ATOMn

EEPROM Header Structure

  Bytes   Field
  4       signature   signature: 0x52, 0x2D, 0x50, 0x69 ("R-Pi" in ASCII)
  1       version     EEPROM data format version (0x00 reserved, 0x01 = first version)
  1       reserved    set to 0
  2       numatoms    total atoms in EEPROM
  4       eeplen      total length in bytes of all eeprom data (including this header)

Atom Structure

  Bytes   Field
  2       type        atom type
  2       count       incrementing atom count
  4       dlen        length in bytes of data+CRC
  N       data        N bytes, N = dlen-2
  2       crc16       CRC-16-CCITT of entire atom (type, count, dlen, data)

Atom Types

  0x0000 = invalid
  0x0001 = vendor info
  0x0002 = GPIO map
  0x0003 = Linux device tree blob
  0x0004 = manufacturer custom data
  0x0005-0xfffe = reserved for future use
  0xffff = invalid

Vendor info atom data (type=0x0001):

Note that the UUID is mandatory and must be filled in correctly according to RFC 4122 (every HAT can then be uniquely identified). It protects against the case where a user accidentally stacks 2 identical HATs on top of each other – this error case is only detectable if the EEPROM data in each is different. The UUID is also useful for manufacturers as a per-board ‘serial number’.

  Bytes   Field
  16      uuid        UUID (unique for every single board ever made)
  2       pid         product ID
  2       pver        product version
  1       vslen       vendor string length (bytes)
  1       pslen       product string length (bytes)
  X       vstr        ASCII vendor string e.g. "ACME Technology Company"
  Y       pstr        ASCII product string e.g. "Special Sensor Board"

GPIO map atom data (type=0x0002):

GPIO map for bank 0 GPIO on 40W B+ header.

NOTE GPIO number refers to BCM2835 GPIO number and NOT J8 pin number!

  Bytes   Field
  1       bank_drive  bank drive strength/slew/hysteresis, BCM2835 can only set per bank, not per IO
            Bits in byte:
            [3:0] drive       0=leave at default, 1-8=drive*2mA, 9-15=reserved
            [5:4] slew        0=leave at default, 1=slew rate limiting, 2=no slew limiting, 3=reserved
            [7:6] hysteresis  0=leave at default, 1=hysteresis disabled, 2=hysteresis enabled, 3=reserved
  1       power
            [1:0] back_power  0=board does not back power Pi
                              1=board back powers and can supply up to 1.3A to the Pi
                              2=board back powers and can supply up to 2A to the Pi
                              3=reserved
                              If back_power=2 high current USB mode is automatically enabled.
            [7:2] reserved    set to 0
  28      1 byte per IO pin
            Bits in each byte:
            [2:0] func_sel    GPIO function as per FSEL GPIO register field in BCM2835 datasheet
            [4:3] reserved    set to 0
            [6:5] pulltype    0=leave at default setting,  1=pullup, 2=pulldown, 3=no pull
            [  7] is_used     1=board uses this pin, 0=not connected and therefore not used

Device tree atom data (type=0x0003):

Binary data (DT blob fragment for board hardware).

For more information on the Devicetree atom contents, see the Devicetree Guide.

 

,手動解碼也許學的更多??

由於 hexdump 不是以 byte 為單位,故而不如 hexedit 方便也。

sudo apt-get install hexedit

hexedit

 

解碼結果如下︰

EEPROM Header
【4 signature】 52 2D 50 69 [R-Pi]
【1 version】 01
【1 reserved】 00
【2 numatoms】 02 00
【4 eeplen】 79 00 00 00

ATOM1
【2 type】 01 00 [vendor info]
【2 count】 00 00
【4 dlen】 3D 00 00 00
[N data]
【16 uuid】 3D F8 93 7E 6A 21 78 B5 D2 46 D9 C7 30 E2 2A 62
【2 pid】 41 31 [A 1]
【2 pver】 01 00
【1 vslen】 17
【1 pslen】 0E
【X vstr】 48 69 46 69 42 65 72 72 79 20 28 4D 6F 64 75 6C 20 39 20 4C 4C 43 29 [HiFiBerry (Modul 9 LLC)]
【Y pstr】 48 69 46 69 42 65 72 72 79 20 44 41 43 2B [HiFiBerry DAC+]
【2 crc16】 4B E8

ATOM2
【2 type】 02 00 [GPIO map]
【2 count】 01 00
【4 dlen】 20 00 00 00
[N data]
【1 bank_drive】 00
【1 power】 00
【28 1 byte per IO pin】 00 00 A4 [2] A4[3] 00 00 00 00 00 00 00 00 00 00 00 00 E0[16] 00 84[18] 84[19] 84[20] 84[21] 00 00 00 00 00 00
【2 crc16】 82 69

FF FF [invalid]

 

【參考資料】

fsel_gpio_register_p92

 

gpio_pins

 

聰明的人或許笑作者太癡,人工解碼幹嘛的呢!!明就有 eepdump 這麼好用的工具乎??!!然而不能手動人工解碼,將如何寫作與除錯那個程式耶!!??

pi@raspberrypi:~/hats/eepromutils $ ./eepdump test.eep test.txt
Reading atom 0…
CRC OK
Reading atom 1…
CRC OK
Warning: Dump finished before EOF
Warning: EOF does not match length specified in header
Done.
pi@raspberrypi:~/hats/eepromutils $ cat test.txt
# ———- Dump generated by eepdump handling format version 0x01 ———-
#
# –Header–
# signature=0x69502d52
# version=0x01
# reserved=0
# numatoms=2
# eeplen=121
# ———-
# Start of atom #0 of type 0x0001 and length 61
# Vendor info
product_uuid 622ae230-c7d9-46d2-b578-216a7e93f83d
product_id 0x3141
product_ver 0x0001
vendor “HiFiBerry (Modul 9 LLC)” # length=23
product “HiFiBerry DAC+” # length=14
# End of atom. CRC16=0xe84b
# Start of atom #1 of type 0x0002 and length 32
# GPIO map info
gpio_drive 0
gpio_slew 0
gpio_hysteresis 0
back_power 0
# GPIO FUNCTION PULL
# —- ——– —-
setgpio 2 ALT0 UP
setgpio 3 ALT0 UP
setgpio 16 INPUT NONE
setgpio 18 ALT0 DEFAULT
setgpio 19 ALT0 DEFAULT
setgpio 20 ALT0 DEFAULT
setgpio 21 ALT0 DEFAULT
# End of atom. CRC16=0x6982
pi@raspberrypi:~/hats/eepromutils $