3 # Copyright (c) 2015-2017 The FreeBSD Foundation
6 # Portions of this software were developed by Glen Barber
7 # under sponsorship from the FreeBSD Foundation.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Common subroutines used to build arm SD card images.
36 if [ -c "${DESTDIR}/dev/null" ]; then
37 umount_loop ${DESTDIR}/dev 2>/dev/null
39 umount_loop ${DESTDIR}
40 if [ ! -z "${mddev}" ]; then
41 mdconfig -d -u ${mddev}
51 while ! umount ${DIR}; do
53 if [ $i -ge 10 ]; then
54 # This should never happen. But, it has happened.
55 echo "Cannot umount(8) ${DIR}"
56 echo "Something has gone horribly wrong."
66 # Create the target raw file and temporary work directory.
67 chroot ${CHROOTDIR} gpart create -s ${PART_SCHEME} ${mddev}
68 chroot ${CHROOTDIR} gpart add -t '!12' -a 512k -s ${FAT_SIZE} ${mddev}
69 chroot ${CHROOTDIR} gpart set -a active -i 1 ${mddev}
70 chroot ${CHROOTDIR} newfs_msdos -L msdosboot -F ${FAT_TYPE} /dev/${mddev}s1
71 chroot ${CHROOTDIR} gpart add -t freebsd ${mddev}
72 chroot ${CHROOTDIR} gpart create -s bsd ${mddev}s2
73 chroot ${CHROOTDIR} gpart add -t freebsd-ufs -a 64k /dev/${mddev}s2
74 chroot ${CHROOTDIR} newfs -U -L rootfs /dev/${mddev}s2a
80 # Create a default user account 'freebsd' with the password 'freebsd',
81 # and set the default password for the 'root' user to 'root'.
82 chroot ${CHROOTDIR} /usr/sbin/pw -R ${DESTDIR} \
83 groupadd freebsd -g 1001
84 chroot ${CHROOTDIR} mkdir -p ${DESTDIR}/home/freebsd
85 chroot ${CHROOTDIR} /usr/sbin/pw -R ${DESTDIR} \
87 -m -M 0755 -w yes -n freebsd -u 1001 -g 1001 -G 0 \
88 -c 'FreeBSD User' -d '/home/freebsd' -s '/bin/csh'
89 chroot ${CHROOTDIR} /usr/sbin/pw -R ${DESTDIR} \
96 # Set up virtual serial port over USB OTG / device mode.
97 echo >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
98 echo '# Required for USB OTG virtual serial port.' \
99 >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
100 echo 'notify 100 {' \
101 >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
102 echo ' match "system" "DEVFS";' \
103 >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
104 echo ' match "subsystem" "CDEV";' \
105 >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
106 echo ' match "type" "CREATE";' \
107 >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
108 echo ' match "cdev" "ttyU[0-9]+";' \
109 >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
110 echo ' action "/sbin/init q";' \
111 >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
113 >> ${CHROOTDIR}/${DESTDIR}/etc/devd.conf
115 echo '# USB OTG virtual serial port' \
116 >> ${CHROOTDIR}/${DESTDIR}/etc/ttys
117 echo 'ttyU0 "/usr/libexec/getty 3wire" vt100 onifconsole secure' \
118 >> ${CHROOTDIR}/${DESTDIR}/etc/ttys
119 echo 'ttyU1 "/usr/libexec/getty 3wire" vt100 onifconsole secure' \
120 >> ${CHROOTDIR}/${DESTDIR}/etc/ttys
122 echo '# Configure USB OTG; see usb_template(4).' \
123 >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf
124 echo 'hw.usb.template=3' \
125 >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf
126 echo 'umodem_load="YES"' \
127 >> ${CHROOTDIR}/${DESTDIR}/boot/loader.conf
131 chroot ${CHROOTDIR} mount /dev/${mddev}s2a ${DESTDIR}
132 eval chroot ${CHROOTDIR} make -C ${WORLDDIR} \
133 TARGET=${EMBEDDED_TARGET} \
134 TARGET_ARCH=${EMBEDDED_TARGET_ARCH} \
135 DESTDIR=${DESTDIR} KERNCONF=${KERNEL} \
136 installworld installkernel distribution
137 chroot ${CHROOTDIR} mkdir -p ${DESTDIR}/boot/msdos
142 echo '# Custom /etc/fstab for FreeBSD embedded images' \
143 > ${CHROOTDIR}/${DESTDIR}/etc/fstab
144 echo "/dev/ufs/rootfs / ufs rw 1 1" \
145 >> ${CHROOTDIR}/${DESTDIR}/etc/fstab
146 echo "/dev/msdosfs/MSDOSBOOT /boot/msdos msdosfs rw,noatime 0 0" \
147 >> ${CHROOTDIR}/${DESTDIR}/etc/fstab
148 echo "tmpfs /tmp tmpfs rw,mode=1777,size=50m 0 0" \
149 >> ${CHROOTDIR}/${DESTDIR}/etc/fstab
152 hostname="$(echo ${KERNEL} | tr '[:upper:]' '[:lower:]')"
153 echo "hostname=\"${hostname}\"" > ${CHROOTDIR}/${DESTDIR}/etc/rc.conf
154 echo 'ifconfig_DEFAULT="DHCP"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf
155 echo 'sshd_enable="YES"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf
156 echo 'sendmail_enable="NONE"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf
157 echo 'sendmail_submit_enable="NO"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf
158 echo 'sendmail_outbound_enable="NO"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf
159 echo 'sendmail_msp_queue_enable="NO"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf
160 echo 'growfs_enable="YES"' >> ${CHROOTDIR}/${DESTDIR}/etc/rc.conf
163 umount_loop ${CHROOTDIR}/${DESTDIR}
169 FATMOUNT="${DESTDIR%${KERNEL}}/fat"
170 UFSMOUNT="${DESTDIR%${KERNEL}}/ufs"
171 chroot ${CHROOTDIR} mkdir -p "${FATMOUNT}" "${UFSMOUNT}"
172 chroot ${CHROOTDIR} mount_msdosfs /dev/${mddev}s1 ${FATMOUNT}
173 chroot ${CHROOTDIR} mount /dev/${mddev}s2a ${UFSMOUNT}
175 if [ "${EMBEDDED_TARGET}" == "arm" ]; then
176 chroot ${CHROOTDIR} cp -p ${UFSMOUNT}/boot/ubldr.bin \
177 ${FATMOUNT}/ubldr.bin
180 BOOTFILES="$(chroot ${CHROOTDIR} \
181 env TARGET=${EMBEDDED_TARGET} TARGET_ARCH=${EMBEDDED_TARGET_ARCH} \
182 WITH_UNIFIED_OBJDIR=yes \
183 make -C ${WORLDDIR}/stand -V .OBJDIR)"
184 BOOTFILES="$(chroot ${CHROOTDIR} realpath ${BOOTFILES})"
186 chroot ${CHROOTDIR} mkdir -p ${FATMOUNT}/EFI/BOOT
187 chroot ${CHROOTDIR} cp -p ${BOOTFILES}/efi/loader/loader.efi \
188 ${FATMOUNT}/EFI/BOOT/$(efi_boot_name ${EMBEDDED_TARGET})
190 chroot ${CHROOTDIR} touch ${UFSMOUNT}/firstboot
192 umount_loop ${CHROOTDIR}/${FATMOUNT}
193 umount_loop ${CHROOTDIR}/${UFSMOUNT}
194 chroot ${CHROOTDIR} rmdir ${FATMOUNT}
195 chroot ${CHROOTDIR} rmdir ${UFSMOUNT}
198 arm_install_uboot() {
199 # Override in the arm/KERNEL.conf file.