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