Adding raw binary file at specific adress in Flash

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

Hello !
I want to add a raw binary file to my code. Normally I use hex2bin/bin2hex to add the binary to the code, but then, AVR-Studio wouldn't programm it automaticly to the device if you are debugging with ICE but would only programm the Code (and the binary is then missing :cry:

Any idea how to do it in the makefile ?

I use absolute adress in the code to access the binary data and it's too long to add as a table in the sourcecode

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

Quote:
it's too long to add as a table in the sourcecode
Rubish. With xxd:
data.c: data.dat
       xxd -i data.dat $@

Stealing Proteus doesn't make you an engineer.

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

avr-objcopy can do this

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

how objcopy can do this ?

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

While it's about placing a CRC at a specific place in flash, this tutorial on the subject will probably give you clues as to how you can accomplish what you want: https://www.avrfreaks.net/index.p...

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

baer.ac wrote:
Hello !I use absolute adress in the code to access the binary data and it's too long to add as a table in the sourcecode
Is absolute address really needed?

Try out-of-function inline asm - just for avoiding of separate asm-file

#include 
#include 

extern prog_uint8_t foo[];

__asm__ (
        ".text \n\t"          /* user-defined section can be used */
        ".global foo \n\t"    /* and placed in fixed location in linker script */
"foo: \n\t"
"       .incbin \"data.bin\" "
);

int main()
{
        PORTB = pgm_read_byte(&foo[5]);
        for(;;);
}

objdump output

...
0000005e :
  5e:   74 79           andi    r23, 0x94       ; 148
  60:   70 65           ori     r23, 0x50       ; 80
  62:   64 65           ori     r22, 0x54       ; 84
  64:   66 20           and     r6, r6
...
00000109 
: 109: e3 e6 ldi r30, 0x63 ; 99 10b: f0 e0 ldi r31, 0x00 ; 0 10d: e4 91 lpm r30, Z+ 10f: e8 bb out 0x18, r30 ; 24 111: ff cf rjmp .-2 ; 0x111

wbr, ReAl

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

baer.ac wrote:
how objcopy can do this ?

https://www.avrfreaks.net/index.p...

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

Quote:

it's too long to add as a table in the sourcecode

OK, I'll bite: If the result fits into the flash why would the table in the source code be "too big"? Really really short of hard disk space?

(You know it doesn't HAVE to be part of main(), don't you? A .h file, or separate .c or even an included .frog or whatever)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Quote:

(You know it doesn't HAVE to be part of main(), don't you? A .h file, or separate .c or even an included .frog or whatever)

In our coding standard this is the one acceptable time to #include C source code but to differentiate it from normal source we use a .i (included data) file extension and hence:

#include "sinetable.i"

or whatever.