Index: trunk/ippScripts/scripts/ipp_cleanup.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_cleanup.pl	(revision 18994)
+++ trunk/ippScripts/scripts/ipp_cleanup.pl	(revision 19397)
@@ -110,6 +110,11 @@
 	my $status = &delete_files (\@files);
 
-	if (! $status)  {
-	    my $command = "$chiptool -updateimfile -chip_id $stage_id -class_id $class_id -code 1"; # Command to run
+	if ($status)  {
+	    my $command = "$chiptool -chip_id $stage_id -class_id $class_id";
+            if ($mode eq "goto_purged") {
+                $command .= " -topurgedimfile";
+            } else {
+                $command .= " -tocleanedimfile";
+            }
 	    $command .= " -dbname $dbname" if defined $dbname;
 
@@ -119,8 +124,21 @@
 		&my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
 	    }
-	    
+        } else {
+	    my $command = "$chiptool -updateimfile -chip_id $stage_id -class_id $class_id -code 1";
+	    $command .= " -dbname $dbname" if defined $dbname;
+
+	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
+	    unless ($success) {
+		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+		&my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
+	    }
 	    $fault = 1;
 	}
     }
+
+if (0) {
+    # This block is not necessary
+    # chiptool -tocleanedimfile and -topurgedimfile automatically update chipRun when the
+    # last image gets set to purged or cleaned
 
     if (! $fault) {
@@ -140,4 +158,5 @@
 	}
     }
+}
     exit 0;
 }
