Print this page
bcm2835: we need a loader on this platform as well
As stated before, the Raspberry Pi loader is terrible. It claims to
supporte ELF file loading, but what it does is crazy. It loads the ELF file
into memory, gets the start address from the header, converts it into file
offset, adds it to the address where the file was loaded and jumps there.
This is very wrong. So, instead of booting the loader as an ELF file, we
objcopy it into a plain ol' binary image. This should be safe because (1)
the loader has no relocations left, (2) whatever benefit we lose from not
having the whole ELF file in memory is only temporary until the loader hands
off control to unix.
Finally, we force the entry point to appear at the beginning of the binary
file by moving _start into its own section (.text.init) and using the
mapfile to put that section before everything else.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/armv6/bcm2835/unix/Makefile
+++ new/usr/src/uts/armv6/bcm2835/unix/Makefile
1 1 #
2 2 # CDDL HEADER START
3 3 #
4 4 # The contents of this file are subject to the terms of the
5 5 # Common Development and Distribution License (the "License").
6 6 # You may not use this file except in compliance with the License.
7 7 #
8 8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 # or http://www.opensolaris.org/os/licensing.
10 10 # See the License for the specific language governing permissions
11 11 # and limitations under the License.
12 12 #
13 13 # When distributing Covered Code, include this CDDL HEADER in each
14 14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 # If applicable, add the following below this CDDL HEADER, with the
16 16 # fields enclosed by brackets "[]" replaced with your own identifying
17 17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 18 #
19 19 # CDDL HEADER END
20 20 #
21 21
22 22 #
23 23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 +# Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
25 26 #
26 27
27 28 #
28 29 # Path to the base of the uts directory tree (usually /usr/src/uts).
29 30 #
30 31 UTSBASE = ../../..
31 32
32 33 #
33 34 # Define the module and object file sets.
34 35 #
35 36 UNIX = unix
36 37 OBJECTS = $(BCM2835_OBJS:%=$(OBJS_DIR)/%) \
37 38 $(CORE_OBJS:%=$(OBJS_DIR)/%) \
38 39 $(KRTLD_OBJS:%=$(OBJS_DIR)/%)
39 40
40 41 ROOTMODULE = $(ROOT_BCM2835_KERN_DIR)/$(UNIX)
41 42 UNIX_BIN = $(OBJS_DIR)/$(UNIX)
42 43
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
43 44 LIBS = $(GENLIB)
44 45
45 46 GENUNIX = genunix
46 47 GENUNIX_DIR = ../../../arm/$(GENUNIX)
47 48 GENOPTS = -L $(GENUNIX_DIR)/$(OBJS_DIR) -l $(GENUNIX)
48 49
49 50 LIBOPTS = $(GENOPTS)
50 51
51 52 CTFEXTRAOBJS = $(OBJS_DIR)/vers.o
52 53
54 +ARCHIVE = boot_archive
55 +
56 +INITRD = initrd
57 +BOOT_MODULE = $(ROOT_BCM2835_KERN_DIR)/$(INITRD)
58 +INITRD_BIN = $(OBJS_DIR)/$(INITRD)
53 59
54 60 #
55 61 # Include common rules.
56 62 #
57 63 include $(UTSBASE)/armv6/bcm2835/Makefile.bcm2835
58 64
59 65 #
60 66 # Define targets
61 67 #
62 68 ALL_TARGET = $(UNIX_BIN)
63 -INSTALL_TARGET = $(UNIX_BIN) $(ROOTMODULE)
69 +INSTALL_TARGET = $(UNIX_BIN) $(ROOTMODULE) $(BOOT_MODULE)
64 70
65 71 #
66 72 # This is UNIX_DIR. Use a short path.
67 73 #
68 74 UNIX_DIR = .
69 75
70 76 #
71 77 # Overrides
72 78 #
73 79 CLEANFILES += $(OBJECTS) \
74 80 $(UNIX_O)
75 81
76 82 CLOBBERFILES = $(CLEANFILES) $(UNIX_BIN)
77 83
78 84 CFLAGS += $(CCVERBOSE)
79 85
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
80 86 CERRWARN += -_gcc=-Wno-parentheses
81 87 CERRWARN += -_gcc=-Wno-uninitialized
82 88 CERRWARN += -_gcc=-Wno-unused-label
83 89 CERRWARN += -_gcc=-Wno-unused-function
84 90 CERRWARN += -_gcc=-Wno-unused-variable
85 91 CERRWARN += -_gcc=-Wno-unused-but-set-variable
86 92
87 93 # The mapfile used to link unix
88 94 MAPFILE = $(UTSBASE)/armv6/bcm2835/conf/Mapfile
89 95
96 +# Tools to build the platform and loader kernel.
97 +MKPLATFORM = $(UTSBASE)/$(PLATFORM)/tools/mkplatform
98 +MKUNI = $(UTSBASE)/$(PLATFORM)/tools/mkuni
99 +
90 100 #
91 101 # Default build targets.
92 102 #
93 103 .KEEP_STATE:
94 104
95 105 def: $(DEF_DEPS)
96 106
97 107 all: $(ALL_DEPS)
98 108
99 109 clean: $(CLEAN_DEPS)
100 110
101 111 clobber: $(CLOBBER_DEPS)
102 112
103 -MKPLATFORM = $(UTSBASE)/$(PLATFORM)/tools/mkplatform.sh
104 -
105 -install: $(INSTALL_DEPS)
106 - pfexec $(MKPLATFORM) -u $(ROOT_BCM2835_MOD_DIR:$(ROOT)/%=/%) $(UNIX_BIN) \
107 - $(GENUNIX_DIR)/$(OBJS_DIR)/genunix
108 - $(MV) boot_archive $(OBJS_DIR)/
113 +install: $(INSTALL_DEPS) $(MKPLATFORM) $(MKUNI)
109 114
110 115 symcheck: $(SYM_DEPS)
111 116
112 117 $(UNIX_BIN): $(UNIX_O) $(MAPFILE) $(LIBS) $(DTRACESTUBS)
113 118 $(LD) -dy -b -znointerp -o $@ -e _start -M $(MAPFILE) \
114 119 $(UNIX_O) $(LIBOPTS) $(DTRACESTUBS)
115 120 $(CTFMERGE_UNIQUIFY_AGAINST_GENUNIX)
116 121 $(POST_PROCESS)
117 122
118 123 $(UNIX_O): $(OBJECTS) $(OBJS_DIR)/vers.o
119 124 $(LD) -r -o $@ $(OBJECTS) $(OBJS_DIR)/vers.o
120 125
121 126 symcheck.targ: $(UNIX_O) $(KRTLD_O) $(MODSTUBS_O) $(LIBS) $(DTRACESTUBS)
122 127 $(LD) -dy -b -o $(SYM_MOD) -M $(MAPFILE) \
123 128 $(UNIX_O) $(KRTLD_O) $(MODSTUBS_O) $(LIBOPTS) $(DTRACESTUBS)
124 129
125 130 $(KRTLD_O): $(KRTLD_OBJECTS)
126 131 $(LD) -r -o $@ -M$(KRTLD_MAPFILE) $(KRTLD_OBJECTS)
132 +
133 +$(MKPLATFORM) $(MKUNI):
134 + cd ../../tools && pwd && dmake
135 +
136 +$(INITRD_BIN): $(MKPLATFORM) $(MKUNI) $(UNIX_BIN) $(GENUNIX_DIR)/$(OBJS_DIR)/$(GENUNIX)
137 + pfexec $(MKPLATFORM) -u $(ROOT_BCM2835_MOD_DIR:$(ROOT)/%=/%) $(UNIX_BIN) \
138 + $(GENUNIX_DIR)/$(OBJS_DIR)/$(GENUNIX)
139 + $(MV) $(ARCHIVE) $(OBJS_DIR)/
140 + $(MKUNI) $(UNIX_BIN) $(OBJS_DIR)/$(ARCHIVE) $(OBJS_DIR)/$(INITRD)
127 141
128 142 #
129 143 # Include common targets.
130 144 #
131 145 include $(UTSBASE)/armv6/bcm2835/Makefile.targ
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX