public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] __attribute aligned and objcopy
@ 2003-09-25 10:37 Øyvind Harboe
  2003-09-25 10:59 ` Gary Thomas
  0 siblings, 1 reply; 3+ messages in thread
From: Øyvind Harboe @ 2003-09-25 10:37 UTC (permalink / raw)
  To: ecos-discuss

This is driving me nuts, and I can't seem to find a solution
to this on the net.

I have a romfs image that I try to convert to a .o file using:


# how do I add a __attribute((aligned(4))__ to objcopy?

arm-elf-objcopy -B arm -I binary -O elf32-littlearm --rename-section
.data=.rodata1 $*.rawdata $(OUTPUT)/$*_raw.o

This is used to mount a ROMFS:

extern "C"
{
extern const cyg_uint8  _binary___rom_rawdata_start[];
}

// this is not aligned to 4 bytes, and hence it does not work
sprintf( address, "%p", _binary___rom_rawdata_start);
err = mount( address, "rom", "romfs" );
	

Øyvind


--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] __attribute aligned and objcopy
  2003-09-25 10:37 [ECOS] __attribute aligned and objcopy Øyvind Harboe
@ 2003-09-25 10:59 ` Gary Thomas
  2003-09-25 13:51   ` Øyvind Harboe
  0 siblings, 1 reply; 3+ messages in thread
From: Gary Thomas @ 2003-09-25 10:59 UTC (permalink / raw)
  To: Øyvind Harboe; +Cc: eCos Discussion

[-- Attachment #1: Type: text/plain, Size: 1784 bytes --]

On Thu, 2003-09-25 at 04:37, Øyvind Harboe wrote:
> This is driving me nuts, and I can't seem to find a solution
> to this on the net.
> 
> I have a romfs image that I try to convert to a .o file using:
> 
> 
> # how do I add a __attribute((aligned(4))__ to objcopy?
> 
> arm-elf-objcopy -B arm -I binary -O elf32-littlearm --rename-section
> .data=.rodata1 $*.rawdata $(OUTPUT)/$*_raw.o
> 
> This is used to mount a ROMFS:
> 
> extern "C"
> {
> extern const cyg_uint8  _binary___rom_rawdata_start[];
> }
> 
> // this is not aligned to 4 bytes, and hence it does not work
> sprintf( address, "%p", _binary___rom_rawdata_start);
> err = mount( address, "rom", "romfs" );
> 	

What I've done in the past is use GCC to get the magic right.  Try 
looking at packages/hal/arm/edb7xxx/current/misc/long*.h
These are binary data files which I then pass through GCC.

I generated them using 'hexdump'.  You can write a script to produce
most any output you'd like.  I've attached the few that I use.  To
use the script:
  % hexdump -f hex_init FILE
  0x23, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, // 0x000008
  0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, // 0x000010
  0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, // 0x000018
  0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, // 0x000020
  0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, // 0x000028
  0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, // 0x000030
Be sure and use the "-v" option, or else it can end up like this:
  0x23, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, // 0x000008
  0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, // 0x000010
  *
  0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x0a, 0x23, // 0x000050
  0x0a, 0x23, 0x20, 0x20, 0x20, 0x20, 0x65, 0x63, // 0x000058

-- 
Gary Thomas <gary@mlbassoc.com>
MLB Associates

[-- Attachment #2: hex_fx --]
[-- Type: text/plain, Size: 46 bytes --]

"0x%06.6_ax "  16/1 "%02x "
"  |" "%_p"
"|\n"

[-- Attachment #3: hex_fx2 --]
[-- Type: text/plain, Size: 41 bytes --]

"/* 0x%06.6_ax */ "  16/1 "0x%02x,"
"\n"

[-- Attachment #4: hex_init --]
[-- Type: text/plain, Size: 35 bytes --]

8/1 "0x%02x, " " // 0x%06.6_ax\n"


[-- Attachment #5: Type: text/plain, Size: 146 bytes --]

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [ECOS] __attribute aligned and objcopy
  2003-09-25 10:59 ` Gary Thomas
@ 2003-09-25 13:51   ` Øyvind Harboe
  0 siblings, 0 replies; 3+ messages in thread
From: Øyvind Harboe @ 2003-09-25 13:51 UTC (permalink / raw)
  To: 'Gary Thomas'; +Cc: 'eCos Discussion'

[-- Attachment #1: Type: text/plain, Size: 992 bytes --]

What irked me about this one was that I had the feeling that
surely someone had done this before me, and that it was just
a matter of finding the right incatation to arm-elf-objcopy. :-)



>What I've done in the past is use GCC to get the magic right.  Try 
>looking at packages/hal/arm/edb7xxx/current/misc/long*.h
>These are binary data files which I then pass through GCC.

When I got your e-mail I had started work on a Frankenmake.
Modified rom/support/file2c.tcl attached. 


# some singing and dancing to get an 4 bytes aligned data. 
# raw data
$(OUTPUT)/%.o: %.alignedraw
	echo -- Raw data file $*.alignedraw
	../scripts/myfile2c.tcl $*.alignedraw $(OUTPUT)/$*.txt
	echo >$(OUTPUT)/$*.xxxx "const __attribute__((aligned(4))) char
"
	echo $(OUTPUT)/$* | sed -e 's/\//_/g'  | sed -e 's/\./_/g'
>>$(OUTPUT)/$*.xxxx
	echo []= >>$(OUTPUT)/$*.xxxx
	cat $(OUTPUT)/$*.txt >>$(OUTPUT)/$*.xxxx
	$(XCC) -o $(OUTPUT)/$*.o $(CFLAGS) -c -x c $(OUTPUT)/$*.xxxx

Øyvind

[-- Attachment #2: myfile2c.tcl --]
[-- Type: application/octet-stream, Size: 4506 bytes --]

#!/bin/bash
# restart using a Tcl shell \
    exec sh -c 'for tclshell in tclsh tclsh83 cygtclsh80 ; do \
            ( echo | $tclshell ) 2> /dev/null && exec $tclshell "`( cygpath -w \"$0\" ) 2> /dev/null || echo $0`" "$@" ; \
        done ; \
        echo "file2c.tcl: cannot find Tcl shell" ; exit 1' "$0" "$@"

#===============================================================================
#
#    file2c.tcl
#
#    Convert a file into a header that can be #included from C.
#
#===============================================================================
#####ECOSGPLCOPYRIGHTBEGIN####
## -------------------------------------------
## This file is part of eCos, the Embedded Configurable Operating System.
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
##
## eCos is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free
## Software Foundation; either version 2 or (at your option) any later version.
##
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
## for more details.
##
## You should have received a copy of the GNU General Public License along
## with eCos; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
##
## As a special exception, if other files instantiate templates or use macros
## or inline functions from this file, or you compile this file and link it
## with other works to produce a work based on this file, this file does not
## by itself cause the resulting work to be covered by the GNU General Public
## License. However the source code for this file must still be made available
## in accordance with section (3) of the GNU General Public License.
##
## This exception does not invalidate any other reasons why a work based on
## this file might be covered by the GNU General Public License.
##
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
## at http://sources.redhat.com/ecos/ecos-license/
## -------------------------------------------
#####ECOSGPLCOPYRIGHTEND####
#===============================================================================
######DESCRIPTIONBEGIN####
#
# Author(s):	jlarmour,bartv
# Contact(s):	
# Date:		2001-07-20
# Purpose:      
# Description:
# Usage:        file2c.tcl <file to encode> <output C header file>
#
#####DESCRIPTIONEND####
#===============================================================================



if { $argc != 2 } {
    puts "Usage: file2c.tcl <file to encode> <output C header file>"
    exit 1
}
set infile [lindex $argv 0]
set outfile [lindex $argv 1]
set variablename [lindex $argv 2]

set status [ catch {
    set infilefd [open $infile "r"]
    fconfigure $infilefd -translation binary
    set data [read $infilefd]
    close $infilefd
} message]

if { $status != 0 } {
    error "Unable to read file $infile: $message"
}

set result ""

set status [ catch {
    set outfilefd [ open $outfile "w" ]
} message ]

if { $status != 0 } {
    error "Unable to create file $outfile: $message"
}

append result "/* This is a generated file. Do not edit. */\n\n"
append result "{\n"

set datalength [ string length $data ]

set aligned_datalength [expr $datalength - ($datalength % 8)]

for { set i 0 } {$i < $aligned_datalength} {incr i 8} {
    binary scan $data "@[set i]H16" var0
    append result [format "    0x%2s, 0x%2s, 0x%2s, 0x%2s, 0x%2s, 0x%2s, 0x%2s, 0x%2s,\n" \
            [string range $var0  0  1] \
            [string range $var0  2  3] \
            [string range $var0  4  5] \
            [string range $var0  6  7] \
            [string range $var0  8  9] \
            [string range $var0 10 11] \
            [string range $var0 12 13] \
            [string range $var0 14 15]]
}

if { $aligned_datalength != $datalength } {
    append result "    "
    for { set i $aligned_datalength } {$i < $datalength} {incr i} {
        binary scan $data "@[set i]H2" var0
        append result [format "0x%2s, " $var0]
    }
}

# Remove either comma+newline or comma+space from the end
set result [string range $result 0 [expr [string length $result] - 3]]

append result "\n};"

puts $outfilefd $result
close $outfilefd


[-- Attachment #3: Type: text/plain, Size: 146 bytes --]

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-09-25 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-25 10:37 [ECOS] __attribute aligned and objcopy Øyvind Harboe
2003-09-25 10:59 ` Gary Thomas
2003-09-25 13:51   ` Øyvind Harboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).