From nobody@FreeBSD.org  Sat Jul 18 18:13:31 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 6AC4B106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 Jul 2009 18:13:31 +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 5901D8FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 Jul 2009 18:13:31 +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 n6IIDVjR016427
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 Jul 2009 18:13:31 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n6IIDVTC016426;
	Sat, 18 Jul 2009 18:13:31 GMT
	(envelope-from nobody)
Message-Id: <200907181813.n6IIDVTC016426@www.freebsd.org>
Date: Sat, 18 Jul 2009 18:13:31 GMT
From: Aragon Gouveia <aragon@phat.za.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: nanobsd error reporting and other refinements
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         136889
>Category:       misc
>Synopsis:       [nanobsd] [patch] nanobsd error reporting and other refinements
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 18 18:20:01 UTC 2009
>Closed-Date:    Fri Mar 14 14:29:53 MDT 2014
>Last-Modified:  Fri Mar 14 14:29:53 MDT 2014
>Originator:     Aragon Gouveia
>Release:        8.0-BETA1
>Organization:
>Environment:
FreeBSD fuzz.geek.sh 8.0-BETA1 FreeBSD 8.0-BETA1 #7: Thu Jul  9 03:27:47 UTC 2009     root@fuzz.geek.sh:/usr/obj/usr/src/sys/FUZZ  amd64
>Description:
I've attached a patch which improves or fixes a few things in the nanobsd build script.

1.  There is an error in create_i386_diskimage in that the routine sets traps to unmount and unallocate the filesystems and md devices it creates, but it doesn't clear the traps before the routine exits.  This causes the nanobsd script to halt (due to set -e) and one never sees the completion message at the end.

2.  set -e is called at the start of the script which causes any errors to terminate execution immediately.  There is no message to show that an error occurred so it is quite easy to run nanobsd and think it ran to completion because it just exits silently.  Meanwhile you end up taking a stale disk image to your device.  I've added a routine to check $? and a trap that calls this routine on EXIT.

3.  prune_usr has an annoying side effect in that while deleting all empty directories in /usr, it also deletes /usr/lib/aout.  With /usr/lib/aout missing, ldconfig generates an error during bootup.  I've modified prune_usr to skip any directories named "aout".

4.  Added NANO_BOOT2CFG variable for adjusting the flags set in /boot.config.  Default is still " -h".

4.  Added NANO_IMAGE_MBRONLY and set it true by default.  When true and when NANO_MD_BACKING is set to "swap", nanobsd will not write out an entire disk image to file.  Instead it will just write the MBR and the code partition image to files.  I added this to make new nanobsd builds quicker and easier as one rarely needs to write an entire disk image after the slices and filesystems are already setup, and with 2 GB or larger flash cards being the norm, writing an entire disk image is heavy.

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- /usr/src/tools/tools/nanobsd/nanobsd.sh	2009-07-12 19:06:20.000000000 +0200
+++ nanobsd.sh	2009-07-18 01:10:45.000000000 +0200
@@ -124,10 +124,17 @@
 NANO_BOOT0CFG="-o packet -s 1 -m 3"
 NANO_BOOTLOADER="boot/boot0sio"
 
+# boot2 flags/options
+# default force serial console
+NANO_BOOT2CFG=" -h"
+
 # Backing type of md(4) device
 # Can be "file" or "swap"
 NANO_MD_BACKING="file"
 
+# for swap type md(4) backing, write out the mbr only
+NANO_IMAGE_MBRONLY=true
+
 # Progress Print level
 PPLEVEL=3
 
@@ -143,6 +150,13 @@
 #
 #######################################################################
 
+nano_cleanup() {
+	if [ $? -ne 0 ]; then
+		echo "Error encountered.  Check for errors in last log file." 1>&2
+	fi
+	exit $?
+}
+
 clean_build ( ) (
 	pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
 
@@ -344,7 +358,7 @@
 prune_usr() (
 
 	# Remove all empty directories in /usr 
-	find ${NANO_WORLDDIR}/usr -type d -depth -print |
+	find ${NANO_WORLDDIR}/usr -type d -depth -not -name aout -print |
 		while read d
 		do
 			rmdir $d > /dev/null 2>&1 || true 
@@ -485,13 +499,20 @@
 	fi
 
 	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
-		echo "Writing out ${NANO_IMGNAME}..."
-		dd if=/dev/${MD} of=${IMG} bs=64k
+		if [ ${NANO_IMAGE_MBRONLY} ]; then
+			echo "Writing out _.disk.mbr..."
+			dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1
+		else
+			echo "Writing out ${NANO_IMGNAME}..."
+			dd if=/dev/${MD} of=${IMG} bs=64k
+		fi
 	fi
 
 	echo "Writing out _.disk.image..."
 	dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
 	mdconfig -d -u $MD
+	trap - 1 2 15
+	trap "nano_cleanup" EXIT
 	) > ${NANO_OBJ}/_.di 2>&1
 )
 
@@ -571,8 +592,7 @@
 	# Disable getty on syscons devices
 	sed -i "" -e '/^ttyv[0-8]/s/	on/	off/' ${NANO_WORLDDIR}/etc/ttys
 
-	# Tell loader to use serial console early.
-	echo " -h" > ${NANO_WORLDDIR}/boot.config
+	echo ${NANO_BOOT2CFG} > ${NANO_WORLDDIR}/boot.config
 )
 
 #######################################################################
@@ -677,7 +697,7 @@
 	echo "	-i	suppress disk image build"
 	echo "	-k	suppress buildkernel"
 	echo "	-n	add -DNO_CLEAN to buildworld, buildkernel, etc"
-	echo "	-q	make output more quite"
+	echo "	-q	make output quieter"
 	echo "	-v	make output more verbose"
 	echo "	-w	suppress buildworld"
 	echo "	-c	specify config file"
@@ -754,6 +774,8 @@
 	usage
 fi
 
+trap "nano_cleanup" EXIT
+
 #######################################################################
 # Setup and Export Internal variables
 #


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-embedded 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Jul 18 23:13:15 UTC 2009 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=136889 
Responsible-Changed-From-To: freebsd-embedded->imp 
Responsible-Changed-By: imp 
Responsible-Changed-When: Fri May 13 13:54:10 MDT 2011 
Responsible-Changed-Why:  
Some of these are OBE, and need to investigate the rest... 


http://www.freebsd.org/cgi/query-pr.cgi?pr=136889 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/136889: commit references a PR
Date: Fri, 14 Mar 2014 19:46:31 +0000 (UTC)

 Author: imp
 Date: Fri Mar 14 19:46:18 2014
 New Revision: 263187
 URL: http://svnweb.freebsd.org/changeset/base/263187
 
 Log:
   Print an error message when we exit out early.
   
   PR: 136889
   Submitted by: Aragon Gouveia
 
 Modified:
   head/tools/tools/nanobsd/nanobsd.sh
 
 Modified: head/tools/tools/nanobsd/nanobsd.sh
 ==============================================================================
 --- head/tools/tools/nanobsd/nanobsd.sh	Fri Mar 14 19:45:40 2014	(r263186)
 +++ head/tools/tools/nanobsd/nanobsd.sh	Fri Mar 14 19:46:18 2014	(r263187)
 @@ -167,6 +167,13 @@ NANO_DATADIR=""
  #
  #######################################################################
  
 +nano_cleanup ( ) (
 +	if [ $? -ne 0 ]; then
 +		echo "Error encountered.  Check for errors in last log file." 1>&2
 +	fi
 +	exit $?
 +)
 +
  clean_build ( ) (
  	pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
  
 @@ -576,7 +583,8 @@ create_i386_diskimage ( ) (
  	fi
  	mdconfig -d -u $MD
  
 -	trap - 1 2 15 EXIT
 +	trap - 1 2 15
 +	trap nano_cleanup EXIT
  
  	) > ${NANO_OBJ}/_.di 2>&1
  )
 @@ -929,6 +937,8 @@ if [ $# -gt 0 ] ; then
  	usage
  fi
  
 +trap nano_cleanup EXIT
 +
  #######################################################################
  # Setup and Export Internal variables
  #
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/136889: commit references a PR
Date: Fri, 14 Mar 2014 19:46:44 +0000 (UTC)

 Author: imp
 Date: Fri Mar 14 19:46:32 2014
 New Revision: 263188
 URL: http://svnweb.freebsd.org/changeset/base/263188
 
 Log:
   When NANO_IMAGE_MBRONLY is set, and we're backing via swap, only copy
   the MBR.
   
   PR: 136889
   Submitted by: Aragon Gouveia
 
 Modified:
   head/tools/tools/nanobsd/nanobsd.sh
 
 Modified: head/tools/tools/nanobsd/nanobsd.sh
 ==============================================================================
 --- head/tools/tools/nanobsd/nanobsd.sh	Fri Mar 14 19:46:18 2014	(r263187)
 +++ head/tools/tools/nanobsd/nanobsd.sh	Fri Mar 14 19:46:32 2014	(r263188)
 @@ -136,6 +136,9 @@ NANO_BOOT2CFG="-h"
  # Can be "file" or "swap"
  NANO_MD_BACKING="file"
  
 +# for swap type md(4) backing, write out the mbr only
 +NANO_IMAGE_MBRONLY=true
 +
  # Progress Print level
  PPLEVEL=3
  
 @@ -573,6 +576,14 @@ create_i386_diskimage ( ) (
  	fi
  
  	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
 +		if [ ${NANO_IMAGE_MBRONLY} ]; then
 +			echo "Writing out _.disk.mbr..."
 +			dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1
 +		else
 +			echo "Writing out ${NANO_IMGNAME}..."
 +			dd if=/dev/${MD} of=${IMG} bs=64k
 +		fi
 +
  		echo "Writing out ${NANO_IMGNAME}..."
  		dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k
  	fi
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Fri Mar 14 14:29:37 MDT 2014 
State-Changed-Why:  
All these are now in the tree. Thanks! 


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