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.

*** 20,29 **** --- 20,30 ---- # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. + # Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> # # # Path to the base of the uts directory tree (usually /usr/src/uts). #
*** 48,68 **** LIBOPTS = $(GENOPTS) CTFEXTRAOBJS = $(OBJS_DIR)/vers.o # # Include common rules. # include $(UTSBASE)/armv6/bcm2835/Makefile.bcm2835 # # Define targets # ALL_TARGET = $(UNIX_BIN) ! INSTALL_TARGET = $(UNIX_BIN) $(ROOTMODULE) # # This is UNIX_DIR. Use a short path. # UNIX_DIR = . --- 49,74 ---- LIBOPTS = $(GENOPTS) CTFEXTRAOBJS = $(OBJS_DIR)/vers.o + ARCHIVE = boot_archive + + INITRD = initrd + BOOT_MODULE = $(ROOT_BCM2835_KERN_DIR)/$(INITRD) + INITRD_BIN = $(OBJS_DIR)/$(INITRD) # # Include common rules. # include $(UTSBASE)/armv6/bcm2835/Makefile.bcm2835 # # Define targets # ALL_TARGET = $(UNIX_BIN) ! INSTALL_TARGET = $(UNIX_BIN) $(ROOTMODULE) $(BOOT_MODULE) # # This is UNIX_DIR. Use a short path. # UNIX_DIR = .
*** 85,94 **** --- 91,104 ---- CERRWARN += -_gcc=-Wno-unused-but-set-variable # The mapfile used to link unix MAPFILE = $(UTSBASE)/armv6/bcm2835/conf/Mapfile + # Tools to build the platform and loader kernel. + MKPLATFORM = $(UTSBASE)/$(PLATFORM)/tools/mkplatform + MKUNI = $(UTSBASE)/$(PLATFORM)/tools/mkuni + # # Default build targets. # .KEEP_STATE:
*** 98,113 **** clean: $(CLEAN_DEPS) clobber: $(CLOBBER_DEPS) ! MKPLATFORM = $(UTSBASE)/$(PLATFORM)/tools/mkplatform.sh ! ! install: $(INSTALL_DEPS) ! pfexec $(MKPLATFORM) -u $(ROOT_BCM2835_MOD_DIR:$(ROOT)/%=/%) $(UNIX_BIN) \ ! $(GENUNIX_DIR)/$(OBJS_DIR)/genunix ! $(MV) boot_archive $(OBJS_DIR)/ symcheck: $(SYM_DEPS) $(UNIX_BIN): $(UNIX_O) $(MAPFILE) $(LIBS) $(DTRACESTUBS) $(LD) -dy -b -znointerp -o $@ -e _start -M $(MAPFILE) \ --- 108,118 ---- clean: $(CLEAN_DEPS) clobber: $(CLOBBER_DEPS) ! install: $(INSTALL_DEPS) $(MKPLATFORM) $(MKUNI) symcheck: $(SYM_DEPS) $(UNIX_BIN): $(UNIX_O) $(MAPFILE) $(LIBS) $(DTRACESTUBS) $(LD) -dy -b -znointerp -o $@ -e _start -M $(MAPFILE) \
*** 123,131 **** --- 128,145 ---- $(UNIX_O) $(KRTLD_O) $(MODSTUBS_O) $(LIBOPTS) $(DTRACESTUBS) $(KRTLD_O): $(KRTLD_OBJECTS) $(LD) -r -o $@ -M$(KRTLD_MAPFILE) $(KRTLD_OBJECTS) + $(MKPLATFORM) $(MKUNI): + cd ../../tools && pwd && dmake + + $(INITRD_BIN): $(MKPLATFORM) $(MKUNI) $(UNIX_BIN) $(GENUNIX_DIR)/$(OBJS_DIR)/$(GENUNIX) + pfexec $(MKPLATFORM) -u $(ROOT_BCM2835_MOD_DIR:$(ROOT)/%=/%) $(UNIX_BIN) \ + $(GENUNIX_DIR)/$(OBJS_DIR)/$(GENUNIX) + $(MV) $(ARCHIVE) $(OBJS_DIR)/ + $(MKUNI) $(UNIX_BIN) $(OBJS_DIR)/$(ARCHIVE) $(OBJS_DIR)/$(INITRD) + # # Include common targets. # include $(UTSBASE)/armv6/bcm2835/Makefile.targ