fmc-write-eeprom.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. fmc-write-eeprom
  2. ================
  3. This module is designed to load a binary file from /lib/firmware and to
  4. write it to the internal EEPROM of the mezzanine card. This driver uses
  5. the `busid' generic parameter.
  6. Overwriting the EEPROM is not something you should do daily, and it is
  7. expected to only happen during manufacturing. For this reason, the
  8. module makes it unlikely for the random user to change a working EEPROM.
  9. The module takes the following measures:
  10. * It accepts a `file=' argument (within /lib/firmware) and if no
  11. such argument is received, it doesn't write anything to EEPROM
  12. (i.e. there is no default file name).
  13. * If the file name ends with `.bin' it is written verbatim starting
  14. at offset 0.
  15. * If the file name ends with `.tlv' it is interpreted as
  16. type-length-value (i.e., it allows writev(2)-like operation).
  17. * If the file name doesn't match any of the patterns above, it is
  18. ignored and no write is performed.
  19. * Only cards listed with `busid=' are written to. If no busid is
  20. specified, no programming is done (and the probe function of the
  21. driver will fail).
  22. Each TLV tuple is formatted in this way: the header is 5 bytes,
  23. followed by data. The first byte is `w' for write, the next two bytes
  24. represent the address, in little-endian byte order, and the next two
  25. represent the data length, in little-endian order. The length does not
  26. include the header (it is the actual number of bytes to be written).
  27. This is a real example: that writes 5 bytes at position 0x110:
  28. spusa.root# od -t x1 -Ax /lib/firmware/try.tlv
  29. 000000 77 10 01 05 00 30 31 32 33 34
  30. 00000a
  31. spusa.root# insmod /tmp/fmc-write-eeprom.ko busid=0x0200 file=try.tlv
  32. [19983.391498] spec 0000:03:00.0: write 5 bytes at 0x0110
  33. [19983.414615] spec 0000:03:00.0: write_eeprom: success
  34. Please note that you'll most likely want to use SDBFS to build your
  35. EEPROM image, at least if your mezzanines are being used in the White
  36. Rabbit environment. For this reason the TLV format is not expected to
  37. be used much and is not expected to be developed further.
  38. If you want to try reflashing fake EEPROM devices, you can use the
  39. fmc-fakedev.ko module (see *note fmc-fakedev::). Whenever you change
  40. the image starting at offset 0, it will deregister and register again
  41. after two seconds. Please note, however, that if fmc-write-eeprom is
  42. still loaded, the system will associate it to the new device, which
  43. will be reprogrammed and thus will be unloaded after two seconds. The
  44. following example removes the module after it reflashed fakedev the
  45. first time.
  46. spusa.root# insmod fmc-fakedev.ko
  47. [ 72.984733] fake-fmc: Manufacturer: fake-vendor
  48. [ 72.989434] fake-fmc: Product name: fake-design-for-testing
  49. spusa.root# insmod fmc-write-eeprom.ko busid=0 file=fdelay-eeprom.bin; \
  50. rmmod fmc-write-eeprom
  51. [ 130.874098] fake-fmc: Matching a generic driver (no ID)
  52. [ 130.887845] fake-fmc: programming 6155 bytes
  53. [ 130.894567] fake-fmc: write_eeprom: success
  54. [ 132.895794] fake-fmc: Manufacturer: CERN
  55. [ 132.899872] fake-fmc: Product name: FmcDelay1ns4cha
  56. Writing to the EEPROM
  57. =====================
  58. Once you have created a binary file for your EEPROM, you can write it
  59. to the storage medium using the fmc-write-eeprom (See *note
  60. fmc-write-eeprom::, while relying on a carrier driver. The procedure
  61. here shown here uses the SPEC driver
  62. (`http://www.ohwr.org/projects/spec-sw').
  63. The example assumes no driver is already loaded (actually, I unloaded
  64. them by hand as everything loads automatically at boot time after you
  65. installed the modules), and shows kernel messages together with
  66. commands. Here the prompt is spusa.root# and two SPEC cards are plugged
  67. in the system.
  68. spusa.root# insmod fmc.ko
  69. spusa.root# insmod spec.ko
  70. [13972.382818] spec 0000:02:00.0: probe for device 0002:0000
  71. [13972.392773] spec 0000:02:00.0: got file "fmc/spec-init.bin", 1484404 (0x16a674) bytes
  72. [13972.591388] spec 0000:02:00.0: FPGA programming successful
  73. [13972.883011] spec 0000:02:00.0: EEPROM has no FRU information
  74. [13972.888719] spec 0000:02:00.0: No device_id filled, using index
  75. [13972.894676] spec 0000:02:00.0: No mezzanine_name found
  76. [13972.899863] /home/rubini/wip/spec-sw/kernel/spec-gpio.c - spec_gpio_init
  77. [13972.906578] spec 0000:04:00.0: probe for device 0004:0000
  78. [13972.916509] spec 0000:04:00.0: got file "fmc/spec-init.bin", 1484404 (0x16a674) bytes
  79. [13973.115096] spec 0000:04:00.0: FPGA programming successful
  80. [13973.401798] spec 0000:04:00.0: EEPROM has no FRU information
  81. [13973.407474] spec 0000:04:00.0: No device_id filled, using index
  82. [13973.413417] spec 0000:04:00.0: No mezzanine_name found
  83. [13973.418600] /home/rubini/wip/spec-sw/kernel/spec-gpio.c - spec_gpio_init
  84. spusa.root# ls /sys/bus/fmc/devices
  85. fmc-0000 fmc-0001
  86. spusa.root# insmod fmc-write-eeprom.ko busid=0x0200 file=fdelay-eeprom.bin
  87. [14103.966259] spec 0000:02:00.0: Matching an generic driver (no ID)
  88. [14103.975519] spec 0000:02:00.0: programming 6155 bytes
  89. [14126.373762] spec 0000:02:00.0: write_eeprom: success
  90. [14126.378770] spec 0000:04:00.0: Matching an generic driver (no ID)
  91. [14126.384903] spec 0000:04:00.0: fmc_write_eeprom: no filename given: not programming
  92. [14126.392600] fmc_write_eeprom: probe of fmc-0001 failed with error -2
  93. Reading back the EEPROM
  94. =======================
  95. In order to read back the binary content of the EEPROM of your
  96. mezzanine device, the bus creates a read-only sysfs file called eeprom
  97. for each mezzanine it knows about:
  98. spusa.root# cd /sys/bus/fmc/devices; ls -l */eeprom
  99. -r--r--r-- 1 root root 8192 Apr 9 16:53 FmcDelay1ns4cha-f001/eeprom
  100. -r--r--r-- 1 root root 8192 Apr 9 17:19 fake-design-for-testing-f002/eeprom
  101. -r--r--r-- 1 root root 8192 Apr 9 17:19 fake-design-for-testing-f003/eeprom
  102. -r--r--r-- 1 root root 8192 Apr 9 17:19 fmc-f004/eeprom