xref: /freebsd/tools/tools/nanobsd/embedded/common (revision 4d3fc8b0)
1# $FreeBSD$
2
3#-
4# Copyright (c) 2015 M. Warner Losh <imp@FreeBSD.org>
5# Copyright (c) 2010-2011 iXsystems, Inc.
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
72if [ -z $NANO_NAME ]; then
73	echo "NANO_NAME not defined. Use foo.cfg instead."
74fi
75
76NANO_SLICE_FAT_SIZE=32m
77NANO_SLICE_CFG_SIZE=32m
78
79NANO_BOOT2CFG="-h -S115200"
80
81NANO_RAM_ETCSIZE=8192
82NANO_RAM_TMPVARSIZE=8192
83NANO_IMAGES=2
84
85NANO_PMAKE="make -j $(sysctl -n hw.ncpu)"
86
87NANO_CFG_BASE=$(pwd)
88NANO_CFG_BASE=$(realpath ${NANO_CFG_BASE}/..)
89NANO_SRC=$(realpath ${NANO_CFG_BASE}/../../..)
90#### XXX share obj
91if [ -z ${NANO_CPUTYPE} ]; then
92	NANO_OBJ=${NANO_SRC}/../embedded/obj
93else
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}
97fi
98NANO_LOG=${NANO_OBJ}/../${NANO_NAME}
99NANO_DISKIMGDIR=${NANO_OBJ}/../images
100NANO_WORLDDIR=${NANO_LOG}/_.w
101NANO_INIT_IMG2=0
102NANO_NOPRIV_BUILD=t
103unset MAKEOBJDIRPREFIX
104
105mkdir -p ${NANO_OBJ}
106NANO_OBJ=$(realpath ${NANO_OBJ})
107mkdir -p ${NANO_LOG}
108NANO_LOG=$(realpath ${NANO_LOG})
109mkdir -p ${NANO_WORLDDIR}
110NANO_WORLDDIR=$(realpath ${NANO_WORLDDIR})
111mkdir -p ${NANO_DISKIMGDIR}
112NANO_DISKIMGDIR=$(realpath ${NANO_DISKIMGDIR})
113
114NANO_FAT_DIR=${NANO_LOG}/_.fat
115
116customize_cmd cust_allow_ssh_root
117
118add_etc_make_conf ( ) (
119	touch ${NANO_WORLDDIR}/etc/make.conf
120)
121customize_cmd add_etc_make_conf
122
123cust_install_machine_files ( ) (
124	echo "cd ${NANO_CFG_BASE}/Files"
125	cd ${NANO_CFG_BASE}/Files
126	find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -dumpv ${NANO_WORLDDIR}
127)
128customize_cmd cust_install_files
129customize_cmd cust_install_machine_files
130
131CONF_BUILD="
132LOCAL_XTOOL_DIRS=usr.bin/mkimg
133WITHOUT_ACPI=true
134WITHOUT_AUDIT=true
135WITHOUT_BLUETOOTH=true
136WITHOUT_CALENDAR=true
137WITHOUT_DICT=true
138WITHOUT_EXAMPLES=true
139WITHOUT_GAMES=true
140WITHOUT_HTML=true
141WITHOUT_IPFILTER=true
142WITHOUT_LLVM_COV=true
143WITHOUT_LOCALES=true
144WITHOUT_LPR=true
145WITHOUT_MAN=true
146WITHOUT_NETCAT=true
147WITHOUT_NIS=true
148WITHOUT_NLS=true
149WITHOUT_NS_CACHING=true
150WITHOUT_PROFILE=true
151WITHOUT_SENDMAIL=true
152WITHOUT_SHAREDOCS=true
153WITHOUT_SYSCONS=true
154WITHOUT_LIB32=true
155WITHOUT_TESTS=true
156WITHOUT_DEBUG_FILES=t
157WITHOUT_KERNEL_SYMBOLS=t
158"
159CONF_INSTALL="$CONF_BUILD
160INSTALL_NODEBUG=t
161NOPORTDOCS=t
162NO_INSTALL_MANPAGES=t
163"
164# The following would help...
165# WITHOUT_TOOLCHAIN=true		can't build ports
166# WITHOUT_INSTALLLIB=true		libgcc.a
167#
168# from the build
169PKG_ONLY_MAKE_CONF="
170WITHOUT_TOOLCHAIN=true
171WITHOUT_INSTALLLIB=true
172"
173
174NANO_PACKAGE_ONLY=1
175
176# Creates images for all the formats that use MBR / GPT
177# split later if the #ifdef soup gets too bad.
178create_diskimage_gpt ( ) (
179	pprint 2 "build diskimage gpt ${NANO_NAME}"
180
181	create_diskimage_mbr $*
182)
183
184create_diskimage_mbr ( ) (
185
186	local fmt
187
188	[ -z ${NANO_DISKIMAGE_FORMAT} ] || fmt=".${NANO_DISKIMAGE_FORMAT}"
189
190	pprint 2 "build diskimage ${NANO_NAME}"
191	pprint 3 "log: ${NANO_LOG}/_.di"
192	pprint 3 "image in: ${NANO_DISKIMGDIR}/_.disk.image.${NANO_NAME}${fmt}"
193
194	(
195	local extra i sz fmt fmtarg bootmbr bootbsd skiparg
196	set -o xtrace
197	# Tell mtools not to be too picky
198	export MTOOLS_SKIP_CHECK=1
199
200	[ -z ${NANO_DISKIMAGE_FORMAT} ] || fmtarg="-f ${NANO_DISKIMAGE_FORMAT}"
201	[ -z ${NANO_DISKIMAGE_FORMAT} ] || fmt=".${NANO_DISKIMAGE_FORMAT}"
202	bootmbr=${NANO_BOOT_MBR:+-b ${NANO_BOOT_MBR}}
203	bootbsd=${NANO_BOOT_BSD:+-b ${NANO_BOOT_BSD}}
204	skiparg=${NANO_MBR_FIRST_SKIP:+-S ${NANO_MBR_FIRST_SKIP}}
205
206	for i in s1 s2 s3 s4 p1 p2 p3 p4 p5 empty; do
207		rm -fr ${NANO_LOG}/_.${i}*
208	done
209
210	# Populate the FAT partition, if needed
211	if [ -n "${NANO_SLICE_FAT}" ]; then
212		echo Creating MSDOS partition for kernel
213		newfs_msdos -C ${NANO_SLICE_FAT_SIZE} -F 16 -L ${NANO_NAME} \
214			${NANO_LOG}/_.${NANO_SLICE_FAT}
215		if [ -d ${NANO_FAT_DIR} ]; then
216			# Need to copy files from ${NANO_FATDIR} with mtools, or use
217			# makefs -t msdos once that's supported
218			mcopy -s -i ${NANO_LOG}/_.${NANO_SLICE_FAT} ${NANO_FAT_DIR}/* ::
219		fi
220	fi
221
222	# Populate the Powerpc boot image, if needed
223	if [ "${NANO_LAYOUT}" = powerpc64-ibm ]; then
224		dd if=${NANO_WORLDDIR}/boot/boot1.elf of=${NANO_LOG}/_.s1 bs=800k count=1 conv=sync
225	fi
226
227	# Populate the / partition, and place it into a slice with a
228	# bsd label
229	[ -z ${NANO_NOPRIV_BUILD} ] || extra="-F ${NANO_METALOG}"
230	sz=${NANO_SLICE_ROOT_SIZE:+-s ${NANO_SLICE_ROOT_SIZE}}
231	eval "${NANO_MAKEFS_UFS}" ${extra} $sz "${NANO_LOG}/_.${NANO_ROOT}" \
232		"${NANO_WORLDDIR}"
233	case ${NANO_DISK_SCHEME} in
234	mbr)
235		mkimg -s bsd ${bootbsd} -p freebsd-ufs:=${NANO_LOG}/_.${NANO_ROOT} \
236			-o ${NANO_LOG}/_.${NANO_SLICE_ROOT}
237		eval $NANO_SLICE_CFG=freebsd
238		eval $NANO_SLICE_ROOT=freebsd
239		;;
240	gpt)
241		eval $NANO_SLICE_CFG=freebsd-ufs
242		eval $NANO_SLICE_ROOT=freebsd-ufs
243		;;
244	esac
245
246	# Populate the /cfg partition, empty if none given
247	if [ -z "${NANO_CFGDIR}" ]; then
248		echo "Faking cfg dir, it's empty"
249		NANO_CFGDIR=${NANO_LOG}/_.empty
250		mkdir -p ${NANO_CFGDIR}
251	fi
252	# XXX -F cfg-mtree
253	eval "${NANO_MAKEFS_UFS}" -s ${NANO_SLICE_CFG_SIZE} \
254		"${NANO_LOG}/_.${NANO_SLICE_CFG}" "${NANO_CFGDIR}"
255
256	# data slice not supported since we need the part for FAT for
257	# booting
258
259	# Now shuffle all the slices together into the proper layout
260	if [ -n "$NANO_SLICE_FAT" ]; then
261		eval $NANO_SLICE_FAT=fat16b
262	fi
263
264	out=${NANO_DISKIMGDIR}/_.disk.image.${NANO_NAME}${fmt}
265	# below depends on https://reviews.freebsd.org/D4403 not yet in the tree
266	# but there's problems: it marks all partitions as active, so you have to
267	# boot off partition 3 or 2 by hand if you're playing around with this WIP
268	case ${NANO_LAYOUT} in
269	std-embedded)
270		mkimg -a 3 ${skiparg} ${fmtarg} ${bootmbr} -s mbr -p ${s1}:=${NANO_LOG}/_.s1 \
271			-p ${s2}:=${NANO_LOG}/_.s2 \
272			-p ${s3}:=${NANO_LOG}/_.s3 \
273			-o ${out}
274		;;
275	std-x86)
276		# s3 is cfg, s1 is /, s2 is other / (s2 is created in first boot script)
277		mkimg -a 1 ${fmtarg} ${bootmbr} -s mbr -p ${s1}:=${NANO_LOG}/_.s1 \
278			-p- \
279			-p ${s3}:=${NANO_LOG}/_.s3 \
280			-o ${out}
281
282
283		;;
284	std-uefi)
285		# s1 is boot, s2 is cfg, s3 is /, not sure how to make that
286		# boot (marked as active) with mkimg yet
287		mkimg -a 2 ${fmtarg} ${bootmbr} -s mbr \
288			-p efi:=${NANO_WORLDDIR}/boot/efiboot.img \
289			-p ${s2}:=${NANO_LOG}/_.s2 \
290			-p ${s3}:=${NANO_LOG}/_.s3 \
291			-o ${out}
292		;;
293	std-uefi-bios)
294		# p1 is boot for uefi, p2 is boot for gpt, p3 is cfg, p4 is /
295		# and p5 is alt-root (after resize)
296		mkimg -a 2 ${fmtarg} ${bootmbr} -s gpt \
297			-p efi:=${NANO_WORLDDIR}/boot/efiboot.img \
298			-p freebsd-boot:=${NANO_WORLDDIR}/boot/gptboot \
299			-p ${p3}:=${NANO_LOG}/_.p3 \
300			-p ${p4}:=${NANO_LOG}/_.p4 \
301			-o ${out}
302		;;
303	powerpc64-ibm)
304		# A lie to make the boot loader work, it boots the first BSD partition
305		# it finds, regardless of the active flag.
306		s2=fat16b
307		# boot image is on a special partition, ala std-embedded, but that
308		# partition isn't FAT with special files, but a copy of the boot
309		# loader itself.
310		mkimg -a 1 ${fmtarg} -s mbr -p prepboot:=${NANO_LOG}/_.s1 \
311			-p ${s2}:=${NANO_LOG}/_.s2 \
312			-p ${s3}:=${NANO_LOG}/_.s3a \
313			-o ${out}
314		;;
315	esac
316	rm -f ${out}.xz
317	xz -9 --keep ${out}
318	) > ${NANO_LOG}/_.di 2>&1
319)
320
321die( ) {
322	echo "$*"
323	exit 1
324}
325
326# Automatically include the packaging port here so it is always first so it
327# builds the port and adds the package so we can add other packages.
328#XXX Doesn't work for cross build, so punting until I can integreate qemu-static
329#XXX or poudriere, both of which require priv'd execution. Or qemu-system,
330#XXX which is super, super slow.
331#add_port ports-mgmt/pkg
332#add_port security/sudo
333#add_port ftp/curl
334
335rp=$(realpath ${NANO_OBJ}/)
336__a=`mount | grep ${rp} | awk '{print length($3), $3;}' | sort -rn | awk '{$1=""; print;}'`
337if [ -n "$__a" ]; then
338    echo "unmounting $__a"
339    umount $__a
340fi
341
342if [ "$DEBUG" = 1 ]; then
343	DEBUG_BUILD="
344DEBUG_FLAGS=		-g
345"
346else
347	DEBUG_INSTALL="
348INSTALL_NODEBUG=	t
349"
350fi
351
352CONF_INSTALL="$CONF_BUILD
353${DEBUG_BUILD}
354"
355CONF_INSTALL="$CONF_INSTALL
356${DEBUG_INSTALL}
357"
358
359if [ "${NANO_PACKAGE_ONLY}" -eq 1 ]; then
360 	CONF_INSTALL="${CONF_INSTALL}
361${PKG_ONLY_MAKE_CONF}
362"
363	echo "Automatically building a thin image with packages"
364else
365	echo "Automatically building a * * F A T * * image so we can build ports"
366fi
367
368VARS="MASTER_SITE_BACKUP MASTER_SITE_OVERRIDE PACKAGEROOT PACKAGESITE"
369
370for var in $VARS; do
371	val=$(eval echo "\$$var")
372	if [ -n "$val" ]; then
373		CONF_INSTALL="${CONF_INSTALL}
374$var=$val"
375	fi
376done
377
378typical_embedded ( ) (
379	# Need to create rc.conf before we copy over /etc to /conf/base/etc
380	# so now's a good time.
381
382	local rc=${NANO_WORLDDIR}/etc/rc.conf
383
384	echo "hostname=nanobsd-${NANO_NAME}" > $rc
385	echo "growfs_enable=YES" >> $rc
386	echo "growfs_type=nanobsd-pingpong" >> $rc
387	echo "ntpdate_enable=YES" >> $rc
388	echo "ifconfig_DEFAULT=DHCP" >> $rc
389	echo "ntpdate_hosts='0.freebsd.pool.ntp.org 1.freebsd.pool.ntp.org'" >> $rc
390	# Make sure that firstboot scripts run so growfs works.
391	# Note: still some issues remvoing this XXX
392	touch ${NANO_WORLDDIR}/firstboot
393)
394customize_cmd typical_embedded
395
396fix_pkg ( ) (
397	chdir ${NANO_WORLDDIR}
398	mkdir -p pkg
399	mkdir -p pkg/db
400	mkdir -p pkg/cache
401	mkdir -p pkg/tmp		# Needed for pkg bootstrap
402	mkdir -p usr/local/etc		# Will get moved to local/etc
403	(
404	echo 'PKG_DBDIR = "/pkg/db"'
405	echo 'PKG_CACHEDIR = "/pkg/cache"'
406	echo 'DEFAULT_ALWAYS_YES = "yes"'
407	echo 'ASSUME_ALWAYS_YES = "yes"'
408	) >> usr/local/etc/pkg.conf
409	[ -z ${NANO_NOPRIV_BUILD} ] || (
410	echo "./pkg type=dir uname=root gname=wheel mode=0755"
411	echo "./pkg/cache type=dir uname=root gname=wheel mode=0755"
412	echo "./pkg/db type=dir uname=root gname=wheel mode=0755"
413	echo "./pkg/tmp type=dir uname=root gname=wheel mode=0755"
414	) >> ${NANO_METALOG}
415)
416customize_cmd fix_pkg
417
418save_build ( ) (
419	VERSION_FILE=${NANO_WORLDDIR}/etc/version
420	if [ "${SVNREVISION}" = "${REVISION}" ]; then
421		echo "${NANO_NAME}" > "${VERSION_FILE}"
422	else
423		echo "${NANO_NAME} (${SVNREVISION})" > "${VERSION_FILE}"
424	fi
425)
426customize_cmd save_build
427
428shrink_md_fbsize ( ) (
429	# We have a lot of little files on our memory disks. Let's decrease
430	# the block and frag size to fit more little files on them (this
431	# halves our space requirement by ~50% on /etc and /var on 8.x --
432	# and gives us more back on 9.x as the default block and frag size
433	# are 4 times larger).
434	sed -i '' -e 's,-S -i 4096,-S -i 4096 -b 4096 -f 512,' \
435		${NANO_WORLDDIR}/etc/rc.initdiskless
436)
437customize_cmd shrink_md_fbsize
438
439customize_cmd cust_comconsole
440
441dos_boot_part ( ) (
442	local d=/usr/local/share/u-boot/${NANO_BOOT_PKG}
443	local f=${NANO_FAT_DIR}
444
445	# For now, just copy all the files. However, for iMX6 and Allwinner,
446	# we'll need to put a special boot block at a fixed location
447	# on the disk as well.
448	rm -rf $f
449	mkdir $f
450	chdir $f
451	cp ${d}/* .
452
453	# We have to touch the saveenv file
454	touch uEnv.txt
455
456	# Now we need to copy over dtb files from the build.
457	cp ${NANO_WORLDDIR}/boot/dtb/*.dtb .
458)
459
460if [ -n "$NANO_BOOT_PKG" ]; then
461	d=/usr/local/share/u-boot/${NANO_BOOT_PKG}
462	if [ ! -d ${d} ]; then
463		echo ${NANO_BOOT_PKG} not installed. Sadly, it must be.
464		exit 1
465	fi
466	if [ ! -x /usr/local/bin/mcopy ]; then
467		echo mtools not installed. Sadly, we gotta have it.
468		exit 1
469	fi
470	customize_cmd dos_boot_part
471fi
472
473product_custom ( ) (
474	# not quite ready to tweak these in nopriv build
475	if [ -z ${NANO_NOPRIV_BUILD} ]; then
476		# Last second tweaks -- generally not needed
477		chown -R root:wheel ${NANO_WORLDDIR}/root
478		chmod 0755 ${NANO_WORLDDIR}/root/*
479		chmod 0755 ${NANO_WORLDDIR}/*
480		chown -R root:wheel ${NANO_WORLDDIR}/etc
481		chown -R root:wheel ${NANO_WORLDDIR}/boot
482		chown root:wheel ${NANO_WORLDDIR}/
483		chown root:wheel ${NANO_WORLDDIR}/usr
484	fi
485)
486late_customize_cmd product_custom
487
488#
489# Convenience routines to bring up many settings for standard environments
490#
491
492#
493# For each architecture, we have a standard set of settings to the extent
494# it makes sense. For architectures that don't have a standard environment
495# cfg files need to either define a lot of settings, provide their own disk
496# imaging, or set which of the variants we support. No subshells, since we
497# set global variables
498#
499
500std_aarch64 ( ) {
501}
502
503std_amd64 ( ) {
504	std_i386
505}
506
507std_arm ( ) {
508}
509
510std_armv6 ( ) {
511}
512
513std_armv7 ( ) {
514}
515
516std_i386 ( ) {
517	# Default values, if not overridden in .cfg file
518	: ${NANO_KERNEL:=GENERIC}
519	: ${NANO_DRIVE:=ada0}
520	: ${NANO_LAYOUT:=std-x86}
521	: ${NANO_BOOT_MBR:=${NANO_WORLDDIR}/boot/boot0sio}
522	: ${NANO_BOOT_BSD:=${NANO_WORLDDIR}/boot/boot}
523}
524
525std_mips ( ) {
526	NANO_ENDIAN=big
527}
528
529std_mipsel ( ) {
530}
531
532std_mips64 ( ) {
533	NANO_ENDIAN=big
534}
535
536std_mips64el ( ) {
537}
538
539std_powerpc ( ) {
540	NANO_ENDIAN=big
541}
542
543std_powerpc64 ( ) {
544	NANO_LAYOUT=powerpc64-ibm
545	NANO_ENDIAN=big
546}
547
548std_sparc64 ( ) {
549	NANO_ENDIAN=big
550}
551
552#
553# QEMU settings for the standard environments
554#
555qemu_env ( ) {
556
557	NANO_DISKIMAGE_FORMAT=qcow2
558}
559
560# other standard environments will go here
561
562eval std_${NANO_ARCH}
563
564# Slice 1: FAT for ROM loading bootstrap
565# Slice 2: Config partition
566# Slice 3: FreeBSD partition (sized exactly)
567# Slice 4: FreeBSD partition (empty)
568# on first boot, we resize slice 3 & 4 to be 1/2 of what's
569# left over on the SD card after slice 1 and 2 are taken
570# off the top. We also resize the 'a' partition on first boot
571# to the size of the partition for the ping/pong upgrade.
572# This feature needs support in the rc.d bootup script.
573#
574# Ideally, we'd not put BSD labels on the MBR disks.
575# However, we can't boot off raw MBR disks. First,
576# boot2 defaults to 'a' partition, and freaks out
577# unless you tell it to use 'c'. But even if we
578# hack that, then /boot/loader wants to load off
579# of 'c' partition. If you fix that, then we'll
580# try to mount root, but sanity checks prevent
581# slices from working.
582#
583
584: ${NANO_ENDIAN:=little}	# make -V something to figure it out?
585: ${NANO_LAYOUT:=std-embedded}
586: ${NANO_MAKEFS_UFS:=makefs -t ffs -B ${NANO_ENDIAN}}
587: ${NANO_DISK_SCHEME:=mbr}  	# No others really supported ATM (well, gpt)
588case ${NANO_LAYOUT} in
589std-embedded)
590	NANO_SLICE_FAT=s1
591	NANO_SLICE_CFG=s2
592	NANO_SLICE_ROOT=s3
593	NANO_SLICE_ALTROOT=s4
594	NANO_ROOT=${NANO_SLICE_ROOT}a
595	NANO_ALTROOT=${NANO_SLICE_ALTROOT}a
596	;;
597std-x86)
598	NANO_SLICE_CFG=s3
599	NANO_SLICE_ROOT=s1
600	NANO_SLICE_ALTROOT=s2
601	NANO_ROOT=${NANO_SLICE_ROOT}a
602	NANO_ALTROOT=${NANO_SLICE_ALTROOT}a
603	;;
604powerpc64-ibm)
605	NANO_SLICE_PPCBOOT=s1
606	NANO_SLICE_CFG=s2
607	NANO_SLICE_ROOT=s3
608	NANO_SLICE_ALTROOT=s4
609	NANO_ROOT=${NANO_SLICE_ROOT}a
610	NANO_ALTROOT=${NANO_SLICE_ALTROOT}a
611	;;
612powerpc64-apple)
613	echo Not yet
614	exit 1
615	;;
616std-uefi)
617	NANO_SLICE_UEFI=s1
618	NANO_SLICE_CFG=s2
619	NANO_SLICE_ROOT=s3
620	NANO_SLICE_ALTROOT=s4
621	NANO_ROOT=${NANO_SLICE_ROOT}
622	NANO_ALTROOT=${NANO_SLICE_ALTROOT}
623	;;
624std-uefi-bios)
625	NANO_DISK_SCHEME=gpt
626	NANO_SLICE_UEFI=p1
627	NANO_SLICE_BOOT=p2
628	NANO_SLICE_CFG=p3
629	NANO_SLICE_ROOT=p4
630	NANO_SLICE_ALTROOT=p5
631	NANO_ROOT=${NANO_SLICE_ROOT}
632	NANO_ALTROOT=${NANO_SLICE_ALTROOT}
633	;;
634*)
635	echo Unknown Layout ${NANO_LAYOUT}
636	exit 1
637	;;
638esac
639
640
641NANO_SLICE_DATA=		# Not included
642
643# These don't make any sense to this strategy, so stub them out.
644calculate_partitioning ( ) (
645)
646
647# These don't make any sense to this strategy, so stub them out.
648create_code_slice ( ) (
649)
650
651# Each major disk scheme has its own routine. Generally
652# this is for mbr, gpt, etc. These are generally are widely
653# shared, but some specialized formats won't be shared.
654create_diskimage ( ) (
655	eval create_diskimage_${NANO_DISK_SCHEME}
656)
657
658# Set the path to the same path we use for buldworld to use latest mkimg
659NANO_TARGET=$(cd ${NANO_SRC}; ${NANO_MAKE} TARGET_ARCH=${NANO_ARCH} -V _TARGET)
660NANO_TMPPATH=$(cd ${NANO_SRC}; ${NANO_MAKE} MK_AUTO_OBJ=no TARGET=${NANO_TARGET} TARGET_ARCH=${NANO_ARCH} -f Makefile.inc1 buildenv -V TMPPATH)
661export PATH="${NANO_TMPPATH}:${PATH}"
662