]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/nanobsd/embedded/common
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r307894, and update
[FreeBSD/FreeBSD.git] / tools / tools / nanobsd / embedded / common
1 # $FreeBSD$
2
3 #-
4 # Copyright (c) 2015 Warner Losh. All Rights Reserved.
5 # Copyright (c) 2010-2011 iXsystems, Inc., All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED.  IN NO EVENT SHALL iXsystems, Inc OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # SUCH DAMAGE.
27 #
28 #
29 # This file is heavily derived from both Sam Leffler's Avilia config,
30 # as well as the BSDRP project's config file.  Neither of these have
31 # an explicit copyright/license statement, but are implicitly BSDL. This
32 # example has been taken from the FreeNAS project (an early version) and
33 # simplified to meet the needs of the example.
34 #
35
36 # NB: You want the other file as the command line arg :)
37
38 # Missing in base:
39 # o mkimg setting active partition
40 # o mkimg starting at arbitrary offset (needed for A10, et al)
41 # o mtools still needed because we have no makefs -t msdos
42 # o nanobsd doesn't record changes to WORLDTEMP in customization
43 #   scripts yet, so we have kludge to pick up all files
44 # o easy way for pkg to grab files from other repos and put that
45 #   data on the image
46 # o Need to have some way to create / resize the s4 slice to do ping
47 #   pong bouncing between s3 and s4 for an arbitrary image. we can resize
48 #   one slice, not two
49 # o hints in the uboot ports for how to create the image
50 #
51 # Missing here
52 # o documentation for how to run the qemu images
53 # o msdos mtools fallback
54 # o special boot for !x86 !arm platforms
55 # o qemu image for arm
56 # o qemu image for aarch64
57 # o qemu image for armv6/armv7
58 # o easy support for different image / vm formats
59 # o need to promote much of this to nanobsd.sh and friends
60 # o uses old kludge to build image w/o ownership being right
61 #   for many files. Should move to mtree-dedup.awk.
62 # o support for EFI images
63 # o support for GPT partitioning
64 #
65 # Long Term
66 # o common tooling for creating images for odd-ball platforms
67 # o support for boot loaders other than uboot in the image
68 #   or via special instructions
69 # o No pony support. Sadly, you cannot have a pony.
70 #
71
72 if [ -z $NANO_NAME ]; then
73         echo "NANO_NAME not defined. Use foo.cfg instead."
74 fi
75
76 NANO_SLICE_FAT_SIZE=32m
77 NANO_SLICE_CFG_SIZE=32m
78
79 NANO_BOOT2CFG="-P -S115200"
80
81 NANO_RAM_ETCSIZE=8192
82 NANO_RAM_TMPVARSIZE=8192
83 NANO_IMAGES=2
84
85 NANO_PMAKE="make -j $(sysctl -n hw.ncpu)"
86
87 NANO_CFG_BASE=$(pwd)
88 NANO_CFG_BASE=$(realpath ${NANO_CFG_BASE}/..)
89 NANO_SRC=$(realpath ${NANO_CFG_BASE}/../../..)
90 #### XXX share obj 
91 if [ -z ${NANO_CPUTYPE} ]; then
92         NANO_OBJ=${NANO_SRC}/../embedded/obj
93 else
94         # Alas, I can't set OBJTREE to ${MACHINE}.${MACHINE_ARCH}.${CPUTYPE}
95         # so this will have to do until I can.
96         NANO_OBJ=${NANO_SRC}/../embedded/obj.${NANO_CPUTYPE}
97 fi
98 NANO_LOG=${NANO_OBJ}/../${NANO_NAME}
99 NANO_DISKIMGDIR=${NANO_OBJ}/../images
100 NANO_WORLDDIR=${NANO_LOG}/_.w
101 NANO_INIT_IMG2=0
102 NANO_NOPRIV_BUILD=t
103 unset MAKEOBJDIRPREFIX
104
105 mkdir -p ${NANO_OBJ}
106 NANO_OBJ=$(realpath ${NANO_OBJ})
107 mkdir -p ${NANO_LOG}
108 NANO_LOG=$(realpath ${NANO_LOG})
109 mkdir -p ${NANO_IMAGES}
110 NANO_IMAGES=$(realpath ${NANO_IMAGES})
111 mkdir -p ${NANO_WORLDDIR}
112 NANO_WORLDDIR=$(realpath ${NANO_WORLDDIR})
113 mkdir -p ${NANO_DISKIMGDIR}
114 NANO_DISKIMGDIR=$(realpath ${NANO_DISKIMGDIR})
115
116 NANO_FAT_DIR=${NANO_LOG}/_.fat
117
118 customize_cmd cust_allow_ssh_root
119
120 add_etc_make_conf ( ) (
121         touch ${NANO_WORLDDIR}/etc/make.conf
122 )
123 customize_cmd add_etc_make_conf
124
125 cust_install_machine_files ( ) (
126         echo "cd ${NANO_CFG_BASE}/Files"
127         cd ${NANO_CFG_BASE}/Files
128         find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -dumpv ${NANO_WORLDDIR}
129 )
130 customize_cmd cust_install_files
131 customize_cmd cust_install_machine_files 
132
133 # NB: leave c++ enabled so devd can be built
134 CONF_BUILD="
135 LOCAL_XTOOL_DIRS=usr.bin/mkimg
136 WITHOUT_ACPI=true
137 WITHOUT_ATM=true
138 WITHOUT_AUDIT=true
139 WITHOUT_BIND_DNSSEC=true
140 WITHOUT_BIND_ETC=true
141 WITHOUT_BIND_LIBS_LWRES=true
142 WITHOUT_BLUETOOTH=true
143 WITHOUT_CALENDAR=true
144 WITHOUT_CVS=true
145 WITHOUT_DICT=true
146 WITHOUT_EXAMPLES=true
147 WITHOUT_FORTRAN=true
148 WITHOUT_GAMES=true
149 WITHOUT_GCOV=true
150 WITHOUT_GPIB=true
151 WITHOUT_HTML=true
152 WITHOUT_I4B=true
153 WITHOUT_IPFILTER=true
154 WITHOUT_IPX=true
155 WITHOUT_LIBKSE=true
156 WITHOUT_LOCALES=true
157 WITHOUT_LPR=true
158 WITHOUT_MAN=true
159 WITHOUT_NETCAT=true
160 WITHOUT_NIS=true
161 WITHOUT_NLS=true
162 WITHOUT_NS_CACHING=true
163 WITHOUT_OBJC=true
164 WITHOUT_PROFILE=true
165 WITHOUT_RCMDS=true
166 WITHOUT_SENDMAIL=true
167 WITHOUT_SHAREDOCS=true
168 WITHOUT_SYSCONS=true
169 WITHOUT_LIB32=true
170 WITHOUT_TESTS=true
171 WITHOUT_DEBUG_FILES=t
172 WITHOUT_KERNEL_SYMBOLS=t
173 "
174 CONF_INSTALL="$CONF_BUILD
175 INSTALL_NODEBUG=t
176 NOPORTDOCS=t
177 NO_INSTALL_MANPAGES=t
178 "
179 # The following would help...
180 # WITHOUT_TOOLCHAIN=true                can't build ports
181 # WITHOUT_INSTALLLIB=true               libgcc.a
182 #
183 # from the build
184 # WITHOUT_INFO=true                     makeinfo
185 # WITHOUT_RCS=true
186 PKG_ONLY_MAKE_CONF="
187 WITHOUT_TOOLCHAIN=true
188 WITHOUT_INSTALLLIB=true
189 WITHOUT_INFO=true
190 WITHOUT_RCS=true
191 "
192
193 NANO_PACKAGE_ONLY=1
194
195 # Creates images for all the formats that use MBR / GPT
196 # split later if the #ifdef soup gets too bad.
197 create_diskimage_gpt ( ) (
198         pprint 2 "build diskimage gpt ${NANO_NAME}"
199
200         create_diskimage_mbr $*
201 )
202
203 create_diskimage_mbr ( ) (
204
205         local fmt
206
207         [ -z ${NANO_DISKIMAGE_FORMAT} ] || fmt=".${NANO_DISKIMAGE_FORMAT}"
208
209         pprint 2 "build diskimage ${NANO_NAME}"
210         pprint 3 "log: ${NANO_LOG}/_.di"
211         pprint 3 "image in: ${NANO_DISKIMGDIR}/_.disk.image.${NANO_NAME}${fmt}"
212
213         (
214         local extra i sz fmt fmtarg bootmbr bootbsd skiparg
215         set -o xtrace
216         # Tell mtools not to be too picky
217         export MTOOLS_SKIP_CHECK=1
218
219         [ -z ${NANO_DISKIMAGE_FORMAT} ] || fmtarg="-f ${NANO_DISKIMAGE_FORMAT}"
220         [ -z ${NANO_DISKIMAGE_FORMAT} ] || fmt=".${NANO_DISKIMAGE_FORMAT}"
221         bootmbr=${NANO_BOOT_MBR:+-b ${NANO_BOOT_MBR}}
222         bootbsd=${NANO_BOOT_BSD:+-b ${NANO_BOOT_BSD}}
223         skiparg=${NANO_MBR_FIRST_SKIP:+-S ${NANO_MBR_FIRST_SKIP}}
224
225         for i in s1 s2 s3 s4 p1 p2 p3 p4 p5 empty; do
226                 rm -fr ${NANO_LOG}/_.${i}*
227         done
228
229         # Populate the FAT partition, if needed
230         if [ -n "${NANO_SLICE_FAT}" ]; then
231                 echo Creating MSDOS partition for kernel
232                 newfs_msdos -C ${NANO_SLICE_FAT_SIZE} -F 16 -L ${NANO_NAME} \
233                         ${NANO_LOG}/_.${NANO_SLICE_FAT}
234                 if [ -d ${NANO_FAT_DIR} ]; then
235                         # Need to copy files from ${NANO_FATDIR} with mtools, or use
236                         # makefs -t msdos once that's supported
237                         mcopy -i ${NANO_LOG}/_.${NANO_SLICE_FAT} ${NANO_FAT_DIR}/* ::
238                 fi
239         fi
240
241         # Populate the Powerpc boot image, if needed
242         if [ "${NANO_LAYOUT}" = powerpc64-ibm ]; then
243                 dd if=${NANO_WORLDDIR}/boot/boot1.elf of=${NANO_LOG}/_.s1 bs=800k count=1 conv=sync
244         fi
245
246         # Populate the / partition, and place it into a slice with a
247         # bsd label
248         [ -z ${NANO_NOPRIV_BUILD} ] || extra="-F ${NANO_METALOG}"
249         sz=${NANO_SLICE_ROOT_SIZE:+-s ${NANO_SLICE_ROOT_SIZE}}
250         eval "${NANO_MAKEFS_UFS}" ${extra} $sz "${NANO_LOG}/_.${NANO_ROOT}" \
251                 "${NANO_WORLDDIR}"
252         case ${NANO_DISK_SCHEME} in
253         mbr)
254                 mkimg -s bsd ${bootbsd} -p freebsd-ufs:=${NANO_LOG}/_.${NANO_ROOT} \
255                         -o ${NANO_LOG}/_.${NANO_SLICE_ROOT}
256                 eval $NANO_SLICE_CFG=freebsd
257                 eval $NANO_SLICE_ROOT=freebsd
258                 ;;
259         gpt)
260                 eval $NANO_SLICE_CFG=freebsd-ufs
261                 eval $NANO_SLICE_ROOT=freebsd-ufs
262                 ;;
263         esac
264
265         # Populate the /cfg partition, empty if none given
266         if [ -z "${NANO_CFGDIR}" ]; then
267                 echo "Faking cfg dir, it's empty"
268                 NANO_CFGDIR=${NANO_LOG}/_.empty
269                 mkdir -p ${NANO_CFGDIR}
270         fi
271         # XXX -F cfg-mtree
272         eval "${NANO_MAKEFS_UFS}" -s ${NANO_SLICE_CFG_SIZE} \
273                 "${NANO_LOG}/_.${NANO_SLICE_CFG}" "${NANO_CFGDIR}"
274
275         # data slice not supported since we need the part for FAT for 
276         # booting
277
278         # Now shuffle all the slices together into the proper layout
279         if [ -n "$NANO_SLICE_FAT" ]; then
280                 eval $NANO_SLICE_FAT=fat16b
281         fi
282
283         out=${NANO_DISKIMGDIR}/_.disk.image.${NANO_NAME}${fmt}
284         # below depends on https://reviews.freebsd.org/D4403 not yet in the tree
285         # but there's problems: it marks all partitions as active, so you have to
286         # boot off parittion 3 or 2 by hand if you're playing around with this WIP
287         case ${NANO_LAYOUT} in
288         std-embedded)
289                 mkimg -a 3 ${skiparg} ${fmtarg} ${bootmbr} -s mbr -p ${s1}:=${NANO_LOG}/_.s1 \
290                         -p ${s2}:=${NANO_LOG}/_.s2 \
291                         -p ${s3}:=${NANO_LOG}/_.s3 \
292                         -o ${out}
293                 ;;
294         std-x86)
295                 # s1 is cfg, s2 is /, not sure how to make that
296                 # boot (marked as active) with mkimg yet
297                 mkimg -a 2 ${fmtarg} ${bootmbr} -s mbr -p ${s1}:=${NANO_LOG}/_.s1 \
298                         -p ${s2}:=${NANO_LOG}/_.s2 \
299                         -o ${out}
300                 ;;
301         std-uefi)
302                 # s1 is boot, s2 is cfg, s3 is /, not sure how to make that
303                 # boot (marked as active) with mkimg yet
304                 mkimg -a 2 ${fmtarg} ${bootmbr} -s mbr \
305                         -p efi:=${NANO_WORLDDIR}/boot/boot1.efifat \
306                         -p ${s2}:=${NANO_LOG}/_.s2 \
307                         -p ${s3}:=${NANO_LOG}/_.s3 \
308                         -o ${out}
309                 ;;
310         std-uefi-bios)
311                 # p1 is boot for uefi, p2 is boot for gpt, p3 is cfg, p4 is /
312                 # and p5 is alt-root (after resize)
313                 mkimg -a 2 ${fmtarg} ${bootmbr} -s gpt \
314                         -p efi:=${NANO_WORLDDIR}/boot/boot1.efifat \
315                         -p freebsd-boot:=${NAANO_WORLDDIR}/boot/gptboot \
316                         -p ${p3}:=${NANO_LOG}/_.p3 \
317                         -p ${p4}:=${NANO_LOG}/_.p4 \
318                         -o ${out}
319                 ;;
320         powerpc64-ibm)
321                 # A lie to make the boot loader work, it boots the first BSD partition
322                 # it finds, regardless of the active flag.
323                 s2=fat16b
324                 # boot image is on a special partition, ala std-embedded, but that
325                 # partition isn't FAT with special files, but a copy of the boot
326                 # loader itself.
327                 mkimg -a 1 ${fmtarg} -s mbr -p prepboot:=${NANO_LOG}/_.s1 \
328                         -p ${s2}:=${NANO_LOG}/_.s2 \
329                         -p ${s3}:=${NANO_LOG}/_.s3a \
330                         -o ${out}
331                 ;;
332         esac
333         rm -f ${out}.xz
334         xz -9 --keep ${out}
335         ) > ${NANO_LOG}/_.di 2>&1
336 )
337
338 die( ) {
339         echo "$*"
340         exit 1
341 }
342
343 # Automatically include the packaging port here so it is always first so it
344 # builds the port and adds the package so we can add other packages.
345 #XXX Doesn't work for cross build, so punting until I can integreate qemu-static
346 #XXX or poudriere, both of which require priv'd execution. Or qemu-system,
347 #XXX which is super, super slow.
348 #add_port ports-mgmt/pkg
349 #add_port security/sudo
350 #add_port ftp/curl
351
352 rp=$(realpath ${NANO_OBJ}/)
353 __a=`mount | grep ${rp} | awk '{print length($3), $3;}' | sort -rn | awk '{$1=""; print;}'`
354 if [ -n "$__a" ]; then
355     echo "unmounting $__a"
356     umount $__a
357 fi
358
359 if [ "$DEBUG" = 1 ]; then
360         DEBUG_BUILD="
361 DEBUG_FLAGS=            -g
362 "
363 else
364         DEBUG_INSTALL="
365 INSTALL_NODEBUG=        t
366 "
367 fi
368
369 CONF_INSTALL="$CONF_BUILD
370 ${DEBUG_BUILD}
371 "
372 CONF_INSTALL="$CONF_INSTALL
373 ${DEBUG_INSTALL}
374 "
375
376 if [ "${NANO_PACKAGE_ONLY}" -eq 1 ]; then
377         CONF_INSTALL="${CONF_INSTALL}
378 ${PKG_ONLY_MAKE_CONF}
379 "
380         echo "Automatically building a thin image with packages"
381 else
382         echo "Automatically building a * * F A T * * image so we can build ports"
383 fi
384
385 VARS="MASTER_SITE_BACKUP MASTER_SITE_OVERRIDE PACKAGEROOT PACKAGESITE"
386
387 for var in $VARS; do
388         val=$(eval echo "\$$var")
389         if [ -n "$val" ]; then
390                 CONF_INSTALL="${CONF_INSTALL}
391 $var=$val"
392         fi
393 done
394
395 typical_embedded ( ) (
396         # Need to create rc.conf before we copy over /etc to /conf/base/etc
397         # so now's a good time.
398
399         local rc=${NANO_WORLDDIR}/etc/rc.conf
400
401         echo "hostname=nanobsd-${NANO_NAME}" > $rc
402         echo "growfs_enable=YES" >> $rc
403         echo "growfs_type=nanobsd-pingpong" >> $rc
404         echo "ntpdate_enable=YES" >> $rc
405         echo "ifconfig_DEFAULT=DHCP" >> $rc
406         echo "ntpdate_hosts='0.freebsd.pool.ntp.org 1.freebsd.pool.ntp.org'" >> $rc
407         # Make sure that firstboot scripts run so growfs works.
408         # Note: still some issues remvoing this XXX
409         touch ${NANO_WORLDDIR}/firstboot
410 )
411 customize_cmd typical_embedded
412
413 fix_pkg ( ) (
414         chdir ${NANO_WORLDDIR}
415         mkdir -p pkg
416         mkdir -p pkg/db
417         mkdir -p pkg/cache
418         mkdir -p pkg/tmp                # Needed for pkg bootstrap
419         mkdir -p usr/local/etc          # Will get moved to local/etc
420         (
421         echo 'PKG_DBDIR = "/pkg/db"'
422         echo 'PKG_CACHEDIR = "/pkg/cache"'
423         echo 'DEFAULT_ALWAYS_YES = "yes"'
424         echo 'ASSUME_ALWAYS_YES = "yes"'
425         ) >> usr/local/etc/pkg.conf
426         [ -z ${NANO_NOPRIV_BUILD} ] || (
427         echo "./pkg type=dir uname=root gname=wheel mode=0755"
428         echo "./pkg/cache type=dir uname=root gname=wheel mode=0755"
429         echo "./pkg/db type=dir uname=root gname=wheel mode=0755"
430         echo "./pkg/tmp type=dir uname=root gname=wheel mode=0755"
431         ) >> ${NANO_METALOG}
432 )
433 customize_cmd fix_pkg
434
435 save_build ( ) (
436         VERSION_FILE=${NANO_WORLDDIR}/etc/version
437         if [ "${SVNREVISION}" = "${REVISION}" ]; then
438                 echo "${NANO_NAME}" > "${VERSION_FILE}"
439         else
440                 echo "${NANO_NAME} (${SVNREVISION})" > "${VERSION_FILE}"
441         fi
442 )
443 customize_cmd save_build
444
445 shrink_md_fbsize ( ) (
446         # We have a lot of little files on our memory disks. Let's decrease
447         # the block and frag size to fit more little files on them (this
448         # halves our space requirement by ~50% on /etc and /var on 8.x --
449         # and gives us more back on 9.x as the default block and frag size
450         # are 4 times larger).
451         sed -i '' -e 's,-S -i 4096,-S -i 4096 -b 4096 -f 512,' \
452                 ${NANO_WORLDDIR}/etc/rc.initdiskless
453 )
454 customize_cmd shrink_md_fbsize
455
456 customize_cmd cust_comconsole
457
458 dos_boot_part ( ) (
459         local d=/usr/local/share/u-boot/${NANO_BOOT_PKG}
460         local f=${NANO_FAT_DIR}
461
462         # For now, just copy all the files. However, for iMX6 and Allwinner,
463         # we'll need to put a special boot block at a fixed location
464         # on the disk as well.
465         rm -rf $f
466         mkdir $f
467         chdir $f
468         cp ${d}/* .
469
470         # Also copy ubldr. u-boot will load it and it will load the kernel
471         # from the ufs partition
472         cp ${NANO_WORLDDIR}/boot/ubldr .
473         cp ${NANO_WORLDDIR}/boot/ubldr.bin .
474
475         # We have to touch the saveenv file
476         touch uEnv.txt
477
478         # Now we need to copy over dtb files from the build.
479         cp ${NANO_WORLDDIR}/boot/dtb/*.dtb .
480 )
481
482 if [ -n "$NANO_BOOT_PKG" ]; then
483         local d=/usr/local/share/u-boot/${NANO_BOOT_PKG}
484         if [ ! -d ${d} ]; then
485                 echo ${NANO_BOOT_PKG} not installed. Sadly, it must be.
486                 exit 1
487         fi
488         if [ ! -x /usr/local/bin/mcopy ]; then
489                 echo mtools not installed. Sadly, we gotta have it.
490                 exit 1
491         fi
492         customize_cmd dos_boot_part
493 fi
494
495 product_custom ( ) (
496         # not quite ready to tweak these in nopriv build
497         if [ -z ${NANO_NOPRIV_BUILD} ]; then
498                 # Last second tweaks -- generally not needed
499                 chown -R root:wheel ${NANO_WORLDDIR}/root
500                 chmod 0755 ${NANO_WORLDDIR}/root/*
501                 chmod 0755 ${NANO_WORLDDIR}/*
502                 chown -R root:wheel ${NANO_WORLDDIR}/etc
503                 chown -R root:wheel ${NANO_WORLDDIR}/boot
504                 chown root:wheel ${NANO_WORLDDIR}/
505                 chown root:wheel ${NANO_WORLDDIR}/usr
506         fi
507 )
508 late_customize_cmd product_custom
509
510 #
511 # Convenience routines to bring up many settings for standard environments
512 #
513
514 #
515 # For each architecture, we have a standard set of settings to the extent
516 # it makes sense. For architectures that don't have a standard environment
517 # cfg files need to either define a lot of settings, provide their own disk
518 # imaging, or set which of the variants we support. No subshells, since we
519 # set global variables
520 #
521
522 std_aarch64 ( ) {
523 }
524
525 std_amd64 ( ) {
526         std_i386
527 }
528
529 std_arm ( ) {
530 }
531
532 std_armeb ( ) {
533         NANO_ENDIAN=big
534 }
535
536 std_armv6 ( ) {
537 }
538
539 std_i386 ( ) {
540         # Default values, if not overridden in .cfg file
541         : ${NANO_KERNEL:=GENERIC}
542         : ${NANO_DRIVE:=ada0}
543         : ${NANO_LAYOUT:=std-x86}
544         : ${NANO_BOOT_MBR:=${NANO_WORLDDIR}/boot/boot0sio}
545         : ${NANO_BOOT_BSD:=${NANO_WORLDDIR}/boot/boot}
546 }
547
548 std_mips ( ) {
549         NANO_ENDIAN=big
550 }
551
552 std_mipsel ( ) {
553 }
554
555 std_mips64 ( ) {
556         NANO_ENDIAN=big
557 }
558
559 std_mips64el ( ) {
560 }
561
562 std_powerpc ( ) {
563         NANO_ENDIAN=big
564 }
565
566 std_powerpc64 ( ) {
567         NANO_LAYOUT=powerpc64-ibm
568         NANO_ENDIAN=big
569 }
570
571 std_sparc64 ( ) {
572         NANO_ENDIAN=big
573 }
574
575 #
576 # QEMU settings for the standard environments
577 #
578 qemu_env ( ) {
579
580         NANO_DISKIMAGE_FORMAT=qcow2
581 }
582
583 # other standard environments will go here
584
585 eval std_${NANO_ARCH}
586
587 # Slice 1: FAT for ROM loading bootstrap
588 # Slice 2: Config partition
589 # Slice 3: FreeBSD partition (sized exactly)
590 # Slice 4: FreeBSD partition (empty)
591 # on first boot, we resize slice 3 & 4 to be 1/2 of what's
592 # left over on the SD card after slice 1 and 2 are taken
593 # off the top. We also resize the 'a' partion on first boot
594 # to the size of the partition for the ping/pong upgrade.
595 # This feature needs support in the rc.d bootup script.
596 #
597 # Ideally, we'd not put BSD labels on the MBR disks.
598 # However, we can't boot off raw MBR disks. First,
599 # boot2 defaults to 'a' partition, and freaks out
600 # unless you tell it to use 'c'. But even if we
601 # hack that, then /boot/loader wants to load off
602 # of 'c' partition. If you fix that, then we'll
603 # try to mount root, but sanity checks prevent
604 # slices from working.
605 #
606
607 : ${NANO_ENDIAN:=little}        # make -V something to figure it out?
608 : ${NANO_LAYOUT:=std-embedded}
609 : ${NANO_MAKEFS_UFS:=makefs -t ffs -B ${NANO_ENDIAN}}
610 : ${NANO_DISK_SCHEME:=mbr}      # No others really supported ATM (well, gpt)
611 case ${NANO_LAYOUT} in
612 std-embedded)
613         NANO_SLICE_FAT=s1
614         NANO_SLICE_CFG=s2
615         NANO_SLICE_ROOT=s3
616         NANO_SLICE_ALTROOT=s4
617         NANO_ROOT=${NANO_SLICE_ROOT}a
618         NANO_ALTROOT=${NANO_SLICE_ALTROOT}a
619         ;;
620 std-x86)
621         NANO_SLICE_CFG=s1
622         NANO_SLICE_ROOT=s2
623         NANO_SLICE_ALTROOT=s3
624         NANO_ROOT=${NANO_SLICE_ROOT}a
625         NANO_ALTROOT=${NANO_SLICE_ALTROOT}a
626         ;;
627 powerpc64-ibm)
628         NANO_SLICE_PPCBOOT=s1
629         NANO_SLICE_CFG=s2
630         NANO_SLICE_ROOT=s3
631         NANO_SLICE_ALTROOT=s4
632         NANO_ROOT=${NANO_SLICE_ROOT}a
633         NANO_ALTROOT=${NANO_SLICE_ALTROOT}a
634         ;;
635 powerpc64-apple)
636         echo Not yet
637         exit 1
638         ;;
639 std-uefi)
640         NANO_SLICE_UEFI=s1
641         NANO_SLICE_CFG=s2
642         NANO_SLICE_ROOT=s3
643         NANO_SLICE_ALTROOT=s4
644         NANO_ROOT=${NANO_SLICE_ROOT}
645         NANO_ALTROOT=${NANO_SLICE_ALTROOT}
646         ;;
647 std-uefi-bios)
648         NANO_DISK_SCHEME=gpt
649         NANO_SLICE_UEFI=p1
650         NANO_SLICE_BOOT=p2
651         NANO_SLICE_CFG=p3
652         NANO_SLICE_ROOT=p4
653         NANO_SLICE_ALTROOT=p5
654         NANO_ROOT=${NANO_SLICE_ROOT}
655         NANO_ALTROOT=${NANO_SLICE_ALTROOT}
656         ;;
657 *)
658         echo Unknown Layout ${NANO_LAYOUT}
659         exit 1
660         ;;
661 esac
662
663
664 NANO_SLICE_DATA=                # Not included
665
666 # Each major disk scheme has its own routine. Generally
667 # this is for mbr, gpt, etc. These are generally are widely
668 # shared, but some specialized formats won't be shared.
669 create_diskimage ( ) (
670         eval create_diskimage_${NANO_DISK_SCHEME}
671 )
672
673 # Set the path to the same path we use for buldworld to use latest mkimg
674 NANO_TARGET=$(cd ${NANO_SRC}; ${NANO_MAKE} TARGET_ARCH=${NANO_ARCH} -V _TARGET)
675 NANO_TMPPATH=$(cd ${NANO_SRC}; ${NANO_MAKE} TARGET=${NANO_TARGET} TARGET_ARCH=${NANO_ARCH} -f Makefile.inc1 buildenv -V TMPPATH)
676 export PATH="${NANO_TMPPATH}"