Index: trunk/ippScripts/scripts/chip_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/chip_imfile.pl	(revision 25471)
+++ trunk/ippScripts/scripts/chip_imfile.pl	(revision 25539)
@@ -144,10 +144,21 @@
     ## XXX make the feature more general?
     my $useDeburnedImage = metadataLookupBool($recipeData, 'USE.DEBURNED.IMAGE');
+
     if ($useDeburnedImage) {
-        ## Check that we have required programs:
-#       print STDERR "Inside burntool loop!\n";
-        my $regtool  = can_run('regtool') or &my_die ("Can't find regtool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-        my $burntool = can_run('burntool') or &my_die ("Can't find burntool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+	my $useBestBurntool  = metadataLookupBool($recipeData, 'USE.BEST.BURNTOOL');
+
+	## Check that we have required programs:
+#	print STDERR "Inside burntool loop!\n";
+	my $regtool  = can_run('regtool') or &my_die ("Can't find regtool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+	my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+	my $burntool = can_run('burntool') or &my_die ("Can't find burntool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+	
+	## Check the current burntool processing version:
+	my $regtool_state_cmd = "$regtool -processedimfile -exp_id $exp_id -class_id $class_id -limit 1";
+	if (defined($dbname)) {
+	    $regtool_state_cmd .= " -dbname $dbname";
+	}
+	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	    run(command => $regtool_state_cmd, verbose => $verbose);
 
         ## Check the current burntool processing version:
@@ -200,7 +211,28 @@
         }
 
-        if (abs($burntoolState) != $burntoolStateGood) {
-            &my_die("Image burntool version does not match current accepted version.", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-        }
+	if (abs($burntoolState) != $burntoolStateGood) {
+	    if ($useBestBurntool) {
+		&my_die("Image burntool version does not match current accepted version.", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+	    }
+	    else {
+		warn ("Image burntool version does not match current accepted version. Continuing as requested.");
+		# Internally pretend that we're at a good version.
+		if ($burntoolState < -10) {
+		    $burntoolState = -1 * $burntoolStateGood;
+		}
+		elsif ($burntoolState > 10) {
+		    $burntoolState = $burntoolStateGood;
+		}
+		elsif ($burntoolState == 0) {
+		    # You've told me to use a deburned image, and that you don't care if it's the most recent. The database has told me
+		    # that burntool has never been run on this image. We'll hope the database is wrong, but I don't really trust that.
+		    warn ("burntool_state suggests no table will be found. This will likely crash.");
+		    $burntoolState = -1 * $burntoolStateGood;
+		}
+		else {
+		    &my_die("No valid burntool table will be found.", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+		}
+	    }
+	}
 
         ## We now know that we have an image that has been burntooled.
