1

I need to convert an picture to an object file(.o) use sde-objcopy, then I can use this picture in our no-os system. I had test the objcopy command, it works well on my PC(Fedora 12). For example, the command below will convert test.jpg to test.o.

objcopy -I binary -O elf32-i386 -B i386 ../stdy/test.jpg test.o

Here are my questions:

A. sde-objcopy doesn't has the "-B" option to specify the architecture, but if I don't specify a architecture, it will reponse an warning like this:

$ sde-objcopy -I binary -O elf32-little test.jpg test.o

sde-objcopy: Warning: Output file cannot represent architecture UNKNOWN!

How to fix this warning?

B. It seems that objcopy uses the file's name to generate symbols in the object file. If I use the full path(such as /home/owner/stdy/test.jpg) as the parameter of objcopy, it will generate long named symbols. Is there any elegant method to fix this issue?

$ objcopy -I binary -O elf32-i386 -B i386 ../stdy/test.jpg test.o

$ nm test.o

00000083 D _binary____stdy_test_jpg_end

00000083 A _binary____stdy_test_jpg_size

00000000 D _binary____stdy_test_jpg_start

$ objcopy -I binary -O elf32-i386 -B i386 test.jpg test.o

$ nm test.o
00000032 D _binary_test_jpg_end

00000032 A _binary_test_jpg_size

00000000 D _binary_test_jpg_start
Stedy
  • 7,359
  • 14
  • 57
  • 77
Serval
  • 153
  • 1
  • 8
  • I search web for a long time and found that the version of sde-objcopy is base on the old gnu-toolchain code(05 april 2000, from man sde-objcopy), and the “-B" option is added to objcopy until 2001 by a programmer who is work for Redhat. So I just ignore this warning. About the second problem, I can't find an elegant way. – Serval Sep 27 '11 at 07:42
  • I had found a very useful Linux command, it can convert any file to a .h file. This header file contains an array, and an integer which is the length of this array. Command is: xxd -i test.jpg > test.h – Serval Feb 02 '13 at 02:45

1 Answers1

0

You could use something like:

# data.s
.section ".rodata"
.globl font_data_start, font_data_end
font_data_start:
.incbin "Zitz-Regular.ttf"
font_data_end:
.size font_data_start, font_data_end - font_data_start

and then access the stuff in your program:

/* prog.c */
extern const char font_data_start[], font_data_end[];
void function() {
    fwrite(font_data_start, font_data_end - font_data_start, 1, stdout);
}