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.


   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.

  25 #
  26 
  27 #
  28 #       Path to the base of the uts directory tree (usually /usr/src/uts).
  29 #
  30 UTSBASE = ../../..
  31 
  32 #
  33 #       Define the module and object file sets.
  34 #
  35 UNIX            = unix
  36 OBJECTS         = $(BCM2835_OBJS:%=$(OBJS_DIR)/%) \
  37                   $(CORE_OBJS:%=$(OBJS_DIR)/%) \
  38                   $(KRTLD_OBJS:%=$(OBJS_DIR)/%)
  39 
  40 ROOTMODULE      = $(ROOT_BCM2835_KERN_DIR)/$(UNIX)
  41 UNIX_BIN        = $(OBJS_DIR)/$(UNIX)
  42 
  43 LIBS            = $(GENLIB)
  44 
  45 GENUNIX         = genunix
  46 GENUNIX_DIR     = ../../../arm/$(GENUNIX)
  47 GENOPTS         = -L $(GENUNIX_DIR)/$(OBJS_DIR) -l $(GENUNIX)
  48 
  49 LIBOPTS         = $(GENOPTS)
  50 
  51 CTFEXTRAOBJS    = $(OBJS_DIR)/vers.o
  52 





  53 
  54 #
  55 #       Include common rules.
  56 #
  57 include $(UTSBASE)/armv6/bcm2835/Makefile.bcm2835
  58 
  59 #
  60 #       Define targets
  61 #
  62 ALL_TARGET      = $(UNIX_BIN)
  63 INSTALL_TARGET  = $(UNIX_BIN) $(ROOTMODULE)
  64 
  65 #
  66 #       This is UNIX_DIR. Use a short path.
  67 #
  68 UNIX_DIR        = .
  69 
  70 #
  71 #       Overrides
  72 #
  73 CLEANFILES      += $(OBJECTS) \
  74                    $(UNIX_O)
  75 
  76 CLOBBERFILES    = $(CLEANFILES) $(UNIX_BIN)
  77 
  78 CFLAGS += $(CCVERBOSE)
  79 
  80 CERRWARN        += -_gcc=-Wno-parentheses
  81 CERRWARN        += -_gcc=-Wno-uninitialized
  82 CERRWARN        += -_gcc=-Wno-unused-label
  83 CERRWARN        += -_gcc=-Wno-unused-function
  84 CERRWARN        += -_gcc=-Wno-unused-variable
  85 CERRWARN        += -_gcc=-Wno-unused-but-set-variable
  86 
  87 # The mapfile used to link unix
  88 MAPFILE         = $(UTSBASE)/armv6/bcm2835/conf/Mapfile
  89 




  90 #
  91 #       Default build targets.
  92 #
  93 .KEEP_STATE:
  94 
  95 def:            $(DEF_DEPS)
  96 
  97 all:            $(ALL_DEPS)
  98 
  99 clean:          $(CLEAN_DEPS)
 100 
 101 clobber:        $(CLOBBER_DEPS)
 102 
 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)/
 109 
 110 symcheck:       $(SYM_DEPS)
 111 
 112 $(UNIX_BIN): $(UNIX_O) $(MAPFILE) $(LIBS) $(DTRACESTUBS)
 113         $(LD) -dy -b -znointerp -o $@ -e _start -M $(MAPFILE) \
 114             $(UNIX_O) $(LIBOPTS) $(DTRACESTUBS)
 115         $(CTFMERGE_UNIQUIFY_AGAINST_GENUNIX)
 116         $(POST_PROCESS)
 117 
 118 $(UNIX_O):      $(OBJECTS) $(OBJS_DIR)/vers.o
 119         $(LD) -r -o $@ $(OBJECTS) $(OBJS_DIR)/vers.o
 120 
 121 symcheck.targ:  $(UNIX_O) $(KRTLD_O) $(MODSTUBS_O) $(LIBS) $(DTRACESTUBS) 
 122         $(LD) -dy -b -o $(SYM_MOD) -M $(MAPFILE) \
 123         $(UNIX_O) $(KRTLD_O) $(MODSTUBS_O) $(LIBOPTS) $(DTRACESTUBS) 
 124 
 125 $(KRTLD_O):     $(KRTLD_OBJECTS)
 126         $(LD) -r -o $@ -M$(KRTLD_MAPFILE) $(KRTLD_OBJECTS)









 127 
 128 #
 129 #       Include common targets.
 130 #
 131 include $(UTSBASE)/armv6/bcm2835/Makefile.targ


   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 # Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  26 #
  27 
  28 #
  29 #       Path to the base of the uts directory tree (usually /usr/src/uts).
  30 #
  31 UTSBASE = ../../..
  32 
  33 #
  34 #       Define the module and object file sets.
  35 #
  36 UNIX            = unix
  37 OBJECTS         = $(BCM2835_OBJS:%=$(OBJS_DIR)/%) \
  38                   $(CORE_OBJS:%=$(OBJS_DIR)/%) \
  39                   $(KRTLD_OBJS:%=$(OBJS_DIR)/%)
  40 
  41 ROOTMODULE      = $(ROOT_BCM2835_KERN_DIR)/$(UNIX)
  42 UNIX_BIN        = $(OBJS_DIR)/$(UNIX)
  43 
  44 LIBS            = $(GENLIB)
  45 
  46 GENUNIX         = genunix
  47 GENUNIX_DIR     = ../../../arm/$(GENUNIX)
  48 GENOPTS         = -L $(GENUNIX_DIR)/$(OBJS_DIR) -l $(GENUNIX)
  49 
  50 LIBOPTS         = $(GENOPTS)
  51 
  52 CTFEXTRAOBJS    = $(OBJS_DIR)/vers.o
  53 
  54 ARCHIVE         = boot_archive
  55 
  56 INITRD          = initrd
  57 BOOT_MODULE     = $(ROOT_BCM2835_KERN_DIR)/$(INITRD)
  58 INITRD_BIN      = $(OBJS_DIR)/$(INITRD)
  59 
  60 #
  61 #       Include common rules.
  62 #
  63 include $(UTSBASE)/armv6/bcm2835/Makefile.bcm2835
  64 
  65 #
  66 #       Define targets
  67 #
  68 ALL_TARGET      = $(UNIX_BIN)
  69 INSTALL_TARGET  = $(UNIX_BIN) $(ROOTMODULE) $(BOOT_MODULE)
  70 
  71 #
  72 #       This is UNIX_DIR. Use a short path.
  73 #
  74 UNIX_DIR        = .
  75 
  76 #
  77 #       Overrides
  78 #
  79 CLEANFILES      += $(OBJECTS) \
  80                    $(UNIX_O)
  81 
  82 CLOBBERFILES    = $(CLEANFILES) $(UNIX_BIN)
  83 
  84 CFLAGS += $(CCVERBOSE)
  85 
  86 CERRWARN        += -_gcc=-Wno-parentheses
  87 CERRWARN        += -_gcc=-Wno-uninitialized
  88 CERRWARN        += -_gcc=-Wno-unused-label
  89 CERRWARN        += -_gcc=-Wno-unused-function
  90 CERRWARN        += -_gcc=-Wno-unused-variable
  91 CERRWARN        += -_gcc=-Wno-unused-but-set-variable
  92 
  93 # The mapfile used to link unix
  94 MAPFILE         = $(UTSBASE)/armv6/bcm2835/conf/Mapfile
  95 
  96 # Tools to build the platform and loader kernel.
  97 MKPLATFORM      = $(UTSBASE)/$(PLATFORM)/tools/mkplatform
  98 MKUNI           = $(UTSBASE)/$(PLATFORM)/tools/mkuni
  99 
 100 #
 101 #       Default build targets.
 102 #
 103 .KEEP_STATE:
 104 
 105 def:            $(DEF_DEPS)
 106 
 107 all:            $(ALL_DEPS)
 108 
 109 clean:          $(CLEAN_DEPS)
 110 
 111 clobber:        $(CLOBBER_DEPS)
 112 
 113 install:        $(INSTALL_DEPS) $(MKPLATFORM) $(MKUNI)





 114 
 115 symcheck:       $(SYM_DEPS)
 116 
 117 $(UNIX_BIN): $(UNIX_O) $(MAPFILE) $(LIBS) $(DTRACESTUBS)
 118         $(LD) -dy -b -znointerp -o $@ -e _start -M $(MAPFILE) \
 119             $(UNIX_O) $(LIBOPTS) $(DTRACESTUBS)
 120         $(CTFMERGE_UNIQUIFY_AGAINST_GENUNIX)
 121         $(POST_PROCESS)
 122 
 123 $(UNIX_O):      $(OBJECTS) $(OBJS_DIR)/vers.o
 124         $(LD) -r -o $@ $(OBJECTS) $(OBJS_DIR)/vers.o
 125 
 126 symcheck.targ:  $(UNIX_O) $(KRTLD_O) $(MODSTUBS_O) $(LIBS) $(DTRACESTUBS) 
 127         $(LD) -dy -b -o $(SYM_MOD) -M $(MAPFILE) \
 128         $(UNIX_O) $(KRTLD_O) $(MODSTUBS_O) $(LIBOPTS) $(DTRACESTUBS) 
 129 
 130 $(KRTLD_O):     $(KRTLD_OBJECTS)
 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)
 141 
 142 #
 143 #       Include common targets.
 144 #
 145 include $(UTSBASE)/armv6/bcm2835/Makefile.targ