Rev 1369 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1369 | Rev 1679 | ||
---|---|---|---|
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 | OBJCOPY="$1" |
33 | OBJCOPY="$1" |
34 | LINK="_link.ld" |
34 | LINK="_link.ld" |
35 | HEADER="_components.h" |
35 | HEADER="_components.h" |
36 | 36 | ||
37 | shift |
37 | shift |
38 | 38 | ||
39 | echo 'OUTPUT_FORMAT("elf32-powerpc") |
39 | echo 'OUTPUT_FORMAT("elf32-powerpc") |
40 | OUTPUT_ARCH(powerpc:common) |
40 | OUTPUT_ARCH(powerpc:common) |
41 | ENTRY(start) |
41 | ENTRY(start) |
42 | 42 | ||
43 | SECTIONS { |
43 | SECTIONS { |
44 | .boot 0x10000000: AT (0) { |
44 | .boot 0x10000000: AT (0) { |
45 | *(BOOTSTRAP); |
45 | *(BOOTSTRAP); |
46 | *(REALMODE); |
46 | *(REALMODE); |
47 | *(.text); |
47 | *(.text); |
48 | 48 | ||
49 | *(.rodata); |
49 | *(.rodata); |
50 | *(.rodata.*); |
50 | *(.rodata.*); |
51 | *(.data); /* initialized data */ |
51 | *(.data); /* initialized data */ |
52 | *(.sdata); |
52 | *(.sdata); |
53 | *(.sdata2); |
53 | *(.sdata2); |
54 | *(.sbss); |
54 | *(.sbss); |
55 | *(.bss); /* uninitialized static variables */ |
55 | *(.bss); /* uninitialized static variables */ |
56 | *(COMMON); /* global variables */ |
56 | *(COMMON); /* global variables */' > "$LINK" |
57 | - | ||
58 | . = ALIGN(4096); |
- | |
59 | *(.kernel_image);' > "$LINK" |
- | |
60 | 57 | ||
61 | echo '#ifndef ___COMPONENTS_H__ |
58 | echo '#ifndef ___COMPONENTS_H__ |
62 | #define ___COMPONENTS_H__ |
59 | #define ___COMPONENTS_H__ |
63 | 60 | ||
64 | typedef struct { |
61 | typedef struct { |
65 | char *name; |
62 | char *name; |
66 | 63 | ||
67 | void *start; |
64 | void *start; |
68 | void *end; |
65 | void *end; |
69 | unsigned int size; |
66 | unsigned int size; |
70 | } component_t;' > "$HEADER" |
67 | } component_t;' > "$HEADER" |
71 | 68 | ||
72 | COUNT="0" |
69 | COUNT="0" |
73 | DATA="" |
70 | DATA="" |
74 | 71 | ||
75 | for TASK in "$@" ; do |
72 | for TASK in "$@" ; do |
76 | BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`" |
73 | BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`" |
77 | OBJECT="${BASENAME}.o" |
74 | OBJECT="${BASENAME}.o" |
78 | SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`" |
75 | SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`" |
79 | MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`" |
76 | MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`" |
80 | echo "$TASK -> $OBJECT" |
77 | echo "$TASK -> $OBJECT" |
81 | 78 | ||
82 | echo " |
79 | echo " |
83 | . = ALIGN(4096); |
80 | . = ALIGN(4096); |
84 | *(.${BASENAME}_image);" >> "$LINK" |
81 | *(.${BASENAME}_image);" >> "$LINK" |
85 | 82 | ||
86 | echo " |
83 | echo " |
87 | extern int ${SYMBOL}_start; |
84 | extern int ${SYMBOL}_start; |
88 | extern int ${SYMBOL}_end; |
85 | extern int ${SYMBOL}_end; |
89 | 86 | ||
90 | #define ${MACRO}_START ((void *) &${SYMBOL}_start) |
87 | #define ${MACRO}_START ((void *) &${SYMBOL}_start) |
91 | #define ${MACRO}_END ((void *) &${SYMBOL}_end) |
88 | #define ${MACRO}_END ((void *) &${SYMBOL}_end) |
92 | #define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER" |
89 | #define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER" |
93 | 90 | ||
94 | "$OBJCOPY" -I binary -O elf32-powerpc -B powerpc:common --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT" |
91 | "$OBJCOPY" -I binary -O elf32-powerpc -B powerpc:common --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT" |
95 | 92 | ||
96 | DATA="${DATA} |
93 | DATA="${DATA} |
97 | components[$COUNT].name = \"${BASENAME}\"; |
94 | components[$COUNT].name = \"${BASENAME}\"; |
98 | components[$COUNT].start = ${MACRO}_START; |
95 | components[$COUNT].start = ${MACRO}_START; |
99 | components[$COUNT].end = ${MACRO}_END; |
96 | components[$COUNT].end = ${MACRO}_END; |
100 | components[$COUNT].size = ${MACRO}_SIZE;"; |
97 | components[$COUNT].size = ${MACRO}_SIZE;"; |
101 | COUNT="`expr "$COUNT" + 1`" |
98 | COUNT="`expr "$COUNT" + 1`" |
102 | done |
99 | done |
103 | 100 | ||
104 | echo ' } |
101 | echo ' } |
105 | }' >> "$LINK" |
102 | }' >> "$LINK" |
106 | 103 | ||
107 | echo " |
104 | echo " |
108 | #define COMPONENTS $COUNT |
105 | #define COMPONENTS $COUNT |
109 | 106 | ||
110 | component_t components[COMPONENTS]; |
107 | component_t components[COMPONENTS]; |
111 | 108 | ||
112 | static void init_components(void) |
109 | static void init_components(void) |
113 | { |
110 | { |
114 | $DATA |
111 | $DATA |
115 | } |
112 | } |
116 | 113 | ||
117 | #endif |
114 | #endif |
118 | " >> "$HEADER" |
115 | " >> "$HEADER" |
119 | 116 |