Rev 1747 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1747 | Rev 1748 | ||
---|---|---|---|
1 | #! /bin/sh |
1 | #! /bin/sh |
2 | 2 | ||
3 | # |
3 | # |
4 | # Copyright (C) 2006 Martin Decky |
4 | # Copyright (C) 2006 Martin Decky |
5 | # All rights reserved. |
5 | # All rights reserved. |
6 | # |
6 | # |
7 | # Redistribution and use in source and binary forms, with or without |
7 | # Redistribution and use in source and binary forms, with or without |
8 | # modification, are permitted provided that the following conditions |
8 | # modification, are permitted provided that the following conditions |
9 | # are met: |
9 | # are met: |
10 | # |
10 | # |
11 | # - Redistributions of source code must retain the above copyright |
11 | # - Redistributions of source code must retain the above copyright |
12 | # notice, this list of conditions and the following disclaimer. |
12 | # notice, this list of conditions and the following disclaimer. |
13 | # - Redistributions in binary form must reproduce the above copyright |
13 | # - Redistributions in binary form must reproduce the above copyright |
14 | # notice, this list of conditions and the following disclaimer in the |
14 | # notice, this list of conditions and the following disclaimer in the |
15 | # documentation and/or other materials provided with the distribution. |
15 | # documentation and/or other materials provided with the distribution. |
16 | # - The name of the author may not be used to endorse or promote products |
16 | # - The name of the author may not be used to endorse or promote products |
17 | # derived from this software without specific prior written permission. |
17 | # derived from this software without specific prior written permission. |
18 | # |
18 | # |
19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | # |
29 | # |
30 | 30 | ||
31 | [ "$#" -lt 1 ] && exit 1 |
31 | [ "$#" -lt 1 ] && exit 1 |
32 | 32 | ||
33 | case "$1" in |
33 | case "$1" in |
34 | "mips") |
34 | "binary") |
35 | BFD="binary" |
35 | BFD="binary" |
36 | ;; |
36 | ;; |
37 | "ecoff") |
37 | "ecoff") |
38 | BFD="ecoff-littlemips" |
38 | BFD="ecoff-littlemips" |
39 | ;; |
39 | ;; |
40 | *) |
40 | *) |
41 | echo "Undefined image format" >&1 |
41 | echo "Undefined image format" >&1 |
42 | exit 1 |
42 | exit 1 |
43 | ;; |
43 | ;; |
44 | esac |
44 | esac |
45 | 45 | ||
46 | OBJCOPY="$2" |
46 | OBJCOPY="$2" |
47 | LINK="_link.ld" |
47 | LINK="_link.ld" |
48 | HEADER="_components.h" |
48 | HEADER="_components.h" |
49 | 49 | ||
50 | shift 2 |
50 | shift 2 |
51 | 51 | ||
52 | echo "OUTPUT_FORMAT(\"${BFD}\") |
52 | echo "OUTPUT_FORMAT(\"${BFD}\") |
53 | ENTRY(start) |
53 | ENTRY(start) |
54 | 54 | ||
55 | SECTIONS { |
55 | SECTIONS { |
56 | .boot 0xbfc00000: AT (0) { |
56 | .boot 0xbfc00000: AT (0) { |
57 | *(BOOTSTRAP); |
57 | *(BOOTSTRAP); |
58 | *(.text); |
58 | *(.text); |
59 | 59 | ||
60 | *(.rodata); |
60 | *(.rodata); |
61 | *(.rodata.*); |
61 | *(.rodata.*); |
62 | *(.data); /* initialized data */ |
62 | *(.data); /* initialized data */ |
63 | *(.sdata); |
63 | *(.sdata); |
64 | *(.sdata2); |
64 | *(.sdata2); |
65 | *(.sbss); |
65 | *(.sbss); |
66 | *(.scommon); |
66 | *(.scommon); |
67 | *(.bss); /* uninitialized static variables */ |
67 | *(.bss); /* uninitialized static variables */ |
68 | *(COMMON); /* global variables */ |
68 | *(COMMON); /* global variables */ |
69 | *(.reginfo);" > "$LINK" |
69 | *(.reginfo);" > "$LINK" |
70 | 70 | ||
71 | echo '#ifndef ___COMPONENTS_H__ |
71 | echo '#ifndef ___COMPONENTS_H__ |
72 | #define ___COMPONENTS_H__ |
72 | #define ___COMPONENTS_H__ |
73 | 73 | ||
74 | typedef struct { |
74 | typedef struct { |
75 | char *name; |
75 | char *name; |
76 | 76 | ||
77 | void *start; |
77 | void *start; |
78 | void *end; |
78 | void *end; |
79 | unsigned int size; |
79 | unsigned int size; |
80 | } component_t;' > "$HEADER" |
80 | } component_t;' > "$HEADER" |
81 | 81 | ||
82 | COUNT="0" |
82 | COUNT="0" |
83 | DATA="" |
83 | DATA="" |
84 | 84 | ||
85 | for TASK in "$@" ; do |
85 | for TASK in "$@" ; do |
86 | BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`" |
86 | BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`" |
87 | OBJECT="${BASENAME}.o" |
87 | OBJECT="${BASENAME}.o" |
88 | SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`" |
88 | SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`" |
89 | MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`" |
89 | MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`" |
90 | echo "$TASK -> $OBJECT" |
90 | echo "$TASK -> $OBJECT" |
91 | 91 | ||
92 | echo " |
92 | echo " |
93 | . = ALIGN(4096); |
93 | . = ALIGN(4096); |
94 | *(.${BASENAME}_image);" >> "$LINK" |
94 | *(.${BASENAME}_image);" >> "$LINK" |
95 | 95 | ||
96 | echo " |
96 | echo " |
97 | extern int ${SYMBOL}_start; |
97 | extern int ${SYMBOL}_start; |
98 | extern int ${SYMBOL}_end; |
98 | extern int ${SYMBOL}_end; |
99 | 99 | ||
100 | #define ${MACRO}_START ((void *) &${SYMBOL}_start) |
100 | #define ${MACRO}_START ((void *) &${SYMBOL}_start) |
101 | #define ${MACRO}_END ((void *) &${SYMBOL}_end) |
101 | #define ${MACRO}_END ((void *) &${SYMBOL}_end) |
102 | #define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER" |
102 | #define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER" |
103 | 103 | ||
104 | "$OBJCOPY" -I binary -O elf32-tradlittlemips -B mips --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT" |
104 | "$OBJCOPY" -I binary -O elf32-tradlittlemips -B mips --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT" |
105 | 105 | ||
106 | DATA="${DATA} |
106 | DATA="${DATA} |
107 | components[$COUNT].name = \"${BASENAME}\"; |
107 | components[$COUNT].name = \"${BASENAME}\"; |
108 | components[$COUNT].start = ${MACRO}_START; |
108 | components[$COUNT].start = ${MACRO}_START; |
109 | components[$COUNT].end = ${MACRO}_END; |
109 | components[$COUNT].end = ${MACRO}_END; |
110 | components[$COUNT].size = ${MACRO}_SIZE;"; |
110 | components[$COUNT].size = ${MACRO}_SIZE;"; |
111 | COUNT="`expr "$COUNT" + 1`" |
111 | COUNT="`expr "$COUNT" + 1`" |
112 | done |
112 | done |
113 | 113 | ||
114 | echo ' } |
114 | echo ' } |
115 | }' >> "$LINK" |
115 | }' >> "$LINK" |
116 | 116 | ||
117 | echo " |
117 | echo " |
118 | #define COMPONENTS $COUNT |
118 | #define COMPONENTS $COUNT |
119 | 119 | ||
120 | static void init_components(component_t components[]) |
120 | static void init_components(component_t components[]) |
121 | { |
121 | { |
122 | $DATA |
122 | $DATA |
123 | } |
123 | } |
124 | 124 | ||
125 | #endif |
125 | #endif |
126 | " >> "$HEADER" |
126 | " >> "$HEADER" |
127 | 127 |