       }
       case 'I': {
         Serial.println("IDENTIFY FLASH");
-        flash_write(0x55, 0x00980098L);
-        Serial.println(" <-- write");
+
+        flash_write(0x55, 0x00980098L);  // Enter CFI mode
+
+        Serial.print("Device size: 2^");
+        Serial.print(flash_read(0x27) & 0xffff);
+        Serial.println(" bytes");
+
         for (uint32_t cfi_addr = 0x10; cfi_addr <= 0x50; ++cfi_addr) {
+          Serial.print("CFI 0x");
+          Serial.print(cfi_addr, HEX);
+          Serial.print(": ");
           Serial.println(flash_read(cfi_addr), HEX);
         }
+
+        flash_write(0x00, 0xf0);  // Exit CFI mode
+        flash_unlock();  // Allow host access again
+
+        break;
+      }
+      case 'P': {
+        chip_end = chip_size();
+        Serial.print("Program whole chip.  Size = ");
+        Serial.println(chip_end * 2);  // Because we actually have double this
+        program_range(0, chip_end);
         flash_unlock();
+        reset();
         break;
       }
       case 'Z': {

  digitalWrite(CPLD_SS_PIN, HIGH);
}

uint32_t flash_read(uint32_t A) {
  // Read a 32-bit word from the flash, leaving allowing_arm_access == 0
  digitalWrite(CPLD_SS_PIN, LOW);

  digitalWrite(CPLD_SS_PIN, HIGH);
}

// Pulse NRESET on the flash chips
void flash_reset() {
  pinMode(FLASH_NRESET_PIN, OUTPUT);
  digitalWrite(FLASH_NRESET_PIN, LOW);
  digitalWrite(FLASH_NRESET_PIN, HIGH);
  pinMode(FLASH_NRESET_PIN, INPUT_PULLUP);
}

// System startup
void setup() {
  // Set pin directions for CPLD JTAG.
  pinMode(TDO_PIN, INPUT);
