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