Erasing the usersig

39 views
Skip to first unread message

erazor

unread,
Apr 23, 2012, 4:22:05 AM4/23/12
to avr-xboot
Hi all,

I'm using the first two bytes of the usersig as some kind of serial
and ran into a problem when writing these bytes a second time.

Avrdude isn't able to erase the usersig so I thought about adding a
workaround in the firmware.

It works somehow like this: check if the first two bytes of the
usersig are zero and if so, erase the usersig.

The code looks like this:

http://pastebin.com/t0C2kRke

But somehow even this does not erase the usersig.

I'm using only xboot/sp_driver.h and xboot/sp_driver.S (the previous
ones with the two .BOOT sections) and added "-Wl,--section-
start=.BOOT=0x020000" to my linker-flags.

It'd be pretty nice if anyone can give me some tips.

Regards,
Alex

Alex Forencich

unread,
Apr 23, 2012, 4:43:49 AM4/23/12
to avr-...@googlegroups.com
Is this code being installed with xboot or standalone? If xboot is
installing it, then you cannot put anything in the boot section as xboot
itself is located in the boot section. You can, however, use the xboot
api to write to the user signature row. The xboot api has a call to
erase and rewrite the user signature row.

XBoot API information:
http://alexforencich.com/wiki/en/xboot/readme#xboot_api

Alex Forencich

erazor

unread,
Apr 23, 2012, 5:05:03 AM4/23/12
to avr-xboot
No, I'm using it standalone. Thats why i changed the two lines back
to sp_driver.S @ 6870d44 .

Alex Forencich

unread,
Apr 23, 2012, 5:15:10 AM4/23/12
to avr-...@googlegroups.com
What chip are you using? Are you sure avrdude is programming the boot
section properly? There have been problems in the past with it not
being able to program it correctly/at all. Have you compared a readback
of the hex file to the original?

Alex Forencich

erazor

unread,
Apr 23, 2012, 5:25:35 AM4/23/12
to avr-xboot
Hm, good point - I'll check it.

It's an Xmega32A4. Haven't had any other problems so far.

Alex Forencich

unread,
Apr 23, 2012, 5:42:38 AM4/23/12
to avr-...@googlegroups.com
Shouldn't the start offset on a 32a4 be 0x010000? The xboot makefile
uses an offset of 0x008000 in words for the 32a4.

Alex Forencich

erazor

unread,
Apr 23, 2012, 10:05:16 AM4/23/12
to avr-xboot
I didn't thought about the different bootloader addresses and just
copy&pasted the one atmel mentioned int this sp_driver.S .


Now it's set to 0x00010000 and when I look into my .map file there is
a section  called .BOOT where SP_LoadFlashPage is at address 0x0001000

Still no success.

I'll check if avrdude programmed my device correctly.

erazor

unread,
Apr 23, 2012, 2:23:04 PM4/23/12
to avr-xboot
Well, I'm not quite sure but I suppose avrdude is not writing into
0x10000 . I did a avrdude ... -U flash:r:/dev/stdout:r | hexdump
which ended with 003490.
Shouldn't there be a lot of zeros and then the stuff from .BOOT ?

I also noticed that when using .BOOT in sp_driver.S @ 6870d44 my
device does not run anymore after calling any SP_ commands :-(

So uhm, what can i do now? Writing a program which only erases the
usersig and where .text starts @ 0x010000 ?

Alex Forencich

unread,
Apr 23, 2012, 2:43:13 PM4/23/12
to avr-...@googlegroups.com
Actually, I just looked at the makefile again. I think I gave you the
wrong number before. Try an offset of 0x008000.

Alex Forencich

erazor

unread,
Apr 23, 2012, 2:56:05 PM4/23/12
to avr-xboot
Got so far now to. I wrote a simple programm, put my little erase
stuff in it and chaged .text to 0x8000. Strange thing is, that now
avrdude complains when checking the last bytes :-(

I think i should simply try to write a little xBoot programm.

Alex Forencich

unread,
Apr 23, 2012, 3:04:26 PM4/23/12
to avr-...@googlegroups.com
Ah yeah, it seems avrdude is having trouble writing to the boot section
(at least it's trying this time though...). I have managed to get the
latest version to write xboot in there properly. Try explicitly erasing
the chip with avrdude, then programming it. However, that will only fix
a verification error where something else was there before and avrdude
didn't properly erase it first. If it's not writing anything at all,
then there is more work to do. What version of avrdude are you using?
And what programmer are you using?

Alex Forencich

erazor

unread,
Apr 23, 2012, 3:10:59 PM4/23/12
to avr-xboot
It's avrdude 5.11.1 .
Calling it with -e erases the chip but does not fix the verification.
fuse2 has to be set to 0xBF, correct?

I'm using some kind of a russian avr programmer which uses usb/
stk500v2 as protocol.

Alex Forencich

unread,
Apr 23, 2012, 3:44:00 PM4/23/12
to avr-...@googlegroups.com
BF if you want to use a bootloader, FF otherwise. The chip will fail
verification if it's either unprogrammed or programmed incorrectly. I
have had issues with the programmer not erasing the boot section before
overwriting it, but that does not seem to be the issue here as you're
writing to a blank boot section. I imagine that either avrdude is
sending the programmer the wrong command or the programmer needs a
firmware update. There are different write commands for writing to the
flash and boot sections of the xmega. I had to patch avrdude a while
ago to get my jtagmkii cable to program the boot section at all. Now it
can write it, but it can't erase it without an explicit chip erase.
Slightly annoying, but workable.

Unfortunately, looks like you're going to need to delve into avrdude
and/or your programmer, or get another programmer. Btw, the avrisp2
works fine and is like $35 from digikey IIRC.

Alex Forencich

erazor

unread,
Apr 30, 2012, 12:19:19 PM4/30/12
to avr-xboot
Well, I hardcoded the serial now but I'll try to adapt avrdude anyway.

Thanks a lot so far!

Regards,
Alex
Reply all
Reply to author
Forward
0 new messages