avr-objcopy creates an invalid file for eeprom data

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am sure I am doing something stupid but I am trying to generate an eep file for a Tiny 2312 using the following command

avr-objcopy -j .eeprom  -O ihex motor.elf  motor.eep

 

but the 1st line of the generated file is invalid (if i am reading it correctly it is specifying an invalid address & I do not know where the data is coming from)

:02000004008179<br />
:10000000FF28632941205761726520323031390061<br />
:10001000493263204D6F746F7220262053657276CB<br />
:100020006F20436F6E74726F6C65722056322E3083<br />
:0100300000CF<br />
:00000001FF</p>
<p>

I know I could simply remove this line (& that should be easy to automate) but I would much rather have the file correct in the 1st place.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok I see that the 1st line is a record type "Extended Linear Address" setting a 32bit offset to the rest of the data, the question is why & how do I stop it so that avrdude can correctly program the eeprom

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But .eeprom is based at 0x810000. Where are you making the adjustment to rebase that?

 

To give you an idea. When AS7 creates EEPROM  it does it with:

"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "test.elf" "test.eep" || exit 0

note the -change-section-lma in that.

 

If I were a Linux user I would be using Mfile. The Mfile template has the equivalent:

%.eep: %.elf
	@echo
	@echo $(MSG_EEPROM) $@
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
	--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0

I suggest you don't mess about with "roll your own" Makefile unless you know exactly how this toolchain works. All good IDEs will do the -change-section-lma thing and all decent Makefile templates will too.

 

The point is that AVR is Harvard and GCC is Von Neumann. So the multiple memory sections in an AVR have to be "flattened" to work in GCC. That happens in the linker script:

MEMORY
{
  text   (rx)   : ORIGIN = 0, LENGTH = __TEXT_REGION_LENGTH__
  data   (rw!x) : ORIGIN = 0x800060, LENGTH = __DATA_REGION_LENGTH__
  eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = __EEPROM_REGION_LENGTH__
  fuse      (rw!x) : ORIGIN = 0x820000, LENGTH = __FUSE_REGION_LENGTH__
  lock      (rw!x) : ORIGIN = 0x830000, LENGTH = __LOCK_REGION_LENGTH__
  signature (rw!x) : ORIGIN = 0x840000, LENGTH = __SIGNATURE_REGION_LENGTH__
  user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = __USER_SIGNATURE_REGION_LENGTH__
}

The 0x810000 offset is applied to EEPROM here - it must be removed again later when you are doing things like extracting .eeprom from the ELF to make a .eep

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is what I was looking for Thanks

Where can i get a copy of this MFile make file - it sounds as if it may be more usefull than the one I am using currently

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IPguru wrote:
Where can i get a copy of this MFile make file
What did Google say?

 

But to preempt that:   http://alfred.sax.de/~joerg/mfile/

 

Mfile is actually an interactive Makefile editor. There is a GUI (in Tcl/Tkinter) that allows you to edit things but, to be honest, the most useful thing is simply makefile_template that comes with it. You can forget the other bits and just take a copy of that as "Makefile" and then hand edit it.

 

That template was put together by some of the original avr-gcc gurus and has a lot of their combined knowledge in it so it will "fix" a lot of the problems you might otherwise encounter if trying to make up this stuff as you go along.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks again

Yes I found it 30 seconds after hitting post

Unfortunately my Linix install Fedora 30 does not seem to have tixwish anywhere so I cant run the app, editing the template will have to be enough.

At least my current project now has a fully working build chain :-)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IPguru wrote:
editing the template will have to be enough.
That's how I've done it in the past - most of the time it's just changing the lines for the CPU target and the SRC= line.