Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jan 2012 22:29:44 -0800
From:      Garrett Cooper <yanegomi@gmail.com>
To:        Adrian Chadd <adrian@freebsd.org>
Cc:        Jacques Fourie <jacques.fourie@gmail.com>, rizzo@iet.unipi.it, current@freebsd.org
Subject:   Re: cross-arch building picobsd/nanobsd images ?
Message-ID:  <CAGH67wSQSRjCYfFCUtaGJFbMJYW8bfqc%2BArzQjvPN6Z1nBOeXQ@mail.gmail.com>
In-Reply-To: <CAJ-Vmom8vfL34-GeAoa-Nt7reGR_LignPDm0LDJkNQkHDLQaAg@mail.gmail.com>
References:  <20111219224545.GA22631@onelab2.iet.unipi.it> <CA%2Bq%2BTcq_hfvzDJUZ3NW44gzQqxy-iYNqM2a==ziRKa8kHp669w@mail.gmail.com> <4EF5915E.1030202@gmail.com> <CALX0vxCNOxNjhvuGfTj05RXOiq4RURxCxa-nWimTjSZgHYJhRg@mail.gmail.com> <CAJ-Vmom8vfL34-GeAoa-Nt7reGR_LignPDm0LDJkNQkHDLQaAg@mail.gmail.com>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Wed, Jan 4, 2012 at 9:50 PM, Adrian Chadd <adrian@freebsd.org> wrote:
> On 4 January 2012 20:53, Jacques Fourie <jacques.fourie@gmail.com> wrote:
>> I've posted a diff to -arm about 2 years ago that I used to
>> cross-build arm picobsd images for a gumstix platform on a i386 host.
>> I don't know if the diff will apply cleanly anymore but here it is in
>> anyway.
>
> Hi,
>
> I've figured out all the right flags to pass to a cross-build
> environment. Namely:

...

> .. ignore LOCAL_TOOL_DIRS, I haven't committed that yet to -HEAD.
>
> If someone would like to update picobsd to make this work, I'll
> happily test out patches and commit it to -HEAD.
>
> Building -8 and previous needed some extra hacks (eg
> TARGET_BIG_ENDIAN) which have been removed from -HEAD/-9.

    Here's the FreeNAS project/iXsystems' contribution to nanobsd
which was contributed back to Warner, but hasn't been reviewed /
committed to CURRENT since I missed my pre-Christmas window of
opportunity :(. There are some potentially helpful gems that could be
added to picobsd (and vice versa I'm sure) -- look for NANO_ARCH for
instance; it doesn't resolve the TARGET_BIG_ENDIAN issue noted
previously, but that's probably part of the reason why NANO_PMAKE is a
separate variable...
Thanks!
-Garrett

[-- Attachment #2 --]
Index: tools/tools/nanobsd/nanobsd.sh
===================================================================
--- tools/tools/nanobsd/nanobsd.sh	(revision 229271)
+++ tools/tools/nanobsd/nanobsd.sh	(working copy)
@@ -58,7 +58,7 @@
 #NANO_DISKIMGDIR=""
 
 # Parallel Make
-NANO_PMAKE="make -j 3"
+NANO_PMAKE="make"
 
 # The default name for any image we create.
 NANO_IMGNAME="_.disk.full"
@@ -76,7 +76,7 @@
 NANO_KERNEL=GENERIC
 
 # Kernel modules to build; default is none
-NANO_MODULES=
+NANO_MODULES=""
 
 # Customize commands.
 NANO_CUSTOMIZE=""
@@ -146,12 +146,14 @@
 NANO_LABEL=""
 
 #######################################################################
-# Architecture to build.  Corresponds to TARGET_ARCH in a buildworld.
-# Unfortunately, there's no way to set TARGET at this time, and it
-# conflates the two, so architectures where TARGET != TARGET_ARCH do
-# not work.  This defaults to the arch of the current machine.
+# Architecture to build.  Corresponds to TARGET:TARGET_ARCH in
+# buildworld.
+# This defaults to the architecture and processor of the current machine.
+#
+# This accepts just the architecture though (for select architectures like
+# amd64, i386, etc where there isn't a different processor).
 
-NANO_ARCH=`uname -p`
+: ${NANO_ARCH=$(uname -m):$(uname -p)}
 
 # Directory to populate /cfg from
 NANO_CFGDIR=""
@@ -159,6 +161,16 @@
 # Directory to populate /data from
 NANO_DATADIR=""
 
+# src.conf to use when building the image. Defaults to /dev/null for the sake
+# of determinism.
+SRCCONF=${SRCCONF:=/dev/null}
+
+# Where to put the obj files. Defaults to /usr/obj.
+MAKEOBJDIRPREFIX=/usr/obj
+
+# Files to exclude via find(1)
+NANO_IGNORE_FILES_EXPR='/(CVS|\.git|\.svn)'
+
 #######################################################################
 #
 # The functions which do the real work.
@@ -182,7 +194,6 @@
 
 	echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_BUILD}
 	echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF_BUILD}
-	echo "SRCCONF=/dev/null" >> ${NANO_MAKE_CONF_BUILD}
 )
 
 build_world ( ) (
@@ -190,7 +201,11 @@
 	pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw"
 
 	cd ${NANO_SRC}
-	env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \
+	env \
+		TARGET=${NANO_ARCH%:*} \
+		TARGET_ARCH=${NANO_ARCH##*:} \
+		${NANO_PMAKE} \
+		SRCCONF=${SRCCONF} \
 		__MAKE_CONF=${NANO_MAKE_CONF_BUILD} buildworld \
 		> ${MAKEOBJDIRPREFIX}/_.bw 2>&1
 )
@@ -214,10 +229,16 @@
 	unset TARGET_BIG_ENDIAN
 	# Note: We intentionally build all modules, not only the ones in
 	# NANO_MODULES so the built world can be reused by multiple images.
-	env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \
+	env \
+		TARGET=${NANO_ARCH%:*} \
+		TARGET_ARCH=${NANO_ARCH##*:} \
+		${NANO_PMAKE} \
+		buildkernel \
+		${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \
+		KERNCONF=${kernconf} \
+		MODULES_OVERRIDE="${NANO_MODULES}" \
+		SRCCONF=${SRCCONF} \
 		__MAKE_CONF=${NANO_MAKE_CONF_BUILD} \
-		${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \
-		KERNCONF=${kernconf}
 	) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1
 )
 
@@ -245,7 +266,6 @@
 
 	echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_INSTALL}
 	echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF_INSTALL}
-	echo "SRCCONF=/dev/null" >> ${NANO_MAKE_CONF_INSTALL}
 )
 
 install_world ( ) (
@@ -253,9 +273,14 @@
 	pprint 3 "log: ${NANO_OBJ}/_.iw"
 
 	cd ${NANO_SRC}
-	env TARGET_ARCH=${NANO_ARCH} \
-	${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} installworld \
+	env \
+		TARGET=${NANO_ARCH%:*} \
+		TARGET_ARCH=${NANO_ARCH##*:} \
+		${NANO_PMAKE} \
+		installworld \
 		DESTDIR=${NANO_WORLDDIR} \
+		SRCCONF=${SRCCONF} \
+		__MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \
 		> ${NANO_OBJ}/_.iw 2>&1
 	chflags -R noschg ${NANO_WORLDDIR}
 )
@@ -266,9 +291,14 @@
 	pprint 3 "log: ${NANO_OBJ}/_.etc"
 
 	cd ${NANO_SRC}
-	env TARGET_ARCH=${NANO_ARCH} \
-	${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} distribution \
+	env \
+		TARGET=${NANO_ARCH%:*} \
+		TARGET_ARCH=${NANO_ARCH##*:} \
+		${NANO_PMAKE} \
+		distribution \
 		DESTDIR=${NANO_WORLDDIR} \
+		SRCCONF=${SRCCONF} \
+		__MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \
 		> ${NANO_OBJ}/_.etc 2>&1
 	# make.conf doesn't get created by default, but some ports need it
 	# so they can spam it.
@@ -288,36 +318,53 @@
 	fi
 
 	cd ${NANO_SRC}
-	env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} installkernel \
+	env \
+		TARGET=${NANO_ARCH%:*} \
+		TARGET_ARCH=${NANO_ARCH##*:} \
+		${NANO_PMAKE} \
+		installkernel \
 		DESTDIR=${NANO_WORLDDIR} \
-		__MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \
 		${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \
 		KERNCONF=${kernconf} \
 		MODULES_OVERRIDE="${NANO_MODULES}"
+		SRCCONF=${SRCCONF} \
+		__MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \
 	) > ${NANO_OBJ}/_.ik 2>&1
 )
 
 run_customize() (
 
 	pprint 2 "run customize scripts"
-	for c in $NANO_CUSTOMIZE
+	set -- $NANO_CUSTOMIZE
+	i=1
+	num_steps=$#
+	while [ $i -le $num_steps ]
 	do
-		pprint 2 "customize \"$c\""
+		c=$1
+		pprint 2 "[$i/$num_steps] customize \"$c\""
 		pprint 3 "log: ${NANO_OBJ}/_.cust.$c"
 		pprint 4 "`type $c`"
 		( set -x ; $c ) > ${NANO_OBJ}/_.cust.$c 2>&1
+		shift
+		: $(( i += 1 ))
 	done
 )
 
 run_late_customize() (
 
 	pprint 2 "run late customize scripts"
-	for c in $NANO_LATE_CUSTOMIZE
+	set -- $NANO_LATE_CUSTOMIZE
+	i=1
+	num_steps=$#
+	while [ $i -le $num_steps ]
 	do
-		pprint 2 "late customize \"$c\""
+		c=$1
+		pprint 2 "[$i/$num_steps] late customize \"$c\""
 		pprint 3 "log: ${NANO_OBJ}/_.late_cust.$c"
 		pprint 4 "`type $c`"
 		( set -x ; $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1
+		shift
+		: $(( i += 1 ))
 	done
 )
 
@@ -335,7 +382,7 @@
 		(
 		mkdir -p etc/local
 		cd usr/local/etc
-		find . -print | cpio -dumpl ../../../etc/local
+		find . | cpio -R root:wheel -dumpl ../../../etc/local
 		cd ..
 		rm -rf etc
 		ln -s ../../etc/local etc
@@ -349,7 +396,7 @@
 		# the files in /$d will be hidden by the mount.
 		# XXX: configure /$d ramdisk size
 		mkdir -p conf/base/$d conf/default/$d
-		find $d -print | cpio -dumpl conf/base/
+		find $d | cpio -R root:wheel -dumpl conf/base/
 	done
 
 	echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size
@@ -359,8 +406,8 @@
 	echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount
 
 	# Put /tmp on the /var ramdisk (could be symlink already)
-	rmdir tmp || true
-	rm tmp || true
+	rm -f tmp || :
+	rm -Rf tmp
 	ln -s var/tmp tmp
 
 	) > ${NANO_OBJ}/_.dl 2>&1
@@ -390,7 +437,7 @@
 prune_usr() (
 
 	# Remove all empty directories in /usr 
-	find ${NANO_WORLDDIR}/usr -type d -depth -print |
+	find ${NANO_WORLDDIR}/usr -type d -depth |
 		while read d
 		do
 			rmdir $d > /dev/null 2>&1 || true 
@@ -418,7 +465,7 @@
 	echo "Creating ${dev} with ${dir} (mounting on ${mnt})"
 	newfs_part $dev $mnt $lbl
 	cd ${dir}
-	find . -print | grep -Ev '/(CVS|\.svn)' | cpio -dumpv ${mnt}
+	find . \! -regex "$NANO_IGNORE_FILES_EXPR" | cpio -R root:wheel -dumpv ${mnt}
 	df -i ${mnt}
 	umount ${mnt}
 )
@@ -588,6 +635,8 @@
 	# after the build completed, for instance to copy the finished
 	# image to a more convenient place:
 	# cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk
+	# The following line is needed to keep bash from barfing on the file.
+	:
 )
 
 #######################################################################
@@ -676,7 +725,8 @@
 
 cust_install_files () (
 	cd ${NANO_TOOLS}/Files
-	find . -print | grep -Ev '/(CVS|\.svn)' | cpio -Ldumpv ${NANO_WORLDDIR}
+	find . \! -regex "${NANO_IGNORE_FILES_EXPR}" | \
+	    cpio -R root:wheel -Ldumpv ${NANO_WORLDDIR}
 )
 
 #######################################################################
@@ -694,8 +744,8 @@
 	mkdir -p ${NANO_WORLDDIR}/Pkg
 	(
 		cd ${NANO_PACKAGE_DIR}
-		find ${NANO_PACKAGE_LIST} -print |
-		    cpio -Ldumpv ${NANO_WORLDDIR}/Pkg
+		find ${NANO_PACKAGE_LIST} | \
+		    cpio -R root:wheel -Ldumpv ${NANO_WORLDDIR}/Pkg
 	)
 
 	# Count & report how many we have to install
@@ -758,105 +808,112 @@
 # Progress Print
 #	Print $2 at level $1.
 pprint() {
-    if [ "$1" -le $PPLEVEL ]; then
-	runtime=$(( `date +%s` - $NANO_STARTTIME ))
-	printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3
-    fi
+	if [ "$1" -le $PPLEVEL ]; then
+		runtime=$(( $(date +'%s') - ${NANO_STARTTIME} ))
+		printf "%s %.${1}s %s\n" "$(date -u -r $runtime +%H:%M:%S)" "#####" "$2" >&3
+	fi
 }
 
 usage () {
-	(
-	echo "Usage: $0 [-bfiknqvw] [-c config_file]"
-	echo "	-b	suppress builds (both kernel and world)"
-	echo "	-f	suppress code slice extraction"
-	echo "	-i	suppress disk image build"
-	echo "	-k	suppress buildkernel"
-	echo "	-n	add -DNO_CLEAN to buildworld, buildkernel, etc"
-	echo "	-q	make output more quiet"
-	echo "	-v	make output more verbose"
-	echo "	-w	suppress buildworld"
-	echo "	-c	specify config file"
-	) 1>&2
+	cat >&2 <<EOF
+usage: ${0##*/} [-biknqvw] [-c config_file]
+	-b		suppress builds (both kernel and world)
+	-c config_file	config file to use after defining all
+			internal variables.
+	-i		suppress disk image build
+	-j make-jobs	number of make jobs to invoke
+	-k		suppress buildkernel
+	-n		add -DNO_CLEAN to buildworld, buildkernel, etc
+	-q		make output more quiet
+	-v		make output more verbose
+	-w		suppress buildworld
+EOF
 	exit 2
 }
 
 #######################################################################
 # Parse arguments
 
+set +e
+
 do_clean=true
 do_kernel=true
 do_world=true
 do_image=true
 do_copyout_partition=true
+make_jobs=3
+nano_confs=
 
-set +e
-args=`getopt bc:fhiknqvw $*`
-if [ $? -ne 0 ] ; then
-	usage
-	exit 2
-fi
-set -e
-
-set -- $args
-for i
+while getopts 'bc:fhij:knqvw' optch
 do
-	case "$i" 
-	in
-	-b)
+	case "$optch" in
+	b)
 		do_world=false
 		do_kernel=false
-		shift
 		;;
-	-k)
-		do_kernel=false
-		shift
+	c)
+		if [ -f "$OPTARG" ]; then
+			nano_confs="$nano_confs $OPTARG"
+		fi
 		;;
-	-c)
-		. "$2"
-		shift
-		shift
-		;;
-	-f)
+	f)
 		do_copyout_partition=false
-		shift
 		;;
-	-h)
+	h)
 		usage
 		;;
-	-i)
+	i)
 		do_image=false
-		shift
 		;;
-	-n)
+	j)
+		echo $OPTARG | egrep -q '^[[:digit:]]+$' && [ $OPTARG -gt 0 ]
+		if [ $? -ne 0 ]; then
+			echo "${0##*/}: -j value must be a positive integer."
+			usage
+		fi
+		make_jobs=$OPTARG
+		;;
+	k)
+		do_kernel=false
+		;;
+	n)
 		do_clean=false
-		shift
 		;;
-	-q)
-		PPLEVEL=$(($PPLEVEL - 1))
-		shift
+	q)
+		: $(( PPLEVEL -= 1))
 		;;
-	-v)
-		PPLEVEL=$(($PPLEVEL + 1))
-		shift
+	v)
+		: $(( PPLEVEL += 1))
 		;;
-	-w)
+	w)
 		do_world=false
-		shift
 		;;
-	--)
-		shift
-		break
+	*)
+		usage
+		;;
 	esac
 done
 
+shift $(( $OPTIND - 1 ))
+
 if [ $# -gt 0 ] ; then
-	echo "$0: Extraneous arguments supplied"
+	echo "${0##*/}: extraneous arguments supplied"
 	usage
 fi
 
+NANO_PMAKE="$NANO_PMAKE -j $make_jobs"
+
+set -e
+
 #######################################################################
 # Setup and Export Internal variables
 #
+
+for nano_conf in $nano_confs; do
+	echo "Sourcing $nano_conf"
+	. "$nano_conf"
+done
+
 test -n "${NANO_OBJ}" || NANO_OBJ=/usr/obj/nanobsd.${NANO_NAME}/
 test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ}
 test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ}
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGH67wSQSRjCYfFCUtaGJFbMJYW8bfqc%2BArzQjvPN6Z1nBOeXQ>