From nobody@FreeBSD.org  Mon Jun 15 05:51:54 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 2199C106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Jun 2009 05:51:54 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 042D38FC13
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Jun 2009 05:51:54 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n5F5pr2R083217
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Jun 2009 05:51:53 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n5F5prhM083216;
	Mon, 15 Jun 2009 05:51:53 GMT
	(envelope-from nobody)
Message-Id: <200906150551.n5F5prhM083216@www.freebsd.org>
Date: Mon, 15 Jun 2009 05:51:53 GMT
From: Olivier Cochard-Labb <olivier@cochard.me>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [nanobsd] simple patch for adding amd64 support
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         135588
>Category:       misc
>Synopsis:       [nanobsd] simple patch for adding amd64 support
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-embedded
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 15 06:00:10 UTC 2009
>Closed-Date:    Mon Aug 23 11:49:37 MDT 2010
>Last-Modified:  Mon Aug 23 11:49:37 MDT 2010
>Originator:     Olivier Cochard-Labb
>Release:        amd64-current
>Organization:
>Environment:
FreeBSD d630.freenas.org 8.0-CURRENT FreeBSD 8.0-CURRENT #33: Sat Jun 13 09:36:53 CEST 2009     root@d630.freenas.org:/usr/obj/usr/src/sys/DellD630  amd64
>Description:
I would to generate a amd64 nanobsd image from my FreeBSD-amd64-current (using the NANO_ARCH=amd64 on my nano configuration file).
But nanobsd complains that function create_amd64_diskimage() is missing.
Then I've just copy the function create_i386_dikimage() to a new create_amd64_diskimage() and it's working...


>How-To-Repeat:
By generating a nanobsd amd64 image.
>Fix:
Using the patch file included in this PR (tested from a freebsd-amd64 only).

Patch attached with submission follows:

--- nanobsd.orig	2009-06-14 09:43:36.000000000 +0200
+++ nanobsd.sh	2009-06-14 10:19:25.000000000 +0200
@@ -490,6 +490,153 @@
 	) > ${MAKEOBJDIRPREFIX}/_.di 2>&1
 )
 
+# Patch added for supporting amd64 arch
+# A simple copy/past of create_i386_diskimage
+
+create_amd64_diskimage ( ) (
+	pprint 2 "build diskimage"
+	pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.di"
+
+	(
+	echo $NANO_MEDIASIZE $NANO_IMAGES \
+		$NANO_SECTS $NANO_HEADS \
+		$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
+	awk '
+	{
+		printf "# %s\n", $0
+
+		# size of cylinder in sectors
+		cs = $3 * $4
+
+		# number of full cylinders on media
+		cyl = int ($1 / cs)
+
+		# output fdisk geometry spec, truncate cyls to 1023
+		if (cyl <= 1023)
+			print "g c" cyl " h" $4 " s" $3
+		else
+			print "g c" 1023 " h" $4 " s" $3
+
+		if ($7 > 0) { 
+			# size of data partition in full cylinders
+			dsl = int (($7 + cs - 1) / cs)
+		} else {
+			dsl = 0;
+		}
+
+		# size of config partition in full cylinders
+		csl = int (($6 + cs - 1) / cs)
+
+		if ($5 == 0) {
+			# size of image partition(s) in full cylinders
+			isl = int ((cyl - dsl - csl) / $2)
+		} else {
+			isl = int (($5 + cs - 1) / cs)
+		}
+
+		# First image partition start at second track
+		print "p 1 165 " $3, isl * cs - $3
+		c = isl * cs;
+
+		# Second image partition (if any) also starts offset one 
+		# track to keep them identical.
+		if ($2 > 1) {
+			print "p 2 165 " $3 + c, isl * cs - $3
+			c += isl * cs;
+		}
+
+		# Config partition starts at cylinder boundary.
+		print "p 3 165 " c, csl * cs
+		c += csl * cs
+
+		# Data partition (if any) starts at cylinder boundary.
+		if ($7 > 0) {
+			print "p 4 165 " c, dsl * cs
+		} else if ($7 < 0 && $1 > c) {
+			print "p 4 165 " c, $1 - c
+		} else if ($1 < c) {
+			print "Disk space overcommitted by", \
+			    c - $1, "sectors" > "/dev/stderr"
+			exit 2
+		}
+
+		# Force slice 1 to be marked active. This is necessary
+		# for booting the image from a USB device to work.
+		print "a 1"
+	}
+	' > ${MAKEOBJDIRPREFIX}/_.fdisk
+
+	IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
+	MNT=${MAKEOBJDIRPREFIX}/_.mnt
+	mkdir -p ${MNT}
+
+	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
+		MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \
+			-y ${NANO_HEADS}`
+	else
+		echo "Creating md backing file..."
+		dd if=/dev/zero of=${IMG} bs=${NANO_SECTS}b \
+			count=`expr ${NANO_MEDIASIZE} / ${NANO_SECTS}`
+		MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
+			-y ${NANO_HEADS}`
+	fi
+
+	trap "df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
+
+	fdisk -i -f ${MAKEOBJDIRPREFIX}/_.fdisk ${MD}
+	fdisk ${MD}
+	# XXX: params
+	# XXX: pick up cached boot* files, they may not be in image anymore.
+	boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
+	bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1
+	bsdlabel ${MD}s1
+
+	# Create first image
+	newfs ${NANO_NEWFS} /dev/${MD}s1a
+	mount /dev/${MD}s1a ${MNT}
+	df -i ${MNT}
+	echo "Copying worlddir..."
+	( cd ${NANO_WORLDDIR} && find . -print | cpio -dump ${MNT} )
+	df -i ${MNT}
+	echo "Generating mtree..."
+	( cd ${MNT} && mtree -c ) > ${MAKEOBJDIRPREFIX}/_.mtree
+	( cd ${MNT} && du -k ) > ${MAKEOBJDIRPREFIX}/_.du
+	umount ${MNT}
+
+	if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
+		# Duplicate to second image (if present)
+		echo "Duplicating to second image..."
+		dd if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
+		mount /dev/${MD}s2a ${MNT}
+		for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab
+		do
+			sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/g" $f
+		done
+		umount ${MNT}
+
+	fi
+	
+	# Create Config slice
+	newfs ${NANO_NEWFS} /dev/${MD}s3
+	# XXX: fill from where ?
+
+	# Create Data slice, if any.
+	if [ $NANO_DATASIZE -gt 0 ] ; then
+		newfs ${NANO_NEWFS} /dev/${MD}s4
+		# XXX: fill from where ?
+	fi
+
+	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
+		echo "Writing out _.disk.full..."
+		dd if=/dev/${MD} of=${IMG} bs=64k
+	fi
+
+	echo "Writing out _.disk.image..."
+	dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
+	mdconfig -d -u $MD
+	) > ${MAKEOBJDIRPREFIX}/_.di 2>&1
+)
+
 last_orders () (
 	# Redefine this function with any last orders you may have
 	# after the build completed, for instance to copy the finished


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-embedded 
Responsible-Changed-By: vwe 
Responsible-Changed-When: Tue Jun 16 21:00:32 UTC 2009 
Responsible-Changed-Why:  
I hate code duplication. If it's really the same code, there's no need to 
copy'n paste. It's much simpler to maintain something like the following 
patch. 
Over to maintainer(s). 

sample replacement patch may look like: 

--- nanobsd.sh.orig	2009-06-16 22:56:29.000000000 +0200 
+++ nanobsd.sh	2009-06-16 23:00:09.000000000 +0200 
@@ -490,6 +490,10 @@ 
) > ${MAKEOBJDIRPREFIX}/_.di 2>&1 
) 

+create_amd64_diskimage ( ) ( 
+	create_i386_diskimage $@ 
+) 
+ 
last_orders () ( 
# Redefine this function with any last orders you may have 
# after the build completed, for instance to copy the finished 


http://www.freebsd.org/cgi/query-pr.cgi?pr=135588 
State-Changed-From-To: open->patched 
State-Changed-By: imp 
State-Changed-When: Thu Apr 1 04:17:42 MDT 2010 
State-Changed-Why:  
Committed to -head.  will mfc in a bit. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=135588 
State-Changed-From-To: patched->closed 
State-Changed-By: imp 
State-Changed-When: Mon Aug 23 11:49:26 MDT 2010 
State-Changed-Why:  
Merged. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=135588 
>Unformatted:
