xref: /haiku/build/jam/images/MMCImage (revision 6f80a9801fedbe7355c4360bd204ba746ec3ec2d)
1# Set anyboot file name and directory defaults.
2HAIKU_MMC_NAME ?= $(HAIKU_DEFAULT_MMC_NAME) ;
3HAIKU_MMC_DIR ?= $(HAIKU_DEFAULT_MMC_DIR) ;
4HAIKU_MMC = $(HAIKU_MMC_NAME) ;
5HAIKU_MMC_LABEL ?= $(HAIKU_DEFAULT_MMC_LABEL) ;
6
7# SD/mmc image rule
8# Files must be in this order:
9#  out : mbrtool fatshell os_image loader floppyboot everything_else
10rule BuildSDImage image : files
11{
12	local mbrtool = <build>mbrtool ;
13	local fatshell = <build>fat_shell ;
14
15	Depends $(image) : $(files) $(TARGET_DEVICE_TREES) ;
16	Depends $(image) : $(HAIKU_IMAGE_NAME) ;
17	Depends $(image) : $(mbrtool) ;
18	Depends $(image) : $(fatshell) ;
19
20	SDIMAGE_OS_SIZE on $(image) = $(HAIKU_IMAGE_SIZE) ;
21	SDIMAGE_BEGIN on $(image) = $(HAIKU_BOOT_SDIMAGE_BEGIN:E=63) ;
22
23	if $(TARGET_BOOT_PLATFORM) = efi {
24		switch $(TARGET_ARCH) {
25			case x86 :
26				EFINAME on $(image) = "BOOTIA32.EFI" ;
27			case x86_64 :
28				EFINAME on $(image) = "BOOTX64.EFI" ;
29			case arm :
30				EFINAME on $(image) = "BOOTARM.EFI" ;
31			case arm64 :
32				EFINAME on $(image) = "BOOTAA64.EFI" ;
33			case riscv32 :
34				EFINAME on $(image) = "BOOTRISCV32.EFI" ;
35			case riscv64 :
36				EFINAME on $(image) = "BOOTRISCV64.EFI" ;
37			case * :
38				Exit "Error: Unknown EFI architecture!" ;
39		}
40		BuildEfiSDImage1 $(image) : $(mbrtool) $(fatshell) $(files) ;
41	} else if $(TARGET_BOOT_PLATFORM) = u-boot {
42		BuildUBootSDImage1 $(image) : $(mbrtool) $(fatshell) $(files) ;
43	} else {
44		# TODO: For now we do nothing. Maybe we want a "AddSDImage" to
45		# append additional loaders like the raw riscv one?
46		echo "Asked for $(TARGET_BOOT_PLATFORM) target boot platform" ;
47		echo "Unknown path to handle adding to image" ;
48	}
49}
50
51# Usage:
52#  out : mbrtool fatshell os_image loader floppyboot everything_else
53actions BuildUBootSDImage1
54{
55	$(RM) $(1)
56
57	export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
58
59	# in KiB
60	EFI_SIZE=32768
61	BOOT_SIZE=`expr ${EFI_SIZE} + $(SDIMAGE_BEGIN)`
62	MMC_SIZE=`expr $(SDIMAGE_OS_SIZE) \* 1024 + ${BOOT_SIZE}`
63
64	# Build "boot" disk
65	dd if=/dev/zero of=$(1) bs=1024 count=${BOOT_SIZE}
66
67	# generate u-boot environment variables
68	echo 'os=haiku' > uEnv.txt
69	echo 'platform=u-boot' >> uEnv.txt
70	echo "loader=haiku_loader.ub" >> uEnv.txt
71
72	# Lay down partition map
73	OS_LENGTH=`expr ${MMC_SIZE} - ${BOOT_SIZE}`
74
75	# EFI System Partition
76	$(2[1]) $(1) 0 0xef $(SDIMAGE_BEGIN) ${EFI_SIZE}
77	# OS Partition
78	$(2[1]) $(1) 1 0xeb ${BOOT_SIZE} ${OS_LENGTH}
79
80	FATFS="$(2[2]) --start-offset `expr $(SDIMAGE_BEGIN) \* 1024`"
81
82	# format the image
83	${FATFS} --end-offset `expr ${BOOT_SIZE} \* 1024` \
84		--initialize "$(1)" 'Haiku Boot'
85
86	# populate
87	for i in $(2[4-]) ; do
88		echo "cp :${i} myfs/" | ${FATFS} $(1)
89	done
90
91	echo "cp :uEnv.txt myfs/" | ${FATFS} $(1)
92
93	# lay down FDT's
94	echo "mkdir myfs/fdt" | ${FATFS} $(1)
95	for i in $(TARGET_DEVICE_TREES[1-]) ; do
96		echo "cp :${i} myfs/fdt/" | ${FATFS} $(1)
97	done
98
99	# list content
100	echo "ls myfs" | ${FATFS} $(1)
101
102	# cleanup
103	$(RM) uEnv.txt
104	$(RM) boot.scr
105
106	# Add haiku partition to MMC image
107	cat $(2[3-3]) >> $(1)
108}
109
110
111# Usage:
112#  out : mbrtool fatshell os_image loader floppyboot everything_else
113actions BuildEfiSDImage1
114{
115	$(RM) $(1)
116
117	export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
118
119	# in KiB
120	EFI_SIZE=32768
121	BOOT_SIZE=`expr ${EFI_SIZE} + $(SDIMAGE_BEGIN)`
122	MMC_SIZE=`expr $(SDIMAGE_OS_SIZE) \* 1024 + ${BOOT_SIZE}`
123
124	# Build "boot" disk
125	dd if=/dev/zero of=$(1) bs=1024 count=${BOOT_SIZE}
126
127	# generate u-boot environment variables
128	echo 'os=haiku' > uEnv.txt
129	echo 'platform=efi' >> uEnv.txt
130	echo "loader=EFI/BOOT/$(EFINAME)" >> uEnv.txt
131
132	# Lay down partition map
133	OS_LENGTH=`expr ${MMC_SIZE} - ${BOOT_SIZE}`
134
135	# EFI System Partition
136	$(2[1]) $(1) 0 0xef $(SDIMAGE_BEGIN) ${EFI_SIZE}
137	# OS Partition
138	$(2[1]) $(1) 1 0xeb ${BOOT_SIZE} ${OS_LENGTH}
139
140	FATFS="$(2[2]) --start-offset `expr $(SDIMAGE_BEGIN) \* 1024`"
141
142	# format the image
143	${FATFS} --end-offset `expr ${BOOT_SIZE} \* 1024` \
144		--initialize "$(1)" 'Haiku Boot'
145
146	# populate
147	echo "mkdir -p myfs/EFI/BOOT" | ${FATFS} $(1)
148	echo "cp :$(2[4-4]) myfs/EFI/BOOT/$(EFINAME)" | ${FATFS} $(1)
149
150	# copy misc files
151	for i in $(2[5-]) ; do
152		echo "cp :${i} myfs/" | ${FATFS} $(1)
153	done
154	echo "cp :uEnv.txt myfs/" | ${FATFS} $(1)
155
156	# lay down FDT's
157	echo "mkdir myfs/fdt" | ${FATFS} $(1)
158	for i in $(TARGET_DEVICE_TREES[1-]) ; do
159		echo "cp :${i} myfs/fdt/" | ${FATFS} $(1)
160	done
161
162	# list content
163	echo "ls myfs" | ${FATFS} $(1)
164
165	# cleanup
166	$(RM) uEnv.txt
167	$(RM) boot.scr
168
169	# Add haiku partition to MMC image
170	cat $(2[3-3]) >> $(1)
171}
172
173for platform in [ MultiBootSubDirSetup ] {
174	on $(platform) {
175		# SD/mmc image targets
176		if $(TARGET_BOOT_PLATFORM) = efi {
177			if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = riscv64 {
178				# These EFI platforms need u-boot to get them going
179				BuildSDImage $(HAIKU_MMC_NAME) : $(HAIKU_IMAGE)
180					haiku_loader.$(TARGET_BOOT_PLATFORM)
181					boot.scr ;
182			} else {
183				BuildSDImage $(HAIKU_MMC_NAME) : $(HAIKU_IMAGE)
184					haiku_loader.$(TARGET_BOOT_PLATFORM) ;
185			}
186		} else if $(TARGET_BOOT_PLATFORM) = u-boot {
187			BuildSDImage $(HAIKU_MMC_NAME) :
188				$(HAIKU_IMAGE) haiku_loader.$(TARGET_BOOT_PLATFORM) haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) boot.scr ;
189		} else {
190			BuildSDImage $(HAIKU_MMC_NAME) :
191				$(HAIKU_IMAGE) haiku_loader.$(TARGET_BOOT_PLATFORM) boot.scr ;
192		}
193	}
194}
195
196#BlessSDImage haiku-$(TARGET_KERNEL_ARCH).mmc ;
197NotFile haiku-mmc-image ;
198Depends haiku-mmc-image : $(HAIKU_MMC_NAME) ;
199