Using binary data with avr-gcc

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

Hi,

I am trying to make a basic webserver, and since I have a Atmega128 with plenty of free flash, I will use that to store the webfiles.

In order to change the webfiles without having to redo the arrays myself, I would like to use the linking with object files.
...But somewhere along the way I did it wrong

I make an .o file
avr-objcopy --rename-section .data=.progmem.data,contents,alloc,load,readonly,data -I binary -O elf32-avr ../index.html index_html.o

I add this in Libraries in AVR studio, save and project save.

In a .h file I have

extern const char index_html[] PROGMEM;
extern const char index_html_end[] PROGMEM;
extern const char index_html_size_sym[];
#define index_html_size index_html_size_sym

My test code to read the string

printf("Try to readout index_html_o\r\n");

uint16_t address = _binary_index_html_bin_start_ ;
//Also tried uint16_t address = index_html;

while (address < index_html_end)
{
	uint8_t result = pgm_read_byte(address);
	printf("/c",result);  //Change to a percent sign
	address++;
	_delay_ms(100);
}

And compiler output

Quote:

../enc28j60_test.c: In function 'main':
../enc28j60_test.c:244: error: '_binary_index_html_bin_start_' undeclared (first use in this function)
../enc28j60_test.c:244: error: (Each undeclared identifier is reported only once
../enc28j60_test.c:244: error: for each function it appears in.)
../enc28j60_test.c:246: warning: comparison between pointer and integer

Any help will be much appreciated!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
const char* address = index_html;

Stefan Ernst

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

sternst wrote:

const char* address = index_html;

Well, index_html is not defined.

242 printf("Try to readout index_html_o\r\n");

244 const char* address = index_html; 

246 while (address < index_html_end)
{
	uint8_t result = pgm_read_byte(address);
	printf("/c",result);
	address++;
	_delay_ms(100);
}

Quote:

enc28j60_test.c:242: undefined reference to `index_html'
enc28j60_test.c:242: undefined reference to `index_html'
enc28j60_test.c:246: undefined reference to `index_html_end'
enc28j60_test.c:246: undefined reference to `index_html_end'

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

I do in the top of the same file.

//test
#include "webfiles.h"

webfiles.h

#ifndef webfiles_loaded
#define webfiles_loaded

#include 
#include 
#include 

bool fileExists(char* name);
uint16_t getFile(char* name);
uint16_t getSize(char* name);

//http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_binarydata
extern const char index_html[] PROGMEM;
extern const char index_html_end[] PROGMEM;
extern const char index_html_size_sym[];
#define index_html_size index_html_size_sym

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

Use the correct names:
_binary_index_html_start
_binary_index_html_end

Stefan Ernst

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

For a simple solution convert the .html to C const arrays using "xxd -i" then just add a PROGMEM to it.

Cliff

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

sternst wrote:
Use the correct names:
_binary_index_html_start
_binary_index_html_end

In the header file or ?

enc28j60_test.c:244: undefined reference to `_binary_index_html_start'
enc28j60_test.c:246: undefined reference to `_binary_index_html_end'

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

clawson wrote:
For a simple solution convert the .html to C const arrays using "xxd -i" then just add a PROGMEM to it.

Cliff


Yes, I used that trick with winhex, it works ok, but requires some more work when the files change.

I Could ofcause write a util that makes a good .h file from a directory, only limit is the array size then, but should be ok.

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

Quote:
In the header file or ?
Everywhere.

And make a "avr-nm index_html.o" to see what the names actually are.
And check the linkage command line whether index_html.o is actually there.

Stefan Ernst

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

Quote:

avr-nm index_html.o
000001a7 R _binary____index_html_end
000001a7 A _binary____index_html_size
00000000 R _binary____index_html_start

but I think the problem is studio not including the o file.

avr-gcc -mmcu=atmega128 -Wall -gdwarf-2 -DF_CPU=16000000UL -Os -fsigned-char -MD -MP -MT enc28j60_test.o -MF dep/enc28j60_test.o.d -c ../enc28j60_test.c

I have made a PHP script, that will generate the webfiles.c/h with binary data in them, so as long as I stay below the limit of one file (32kB?) it can work.

However I would like to get this working correctly also, so I atleast know how.

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

Quote:

but I think the problem is studio not including the o file.

Listing the .o under the [linker commands] section of project config *might* be away to get a .o linked that is not being generated from a .c or .S - otherwise you probably need to switch to using an external makefile.

Cliff

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

Quote:
otherwise you probably need to switch to using an external makefile.
Which is the better choice anyway (IMHO), because then you can include a rule to automatically generate the binary object file(s) from the html files(s).

Stefan Ernst