5 # This script creates a bootable image and should at some point in the future
6 # be replaced by the proper NetBSD infrastructure.
10 # Source settings if present
12 : ${SETTINGS_MINIX=.settings}
13 if [ -f "${SETTINGS_MINIX}" ]
15 echo "Sourcing settings from ${SETTINGS_MINIX}"
16 # Display the content (so we can check in the build logs
17 # what the settings contain.
18 cat ${SETTINGS_MINIX} |
sed "s,^,CONTENT ,g"
23 : ${OBJ=../obj.${ARCH}}
24 : ${TOOLCHAIN_TRIPLET=arm-elf32-minix-}
27 : ${SETS="minix-base minix-comp minix-games minix-man minix-tests tests"}
28 : ${IMG=minix_arm_sd.img}
31 : ${BUILDVARS=-V MKGCCCMDS=yes -V MKLLVM=no}
32 # These BUILDVARS are for building with LLVM:
33 #: ${BUILDVARS=-V MKLIBCXX=no -V MKKYUA=no -V MKATF=no -V MKLLVMCMDS=no}
34 : ${FAT_SIZE=$(( 10*(2**20) / 512))} # This is in sectors
37 : ${U_BOOT_BIN_DIR=build/omap3_beagle/}
40 # BeagleBone (and black)
41 #: ${U_BOOT_BIN_DIR=build/am335x_evm/}
45 # We host u-boot binaries.
49 U_BOOT_GIT_VERSION
=cb5178f12787c690cb1c888d88733137e5a47b15
51 if [ ! -f ${BUILDSH} ]
53 echo "Please invoke me from the root source dir, where ${BUILDSH} is."
59 #we no longer download u-boot but do a checkout
60 #BASE_URL used to be the base url for u-boot
62 echo "Warning:** Setting BASE_URL (u-boot) is no longer possible use U_BOOT_BIN_DIR"
63 echo "Look in ${RELEASETOOLSDIR}/arm_sdimage.sh for suggested values"
69 MKFS_VFAT_CMD
=newfs_msdos
70 MKFS_VFAT_OPTS
="-h 64 -u 32 -S 512 -s ${FAT_SIZE} -o 0"
73 MKFS_VFAT_CMD
=newfs_msdos
77 MKFS_VFAT_CMD
=mkfs.vfat
82 export PATH
=/bin
:/sbin
:/usr
/bin
:/usr
/sbin
:/usr
/local
/bin
:/usr
/local
/sbin
:${PATH}
84 for needed
in mcopy
dd ${MKFS_VFAT_CMD} git
86 if ! which $needed 2>&1 > /dev
/null
88 echo "**Skipping image creation: missing tool '$needed'"
93 # we create a disk image of about 2 gig's
94 # for alignment reasons, prefer sizes which are multiples of 4096 bytes
95 : ${IMG_SIZE=$(( 2*(2**30) ))}
96 : ${ROOT_SIZE=$(( 64*(2**20) ))}
97 : ${HOME_SIZE=$(( 128*(2**20) ))}
98 : ${USR_SIZE=$(( 1792*(2**20) ))}
100 # set up disk creation environment
101 . releasetools
/image.defaults
102 . releasetools
/image.functions
104 # all sizes are written in 512 byte blocks
105 ROOTSIZEARG
="-b $((${ROOT_SIZE} / 512 / 8))"
106 USRSIZEARG
="-b $((${USR_SIZE} / 512 / 8))"
107 HOMESIZEARG
="-b $((${HOME_SIZE} / 512 / 8))"
109 # where the kernel & boot modules will be
110 MODDIR
=${DESTDIR}/boot
/minix
/.temp
112 echo "Building work directory..."
113 build_workdir
"$SETS"
115 echo "Adding extra files..."
117 # create a fstab entry in /etc
118 cat >${ROOT_DIR}/etc
/fstab
<<END_FSTAB
119 /dev/c0d0p2 /usr mfs rw 0 2
120 /dev/c0d0p3 /home mfs rw 0 2
121 none /sys devman rw,rslabel=devman 0 0
122 none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
124 add_file_spec
"etc/fstab" extra.fstab
126 echo "Bundling packages..."
127 bundle_packages
"$BUNDLE_PACKAGES"
129 echo "Creating specification files..."
131 create_protos
"usr home"
134 # Create the FAT partition, which contains the bootloader files, kernel and modules
136 dd if=/dev
/zero of
=${WORK_DIR}/fat.img bs
=512 count
=1 seek
=$
(($FAT_SIZE -1)) 2>/dev
/null
139 # Format the fat partition and put the bootloaders
140 # uEnv and the kernel command line in the FAT partition
142 ${MKFS_VFAT_CMD} ${MKFS_VFAT_OPTS} ${WORK_DIR}/fat.img
145 # Download the stage 1 bootloader and u-boot
147 ${RELEASETOOLSDIR}/fetch_u-boot.sh
-o ${RELEASETOOLSDIR}/u-boot
-n $U_BOOT_GIT_VERSION
148 cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/MLO ${WORK_DIR}/
149 cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/u-boot.img ${WORK_DIR}/
152 # Create a uEnv.txt file
153 # -n default to network boot
154 # -p add a prefix to the network booted files (e.g. xm/"
155 # -c set console e.g. tty02 or tty00
156 # -v set verbosity e.g. 0 to 3
157 #${RELEASETOOLSDIR}/gen_uEnv.txt.sh -c ${CONSOLE} -n -p bb/ > ${WORK_DIR}/uEnv.txt
158 ${RELEASETOOLSDIR}/gen_uEnv.txt.sh -c ${CONSOLE} > ${WORK_DIR}/uEnv.txt
160 echo "Copying configuration kernel and boot modules"
161 mcopy
-bsp -i ${WORK_DIR}/fat.img
${WORK_DIR}/$MLO ::MLO
162 mcopy
-bsp -i ${WORK_DIR}/fat.img
${WORK_DIR}/$UBOOT ::u-boot.img
163 mcopy
-bsp -i ${WORK_DIR}/fat.img
${WORK_DIR}/uEnv.txt
::uEnv.txt
166 # Do some last processing of the kernel and servers and then put them on the FAT
169 ${CROSS_PREFIX}objcopy ${OBJ}/minix/kernel/kernel -O binary ${OBJ}/kernel.bin
170 mcopy
-bsp -i ${WORK_DIR}/fat.img
${OBJ}/kernel.bin
::kernel.bin
172 for f
in servers
/vm
/vm servers
/rs
/rs servers
/pm
/pm servers
/sched
/sched \
173 servers
/vfs
/vfs servers
/ds
/ds servers
/mib
/mib fs
/pfs
/pfs fs
/mfs
/mfs \
177 cp ${OBJ}/minix/${f} ${OBJ}/${fn}
178 ${CROSS_PREFIX}strip -s ${OBJ}/${fn}
179 mcopy
-bsp -i ${WORK_DIR}/fat.img ${OBJ}/${fn} ::${fn}
182 for f
in tty
/tty
/tty storage
/memory
/memory
185 cp ${OBJ}/minix/drivers/${f} ${OBJ}/${fn}
186 ${CROSS_PREFIX}strip -s ${OBJ}/${fn}
187 mcopy
-bsp -i ${WORK_DIR}/fat.img ${OBJ}/${fn} ::${fn}
193 cp ${WORK_DIR}/uEnv.txt
${OBJ}/
196 if [ -f ${IMG} ] # IMG might be a block device
202 # Create the empty image where we later will put the partitions in.
203 # Make sure it is at least 2GB, otherwise the SD card will not be detected
204 # correctly in qemu / HW.
206 dd if=/dev
/zero of
=${IMG} bs
=512 count
=1 seek
=$
((($IMG_SIZE / 512) -1))
209 # Generate /root, /usr and /home partition images.
211 echo "Writing disk image..."
212 FAT_START
=2048 # those are sectors
213 ROOT_START
=$
(($FAT_START + $FAT_SIZE))
215 _ROOT_SIZE
=$
(${CROSS_TOOLS}/nbmkfs.mfs -d ${ROOTSIZEARG} -I $((${ROOT_START}*512)) ${IMG} ${WORK_DIR}/proto.root
)
216 _ROOT_SIZE
=$
(($_ROOT_SIZE / 512))
217 USR_START
=$
((${ROOT_START} + ${_ROOT_SIZE}))
219 _USR_SIZE
=$
(${CROSS_TOOLS}/nbmkfs.mfs -d ${USRSIZEARG} -I $((${USR_START}*512)) ${IMG} ${WORK_DIR}/proto.usr
)
220 _USR_SIZE
=$
(($_USR_SIZE / 512))
221 HOME_START
=$
((${USR_START} + ${_USR_SIZE}))
223 _HOME_SIZE
=$
(${CROSS_TOOLS}/nbmkfs.mfs -d ${HOMESIZEARG} -I $((${HOME_START}*512)) ${IMG} ${WORK_DIR}/proto.home
)
224 _HOME_SIZE
=$
(($_HOME_SIZE / 512))
227 # Write the partition table using the natively compiled
228 # minix partition utility
230 ${CROSS_TOOLS}/nbpartition -f -m ${IMG} ${FAT_START} "c:${FAT_SIZE}*" 81:${_ROOT_SIZE} 81:${_USR_SIZE} 81:${_HOME_SIZE}
233 # Merge the partitions into a single image.
235 echo "Merging file systems"
236 dd if=${WORK_DIR}/fat.img of
=${IMG} seek
=$FAT_START conv
=notrunc
238 echo "Disk image at `pwd`/${IMG}"
239 echo "To boot this image on kvm:"
240 echo "qemu-system-arm -M beaglexm -serial stdio -drive if=sd,cache=writeback,file=`pwd`/${IMG}"