1SubDir HAIKU_TOP src system boot platform u-boot ; 2 3SubDirHdrs $(HAIKU_TOP) headers private kernel boot platform $(TARGET_BOOT_PLATFORM) ; 4 5SubDirHdrs $(HAIKU_TOP) src system boot arch $(TARGET_KERNEL_ARCH) ; 6 7UsePrivateHeaders [ FDirName kernel disk_device_manager ] ; 8UsePrivateHeaders [ FDirName graphics common ] ; 9UsePrivateHeaders [ FDirName graphics vesa ] ; 10UsePrivateHeaders [ FDirName storage ] ; 11UsePrivateHeaders [ FDirName kernel arch generic ] ; 12 13# TODO: move this to arch/arm ! 14 15UsePrivateHeaders [ FDirName kernel arch $(TARGET_KERNEL_ARCH) board $(TARGET_BOOT_BOARD) ] ; 16 17{ 18 local defines = _BOOT_MODE ; 19 20 defines = [ FDefines $(defines) ] ; 21 SubDirCcFlags $(defines) -g3 -O0 ; 22 SubDirC++Flags $(defines) -fno-rtti -g3 -O0 ; 23} 24 25UseLibraryHeaders [ FDirName libfdt ] ; 26 27local libFDTSources = 28 fdt.c 29 fdt_ro.c 30 fdt_rw.c 31 fdt_strerror.c 32 fdt_sw.c 33 fdt_wip.c 34; 35 36# we fake NetBSD since we don't have an OS ID yet for uimage, 37# and we also fake a netbsd loader anyway. 38local uImageFakeOS = "netbsd" ; 39 40SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons accelerants common ] ; 41 42# First build the non arch dependent parts 43BootMergeObject boot_platform_u-boot_common.o : 44 start.cpp 45 debug.cpp 46 console.cpp 47 serial.cpp 48 devices.cpp 49 keyboard.cpp 50 menu.cpp 51 cpu.cpp 52 uimage.cpp 53 video.cpp 54 fdt_serial.cpp 55 fdt_support.cpp 56 openfirmware.cpp 57 $(genericPlatformSources) 58 $(libFDTSources) 59 60 61 : -fno-pic 62 : boot_platform_generic.a 63; 64 65BootMergeObject boot_platform_u-boot.o : 66 : : 67 # must come first to have _start_* at correct locations 68 boot_platform_u-boot_$(TARGET_ARCH).o 69 boot_platform_u-boot_common.o 70; 71 72# TODO: handle flash and SD images as Container stuff ? 73 74# bootable flash image 75rule BuildUBootFlashImage image : haikuLoader : parts 76{ 77 Depends $(image) : $(haikuLoader) ; 78 #Depends $(image) : $(archive) ; 79 Depends $(image) : $(parts) ; 80 LocalClean clean : $(image) ; 81 FLASH_IMAGE_BLOCK_SIZE on $(image) = 1024 ; 82 FLASH_IMAGE_BLOCK_COUNT on $(image) = 32768 ; 83 #FLASH_IMAGE_UBOOT_OFFSET on $(image) = 0 ; 84 FLASH_IMAGE_LOADER_OFFSET on $(image) = 248 ; 85 86 # add u-boot 87 FLASH_OFFSET on $(haikuLoader) = $(FLASH_IMAGE_LOADER_OFFSET) ; 88 local offsets = ; 89 for dep in $(haikuLoader) $(parts) { 90 offsets += [ on $(dep) return $(FLASH_OFFSET) ] ; 91 } 92 FLASH_OFFSETS on $(image) = $(offsets) ; 93 94 # create empty image 95 BuildUBootFlashImage1 $(image) : $(haikuLoader) $(parts) ; 96} 97 98 99actions BuildUBootFlashImage1 100{ 101 $(RM) $(<) 102 103 # make an empty image 104 dd of=$(<) \ 105 if=/dev/zero \ 106 bs=$(FLASH_IMAGE_BLOCK_SIZE) \ 107 count=$(FLASH_IMAGE_BLOCK_COUNT) 108 109 # add binaries 110 # ugly HACK 111 FLASH_OFFSETS=" $(FLASH_OFFSETS) " 112 FLASH_OFFSETS=${FLASH_OFFSETS# } 113 for b in $(>) ; do 114 s="${FLASH_OFFSETS%% *}" 115 FLASH_OFFSETS="${FLASH_OFFSETS#* }" 116 dd of=$(<) \ 117 if=$b \ 118 bs=$(FLASH_IMAGE_BLOCK_SIZE) \ 119 conv=notrunc seek=$s 120 done 121} 122 123# uImage 124rule BuildUImage image : data : args 125{ 126 Depends $(image) : $(data) ; 127 LocalClean clean : $(image) ; 128 MKIMAGE_ARGS on $(image) = $(args) ; 129 colon on $(image) = ":" ; 130 local files = $(data:G=) ; 131 BuildUImage1 $(image) : $(data) ; 132} 133 134actions BuildUImage1 135{ 136 mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<) 137} 138 139rule BuildUImageScript script : content 140{ 141 LocalClean clean : $(script) ; 142 SCRIPTCONTENT on $(script) = $(content) ; 143 SCRIPTNAME on $(script) = $(script) ; 144 FAKEOS on $(script) = $(uImageFakeOS) ; 145 BuildUImageScript1 $(script) : $(content) ; 146} 147 148actions BuildUImageScript1 149{ 150 rm -f $(<) $(<).txt 151 echo '$(SCRIPTCONTENT)' > $(<).txt 152 mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \ 153 -d $(<).txt $(<) 154 rm -f $(<).txt 155} 156 157# SD/mmc image rule 158# requires mtools package on linux 159rule BuildUBootSDImage image : files 160{ 161 Depends $(image) : $(files) ; 162 SDIMAGE_BLOCK_SIZE on $(image) = 1048576 ; # 1M 163 SDIMAGE_SIZE on $(image) = $(HAIKU_BOARD_SDIMAGE_SIZE) ; 164 SDIMAGE_MTOOLS_H on $(image) = 255 ; 165 SDIMAGE_MTOOLS_S on $(image) = 63 ; 166 SDIMAGE_MTOOLS_C on $(image) = 8 ; 167 BuildUBootSDImage1 $(image) : $(files) ; 168} 169 170actions BuildUBootSDImage1 171{ 172 $(RM) $(1) 173 $(RM) $(1).mtools 174 175 # make an empty image 176 dd of=$(1) \ 177 if=/dev/zero \ 178 bs=$(SDIMAGE_BLOCK_SIZE) \ 179 count=$(SDIMAGE_SIZE) 180 # generate mtools config 181 echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C) 182 heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S) 183 mformat_only' > $(1).mtools 184 # partition it 185 MTOOLSRC=$(1).mtools mpartition -cI -T 0xc i: 186 # format the image 187 MTOOLSRC=$(1).mtools mformat -L 32 -v "Haiku" i: 188 189 # generate u-boot environment variables 190 echo '$(HAIKU_BOARD_SDIMAGE_UBOOT_UENV)' > uEnv.txt 191 # populate 192 MTOOLSRC=$(1).mtools mcopy $(2[1-]) i: 193 MTOOLSRC=$(1).mtools mcopy uEnv.txt i: 194 # list content 195 MTOOLSRC=$(1).mtools mdir i: 196 # cleanup 197 $(RM) $(1).mtools 198 $(RM) uEnv.txt 199 # Add haiku bootstrap partition to MMC image 200 #cat $(2[0]) >> $(1) 201} 202 203# uimage targets 204BuildUImage haiku_loader.ub : haiku_loader : 205 -A $(TARGET_ARCH) -O $(uImageFakeOS) -T kernel -C none 206 -a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_RAW) 207 -n 'haiku_loader $(TARGET_BOOT_BOARD)' ; 208 209local tgzArchive = haiku-floppyboot.tgz ; 210 211BuildUImage $(tgzArchive).ub : $(tgzArchive) : 212 -A $(TARGET_ARCH) -O linux -T ramdisk -C none 213 -n '$(tgzArchive) $(TARGET_BOOT_BOARD)' ; 214 215BuildUImage haiku_loader_linux.ub : haiku_loader : 216 -A $(TARGET_ARCH) -O linux -T kernel -C none 217 -a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_LINUX) 218 -n 'haiku_loader $(TARGET_BOOT_BOARD)' ; 219 220local fdtBinary = [ FDirName $(HAIKU_OUTPUT_DIR) $(HAIKU_BOARD_FDT_NAME).dtb ] ; 221CompileDTS $(fdtBinary) : [ FDirName $(HAIKU_TOP) src data dts arch $(TARGET_ARCH) $(HAIKU_BOARD_FDT_NAME).dts ] ; 222 223BuildUImage haiku_loader_nbsd.ub : haiku_loader $(tgzArchive) $(fdtBinary) : 224 -A $(TARGET_ARCH) -O $(uImageFakeOS) -T multi -C none 225 -a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_NBSD) 226 -n 'haiku_loader $(TARGET_BOOT_BOARD)' ; 227 228if $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT_NAME) { 229 BuildUImageScript $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT_NAME) : 230 $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT) ; 231} 232 233# flash image targets 234 235BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_raw.img : haiku_loader : 236 $(FLASH_IMAGE_PARTS) ; 237NotFile haiku-flash-image ; 238Depends haiku-flash-image : haiku-$(HAIKU_BOOT_BOARD)_flash_image_raw.img ; 239 240#BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_elf.img : boot_loader_u-boot : 241# $(FLASH_IMAGE_PARTS) ; 242#NotFile haiku-flash-elf-image ; 243#Depends haiku-flash-elf-image : haiku-$(HAIKU_BOOT_BOARD)_flash_image_elf.img ; 244 245BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_uimage.img : haiku_loader.ub : 246 $(FLASH_IMAGE_PARTS) ; 247NotFile haiku-flash-uimage ; 248Depends haiku-flash-uimage : haiku-$(HAIKU_BOOT_BOARD)_flash_image_uimage.img ; 249 250# SD/mmc image targets 251BuildUBootSDImage haiku-$(HAIKU_BOOT_BOARD).mmc : $(HAIKU_IMAGE) $(HAIKU_BOARD_SDIMAGE_FILES) ; 252NotFile haiku-mmc-image ; 253Depends haiku-mmc-image : haiku-$(HAIKU_BOOT_BOARD).mmc ; 254 255SEARCH on [ FGristFiles $(genericPlatformSources) ] 256 = [ FDirName $(HAIKU_TOP) src system boot platform generic ] ; 257 258SEARCH on [ FGristFiles openfirmware.cpp fdt_serial.cpp fdt_support.cpp ] 259 = [ FDirName $(HAIKU_TOP) src system kernel platform u-boot ] ; 260 261SEARCH on [ FGristFiles $(libFDTSources) ] 262 = [ FDirName $(HAIKU_TOP) src libs libfdt ] ; 263 264# Tell the build system to where stage1.bin can be found, so it can be used 265# elsewhere. 266SEARCH on stage1.bin = $(SUBDIR) ; 267 268SubInclude HAIKU_TOP src system boot platform u-boot arch ; 269