From bremner-dated-1084880483.5406f2@unb.ca  Tue May  4 04:41:24 2004
Return-Path: <bremner-dated-1084880483.5406f2@unb.ca>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7E39816A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  4 May 2004 04:41:24 -0700 (PDT)
Received: from convex.cs.unb.ca (convex.cs.unb.ca [131.202.244.141])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 24B1843D53
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  4 May 2004 04:41:24 -0700 (PDT)
	(envelope-from bremner-dated-1084880483.5406f2@unb.ca)
Received: from bremner by convex.cs.unb.ca with local (Exim 4.24; FreeBSD)
	id 1BKyId-0003Nw-8i
	for FreeBSD-gnats-submit@freebsd.org; Tue, 04 May 2004 08:41:23 -0300
Received: by convex.cs.unb.ca (tmda-sendmail, from uid 1266);
	Tue, 04 May 2004 08:41:23 -0300 (ADT)
Received: from bremner by convex.cs.unb.ca with local (Exim 4.24; FreeBSD)
	id 1BKyIc-0003Nm-Rm
	for FreeBSD-gnats-submit@freebsd.org; Tue, 04 May 2004 08:41:22 -0300
Message-Id: <E1BKyIc-0003Nm-Rm@convex.cs.unb.ca>
Date: Tue, 04 May 2004 08:41:22 -0300
From: David Bremner <bremner@unb.ca>
Sender: David Bremner <bremner@convex.cs.unb.ca>
Reply-To: David Bremner <bremner@unb.ca>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: FreeBSD bootloader is confused by booting from USB flash,
	trashes main drives boot block
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         66248
>Category:       kern
>Synopsis:       [panic] bootloader is confused by booting from U.S.B flash, trashes main drives boot block
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    peadar
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 04 04:50:24 PDT 2004
>Closed-Date:    Wed Jan 26 19:12:56 GMT 2005
>Last-Modified:  Wed Jan 26 19:12:56 GMT 2005
>Originator:     David Bremner
>Release:        FreeBSD 5.2.1-RELEASE-p3 i386
>Organization:
University of New Brunswick
>Environment:
System: FreeBSD convex.cs.unb.ca 5.2.1-RELEASE-p3 FreeBSD 5.2.1-RELEASE-p3 #12: Fri Mar 19 11:08:54 AST 2004 bremner@convex.cs.unb.ca:/usr/obj/usr/src/sys/CONVEX2 i386


	
>Description:
	I was experimenting with booting FreeBSD from a USB flash card 
	with 1 fat partition, with booteasy (written from /stand/sysinstall).
	It seemed to be in an infinite loop of (hard) rebooting, with 
	self-test and all.

	Booting from the harddrive now presents 
		F1 DOS.
	Which does not boot the windows XP partition

	Conjecture:
		At some point I suceeded enough for the bootloader 
	to want to make a note of what it booted last, but it wrote back 
	the wrong boot block.


	
>How-To-Repeat:
	
	see above.
>Fix:

	
	Perhaps just a warning somewhere (fdisk?).






>Release-Note:
>Audit-Trail:

From: David Bremner <bremner@unb.ca>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: i386/66248: FreeBSD bootloader is confused by booting from USB
	flash, trashes main drives boot block
Date: Tue, 04 May 2004 12:58:41 -0300

 follow up information:
 
 I don't know why I said booteasy. I meant whatever fdisk writes for
 "FreeBSD Bootloader".
 
 This is on a Thinkpad X40, attempting to boot frmo a generic (ACOM)
 usb flash adapter with a 128M Hama CF card.
 
 
Responsible-Changed-From-To: freebsd-i386->freebsd-usb 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Nov 4 06:43:05 GMT 2004 
Responsible-Changed-Why:  
Reassign to appropriate mailing list. 

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

From: Hans Petter Selasky <hselasky@c2i.net>
To: jhb@freebsd.org, freebsd-gnats-submit@freebsd.org, bremner@unb.ca
Cc:  
Subject: Re: kern/66248: [panic] bootloader is confused by booting from USB flash, trashes main drives boot block
Date: Mon, 8 Nov 2004 18:24:03 +0100

 --SUOF0GtieIMvvwua
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Hi,
 
 Attached patch for /src/sys/boot/i386/boot0/boot0.S closes kern/66248
 Apply using: cat boot0.S.diff | patch -N -l
 
 
 When the boot0 boot-manager is used on a floppy or USB drive, the floppy's or
 USB's boot-sector gets written to the hdd!
 
 Solution: Only update the boot-sector when there is a valid drive number or
 the drive number is set manually.
 
 To make the patch fit into the code I had to disable the "beep-signal".
 
 Yours
 -HPS
 
 
 --SUOF0GtieIMvvwua
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="boot0.S.diff"
 
 *** boot0.S.ref	Wed Oct 20 17:24:19 2004
 --- boot0.S	Wed Oct 20 17:30:56 2004
 ***************
 *** 103,112 ****
    * Check what flags were loaded with us, specifically, Use a predefined Drive.
    * If what the bios gives us is bad, use the '0' in the block instead, as well.
    */
 ! 		testb $0x20,_FLAGS(%bp)		# Set number drive?
   		jnz main.1			# Yes
   		testb %dl,%dl			# Drive number valid?
   		js main.2			# Possibly (0x80 set)
   main.1:		movb _SETDRV(%bp),%dl		# Drive number to use
   /*
    * Whatever we decided to use, now store it into the fake
 --- 103,117 ----
    * Check what flags were loaded with us, specifically, Use a predefined Drive.
    * If what the bios gives us is bad, use the '0' in the block instead, as well.
    */
 ! 		testb $0x20,_FLAGS(%bp)		# Set drive number?
   		jnz main.1			# Yes
   		testb %dl,%dl			# Drive number valid?
   		js main.2			# Possibly (0x80 set)
 + /*
 +  * Only update the boot-sector when there is a valid drive number or
 +  * the drive number is set manually.
 +  */
 + 		orb $0x40,_FLAGS(%bp)		# Disable updates
   main.1:		movb _SETDRV(%bp),%dl		# Drive number to use
   /*
    * Whatever we decided to use, now store it into the fake
 ***************
 *** 203,210 ****
   /*
    * Start of input loop.  Beep and take note of time
    */
 ! main.10:	movb $ASCII_BEL,%al		# Signal
   		callw putchr			#  beep!
   		xorb %ah,%ah			# BIOS: Get
   		int $0x1a			#  system time
   		movw %dx,%di			# Ticks when
 --- 208,218 ----
   /*
    * Start of input loop.  Beep and take note of time
    */
 ! main.10:
 ! #ifdef BEL
 ! 		movb $ASCII_BEL,%al		# Signal
   		callw putchr			#  beep!
 + #endif
   		xorb %ah,%ah			# BIOS: Get
   		int $0x1a			#  system time
   		movw %dx,%di			# Ticks when
 
 --SUOF0GtieIMvvwua--

From: Peter Edwards <peadar@freebsd.org>
To: freebsd-gnats-submit@FreeBSD.org, bremner@unb.ca
Cc: julian@elischer.org, imp@bsdimp.org
Subject: Re: kern/66248: [panic] bootloader is confused by booting from USB
 flash, trashes main drives boot block
Date: Wed, 05 Jan 2005 20:53:02 +0000

 This is a multi-part message in MIME format.
 --------------070200040205060401080901
 Content-Type: text/plain; charset=us-ascii; format=flowed
 Content-Transfer-Encoding: 7bit
 
 The following patch, applied before the one above, shrinks boot0 enough 
 to squeeze the previous patch in without undeffing the BEL stuff.
 
 FWIW: The patch to fix the bug looks good to me.
 I someone gives a go-ahead, I'll commit a combined patch: I certainly 
 don't want to make a commit to boot0 and have half the FreeBSD community 
 left without a bootable machine, unless I can pass the book :-)
 
 
 --------------070200040205060401080901
 Content-Type: text/plain;
  name="boot0.smaller.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="boot0.smaller.patch"
 
 Index: boot0.S
 ===================================================================
 RCS file: /usr/cvs/FreeBSD-CVS/src/sys/boot/i386/boot0/boot0.S,v
 retrieving revision 1.12
 diff -u -w -r1.12 boot0.S
 --- boot0.S	24 Nov 2004 15:39:04 -0000	1.12
 +++ boot0.S	5 Jan 2005 20:44:32 -0000
 @@ -29,7 +29,7 @@
  		.set PRT_OFF,0x1be		# Partition table
  
  		.set TBL0SZ,0x3 		# Table 0 size
 -		.set TBL1SZ,0xb 		# Table 1 size
 +		.set TBL1SZ,0xc 		# Table 1 size
  
  		.set MAGIC,0xaa55		# Magic: bootable
  		.set B0MAGIC,0xbb66		# Identification
 @@ -148,13 +148,8 @@
  		movb $TBL1SZ,%cl		# Number of entries
  		repne				# Known
  		scasb				#  type?
 -		jne main.4			# No
 -/*
 - * If it matches get the matching element in the next array.  If it doesn't,
 - * we are already pointing at its first element which points to a "?".
 - */
 -		addw $TBL1SZ,%di		# Adjust
 -main.4:		movb (%di),%cl			# Partition
 +		addw $TBL1SZ - 1, %di		# Adjust
 +		movb (%di),%cl			# Partition
  		addw %cx,%di			#  description
  		callw putx			# Display it
  main.5:		incw %dx			# Next item
 @@ -314,8 +309,7 @@
  		cmpw $MAGIC,0x1fe(%bx)		# Bootable?
  		jne main.10			# No
  		pushw %si			# Save
 -		movw $crlf,%si			# Leave some
 -		callw puts			#  space
 +		callw putn			# Leave some space
  		popw %si			# Restore
  		jmp *%bx			# Invoke bootstrap
  
 @@ -408,14 +402,14 @@
  		.byte 0x0, 0x5, 0xf
  /*
   * These values indicate bootable types we know the names of.
 + * The value of the last entry is unimportant: it indicates "everything else"
   */
  		.byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0x83
 -		.byte 0x9f, 0xa5, 0xa6, 0xa9
 +		.byte 0x9f, 0xa5, 0xa6, 0xa9, 0xff
  /*
   * These are offsets that match the known names above and point to the strings
   * that will be printed.
   */
 -		.byte os_misc-. 		# Unknown
  		.byte os_dos-.			# DOS
  		.byte os_dos-.			# DOS
  		.byte os_dos-.			# DOS
 @@ -427,6 +421,7 @@
  		.byte os_freebsd-.		# FreeBSD
  		.byte os_bsd-.			# OpenBSD
  		.byte os_bsd-.			# NetBSD
 +		.byte os_misc-. 		# Unknown
  /*
   * And here are the strings themselves. 0x80 or'd into a byte indicates
   * the end of the string. (not so great for Russians but...)
 
 --------------070200040205060401080901--
State-Changed-From-To: open->patched 
State-Changed-By: peadar 
State-Changed-When: Mon Jan 10 00:27:44 GMT 2005 
State-Changed-Why:  
Patch appied to -current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=66248 
Responsible-Changed-From-To: freebsd-usb->peadar 
Responsible-Changed-By: julian 
Responsible-Changed-When: Mon Jan 10 03:52:32 GMT 2005 
Responsible-Changed-Why:  
Taken over by peadar.. stop it showing up in the USB 'to-do' list :-) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=66248 
State-Changed-From-To: patched->closed 
State-Changed-By: peadar 
State-Changed-When: Wed Jan 26 19:12:02 GMT 2005 
State-Changed-Why:  
Patch committed to -current and RELENG_5 


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