I am trying to find a dfu-util command to write to the EEPROM memory area such that I can seed my device with some default configuration flags. I’ve read up on the “100 bytes” of emulated EEPROM, and have been digging into spark code and see that its actually implemented as a 1k area with some sort of paging that I don’t understand fully, but I thought I figured out enough to at least accomplish what I was trying to do, but hit a snag.
I wrote a sketch that sets all 100 EEPROM bytes to some specific value, and then used the following command to download the emulated EEPROM flash bytes:
dfu-util -d 1d50:607f -a 0 -s 0x08004000:1024 -U eeprom.dat
And when I hexdump the file, I see the following
0000000 00 00 ff ff 0a 00 00 00 0b 00 01 00 0c 00 02 00
0000010 0d 00 03 00 0e 00 04 00 0f 00 05 00 10 00 06 00
0000020 11 00 07 00 12 00 08 00 13 00 09 00 41 00 0a 00
0000030 0a 00 00 00 0b 00 01 00 0c 00 02 00 0d 00 03 00
(truncated for brevity - has all the data my sketch wrote to EEPROM)
00001f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
So after the first 32 bits I see a repeating 32 bits where 16 bits are used for the stored value (even though the API only lets you write 8 bits), and then the 16 bit ‘virtual address’.
What I then did is use a hex editor to change some of the data bytes, and then I was hoping to dfu-util write the file back to the core at the same EEPROM memory location, and then have my sketch dump all 100 virtual EEPROM bytes, hoping to see the value I put in with the hex editor. This would prove that I can seed specific EEPROM values to my device before shipping to the customer. But here is the error I get when trying to write the EEPROM 1k bytes:
dfu-util -d 1d50:607f -a 0 -s 0x08004000 -D updated_eeprom.dat
Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2012 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to firstname.lastname@example.org
Filter on vendor = 0x1d50 product = 0x607f
Opening DFU capable USB device… ID 1d50:607f
Run-time device DFU version 011a
Found DFU: [1d50:607f] devnum=0, cfg=1, intf=0, alt=0, name="@Internal Flash /0x08000000/20001Ka,108001Kg"
Claiming USB DFU Interface…
Setting Alternate Setting #0 …
Determining device status: state = dfuERROR, status = 10
dfuERROR, clearing status
Determining device status: state = dfuIDLE, status = 0
DFU mode device DFU version 011a
Device returned transfer size 1024
No valid DFU suffix signature
Warning: File has no DFU suffix
DfuSe interface name: "Internal Flash "
Downloading to address = 0x08004000, size = 1024
Error: Last page at 0x080043ff is not writeable
“Error: Last page at 0x080043ff is not writeable” makes me think some sort of write protection is in place, and when I read about the ‘unprotect’ and ‘force’ options of dfu-util, I got a little nervious about bricking the core, so I thought I would ask here first
Of course I could just write a ‘seed’ sketch for my device that uses code to set the EEPROM, but then I would have to flash my device with the seed firmware, run it once, re-flash with the real product firmware. I would like to bypass that first firmware if possible and just write the EEPROM with dfu-util during product production.
Any thoughts on how I can get dfu-util to let me write these bytes?