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"
67 export PATH
=/bin
:/sbin
:/usr
/bin
:/usr
/sbin
:/usr
/local
/bin
:/usr
/local
/sbin
:${PATH}
69 # we create a disk image of about 2 gig's
70 # for alignment reasons, prefer sizes which are multiples of 4096 bytes
71 : ${IMG_SIZE=$(( 2*(2**30) ))}
72 : ${ROOT_SIZE=$(( 64*(2**20) ))}
73 : ${HOME_SIZE=$(( 128*(2**20) ))}
74 : ${USR_SIZE=$(( 1792*(2**20) ))}
76 # set up disk creation environment
77 . releasetools
/image.defaults
78 . releasetools
/image.functions
80 # all sizes are written in 512 byte blocks
81 ROOTSIZEARG
="-b $((${ROOT_SIZE} / 512 / 8))"
82 USRSIZEARG
="-b $((${USR_SIZE} / 512 / 8))"
83 HOMESIZEARG
="-b $((${HOME_SIZE} / 512 / 8))"
85 # where the kernel & boot modules will be
86 MODDIR
=${DESTDIR}/boot
/minix
/.temp
88 echo "Building work directory..."
91 echo "Adding extra files..."
93 # create a fstab entry in /etc
94 cat >${ROOT_DIR}/etc
/fstab
<<END_FSTAB
95 /dev/c0d0p2 /usr mfs rw 0 2
96 /dev/c0d0p3 /home mfs rw 0 2
97 none /sys devman rw,rslabel=devman 0 0
98 none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
100 add_file_spec
"etc/fstab" extra.fstab
102 echo "Bundling packages..."
103 bundle_packages
"$BUNDLE_PACKAGES"
105 echo "Creating specification files..."
107 create_protos
"usr home"
109 # Download the stage 1 bootloader and u-boot
111 ${RELEASETOOLSDIR}/fetch_u-boot.sh
-o ${RELEASETOOLSDIR}/u-boot
-n $U_BOOT_GIT_VERSION
114 if [ -f ${IMG} ] # IMG might be a block device
120 # Create the empty image where we later will put the partitions in.
121 # Make sure it is at least 2GB, otherwise the SD card will not be detected
122 # correctly in qemu / HW.
124 dd if=/dev
/zero of
=${IMG} bs
=512 count
=1 seek
=$
((($IMG_SIZE / 512) -1))
127 # Generate /root, /usr and /home partition images.
129 echo "Writing disk image..."
130 FAT_START
=2048 # those are sectors
131 ROOT_START
=$
(($FAT_START + $FAT_SIZE))
133 _ROOT_SIZE
=$
(${CROSS_TOOLS}/nbmkfs.mfs -d ${ROOTSIZEARG} -I $((${ROOT_START}*512)) ${IMG} ${WORK_DIR}/proto.root
)
134 _ROOT_SIZE
=$
(($_ROOT_SIZE / 512))
135 USR_START
=$
((${ROOT_START} + ${_ROOT_SIZE}))
137 _USR_SIZE
=$
(${CROSS_TOOLS}/nbmkfs.mfs -d ${USRSIZEARG} -I $((${USR_START}*512)) ${IMG} ${WORK_DIR}/proto.usr
)
138 _USR_SIZE
=$
(($_USR_SIZE / 512))
139 HOME_START
=$
((${USR_START} + ${_USR_SIZE}))
141 _HOME_SIZE
=$
(${CROSS_TOOLS}/nbmkfs.mfs -d ${HOMESIZEARG} -I $((${HOME_START}*512)) ${IMG} ${WORK_DIR}/proto.home
)
142 _HOME_SIZE
=$
(($_HOME_SIZE / 512))
145 cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/MLO ${ROOT_DIR}/
146 cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/u-boot.img ${ROOT_DIR}/
148 # Create a uEnv.txt file
149 # -n default to network boot
150 # -p add a prefix to the network booted files (e.g. xm/"
151 # -c set console e.g. tty02 or tty00
152 # -v set verbosity e.g. 0 to 3
153 #${RELEASETOOLSDIR}/gen_uEnv.txt.sh -c ${CONSOLE} -n -p bb/ > ${WORK_DIR}/uEnv.txt
154 ${RELEASETOOLSDIR}/gen_uEnv.txt.sh -c ${CONSOLE} > ${ROOT_DIR}/uEnv.txt
156 # Do some last processing of the kernel and servers and then put them on the FAT
158 ${CROSS_PREFIX}objcopy ${OBJ}/minix/kernel/kernel -O binary ${ROOT_DIR}/kernel.bin
160 for f
in servers
/vm
/vm servers
/rs
/rs servers
/pm
/pm servers
/sched
/sched \
161 servers
/vfs
/vfs servers
/ds
/ds servers
/mib
/mib fs
/pfs
/pfs fs
/mfs
/mfs \
162 ..
/sbin
/init
/init drivers
/tty
/tty
/tty drivers
/storage
/memory
/memory
165 cp ${OBJ}/minix/${f} ${ROOT_DIR}/${fn}
166 ${CROSS_PREFIX}strip -s ${ROOT_DIR}/${fn}
168 cat >${WORK_DIR}/boot.mtree
<<EOF
171 ./u-boot.img type=file
173 ./kernel.bin type=file
177 ./sched.elf type=file
179 ./memory.elf type=file
189 # Create the FAT partition, which contains the bootloader files, kernel and modules
191 ${CROSS_TOOLS}/nbmakefs
-t msdos
-s ${FAT_SIZE}b
-o F
=16,c
=1 \
192 -F ${WORK_DIR}/boot.mtree ${WORK_DIR}/fat.img ${ROOT_DIR}
195 # Write the partition table using the natively compiled
196 # minix partition utility
198 ${CROSS_TOOLS}/nbpartition -f -m ${IMG} ${FAT_START} \
199 "c:${FAT_SIZE}*" 81:${_ROOT_SIZE} 81:${_USR_SIZE} 81:${_HOME_SIZE}
202 # Merge the partitions into a single image.
204 echo "Merging
file systems
"
205 dd if=${WORK_DIR}/fat.img of=${IMG} seek=$FAT_START conv=notrunc
207 echo "Disk image
at `pwd`/${IMG}"
208 echo "To boot this image on kvm
:"
209 echo "qemu-system-arm
-M beaglexm
-serial stdio
-drive if=sd
,cache
=writeback
,file=`pwd`/${IMG}"