Parcourir la source

Merge pull request #152 from ZuluSCSI/bscsi_sync

Reduce differences with BlueSCSI fork
Alex Perez il y a 2 ans
Parent
commit
32f007da93
29 fichiers modifiés avec 548 ajouts et 515 suppressions
  1. 55 55
      lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.cpp
  2. 15 15
      lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.h
  3. 4 4
      lib/ZuluSCSI_platform_GD32F205/greenpak.cpp
  4. 3 3
      lib/ZuluSCSI_platform_GD32F205/scsiPhy.cpp
  5. 5 5
      lib/ZuluSCSI_platform_GD32F205/scsi_accel_dma.cpp
  6. 3 3
      lib/ZuluSCSI_platform_GD32F205/scsi_accel_sync.cpp
  7. 14 14
      lib/ZuluSCSI_platform_GD32F205/sd_card_sdio.cpp
  8. 7 7
      lib/ZuluSCSI_platform_GD32F205/sd_card_spi.cpp
  9. 62 62
      lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp
  10. 18 18
      lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.h
  11. 16 16
      lib/ZuluSCSI_platform_RP2040/rp2040_sdio.cpp
  12. 5 5
      lib/ZuluSCSI_platform_RP2040/scsiHostPhy.cpp
  13. 2 2
      lib/ZuluSCSI_platform_RP2040/scsiPhy.cpp
  14. 1 1
      lib/ZuluSCSI_platform_RP2040/scsi_accel_host.cpp
  15. 4 4
      lib/ZuluSCSI_platform_RP2040/scsi_accel_rp2040.cpp
  16. 24 24
      lib/ZuluSCSI_platform_RP2040/sd_card_sdio.cpp
  17. 1 1
      lib/ZuluSCSI_platform_RP2040/sd_card_spi.cpp
  18. 1 1
      lib/ZuluSCSI_platform_template/README.md
  19. 7 7
      lib/ZuluSCSI_platform_template/ZuluSCSI_platform.cpp
  20. 7 7
      lib/ZuluSCSI_platform_template/ZuluSCSI_platform.h
  21. 1 1
      lib/ZuluSCSI_platform_template/scsiPhy.cpp
  22. 54 42
      src/ZuluSCSI.cpp
  23. 23 23
      src/ZuluSCSI_bootloader.cpp
  24. 106 87
      src/ZuluSCSI_disk.cpp
  25. 2 0
      src/ZuluSCSI_disk.h
  26. 40 40
      src/ZuluSCSI_initiator.cpp
  27. 18 18
      src/ZuluSCSI_log.cpp
  28. 24 24
      src/ZuluSCSI_log.h
  29. 26 26
      src/ZuluSCSI_log_trace.cpp

+ 55 - 55
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.cpp

@@ -10,7 +10,7 @@
 
 extern "C" {
 
-const char *g_azplatform_name = PLATFORM_NAME;
+const char *g_platform_name = PLATFORM_NAME;
 static bool g_enable_apple_quirks = false;
 
 /*************************/
@@ -57,7 +57,7 @@ void SysTick_Handler_inner(uint32_t *sp)
         {
             if (!scsiDev.resetFlag)
             {
-                azlog("WATCHDOG TIMEOUT at PC ", sp[6], " LR ", sp[5], " attempting bus reset");
+                logmsg("WATCHDOG TIMEOUT at PC ", sp[6], " LR ", sp[5], " attempting bus reset");
                 scsiDev.resetFlag = 1;
             }
 
@@ -108,7 +108,7 @@ void SysTick_Handle_PreEmptively()
 
 // Initialize SPI and GPIO configuration
 // Clock has already been initialized by system_gd32f20x.c
-void azplatform_init()
+void platform_init()
 {
     SystemCoreClockUpdate();
 
@@ -201,48 +201,48 @@ void azplatform_init()
     gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
 }
 
-void azplatform_late_init()
+void platform_late_init()
 {
-    azlog("Platform: ", g_azplatform_name);
-    azlog("FW Version: ", g_azlog_firmwareversion);
+    logmsg("Platform: ", g_platform_name);
+    logmsg("FW Version: ", g_log_firmwareversion);
     
 #ifdef ZULUSCSI_V1_0_mini
-    azlog("DIPSW3 is ON: Enabling SCSI termination");
+    logmsg("DIPSW3 is ON: Enabling SCSI termination");
 #else
     if (gpio_input_bit_get(DIP_PORT, DIPSW3_PIN))
     {
-        azlog("DIPSW3 is ON: Enabling SCSI termination");
+        logmsg("DIPSW3 is ON: Enabling SCSI termination");
         gpio_bit_reset(SCSI_TERM_EN_PORT, SCSI_TERM_EN_PIN);
     }
     else
     {
-        azlog("DIPSW3 is OFF: SCSI termination disabled");
+        logmsg("DIPSW3 is OFF: SCSI termination disabled");
     }
 #endif // ZULUSCSI_V1_0_mini
 
     if (gpio_input_bit_get(DIP_PORT, DIPSW2_PIN))
     {
-        azlog("DIPSW2 is ON: enabling debug messages");
-        g_azlog_debug = true;
+        logmsg("DIPSW2 is ON: enabling debug messages");
+        g_log_debug = true;
     }
     else
     {
-        g_azlog_debug = false;
+        g_log_debug = false;
     }
 
     if (gpio_input_bit_get(DIP_PORT, DIPSW1_PIN))
     {
-        azlog("DIPSW1 is ON: enabling Apple quirks by default");
+        logmsg("DIPSW1 is ON: enabling Apple quirks by default");
         g_enable_apple_quirks = true;
     }
 
     greenpak_load_firmware();
 }
 
-void azplatform_disable_led(void)
+void platform_disable_led(void)
 {   
     gpio_init(LED_PORT, GPIO_MODE_IPU, 0, LED_PINS);
-    azlog("Disabling status LED");
+    logmsg("Disabling status LED");
 }
 
 /*****************************************/
@@ -252,7 +252,7 @@ void azplatform_disable_led(void)
 extern SdFs SD;
 
 // Writes log data to the PB3 SWO pin
-void azplatform_log(const char *s)
+void platform_log(const char *s)
 {
     while (*s)
     {
@@ -262,9 +262,9 @@ void azplatform_log(const char *s)
     }
 }
 
-void azplatform_emergency_log_save()
+void platform_emergency_log_save()
 {
-    azplatform_set_sd_callback(NULL, NULL);
+    platform_set_sd_callback(NULL, NULL);
 
     SD.begin(SD_CONFIG_CRASH);
     FsFile crashfile = SD.open(CRASHFILE, O_WRONLY | O_CREAT | O_TRUNC);
@@ -279,8 +279,8 @@ void azplatform_emergency_log_save()
     }
 
     uint32_t startpos = 0;
-    crashfile.write(azlog_get_buffer(&startpos));
-    crashfile.write(azlog_get_buffer(&startpos));
+    crashfile.write(log_get_buffer(&startpos));
+    crashfile.write(log_get_buffer(&startpos));
     crashfile.flush();
     crashfile.close();
 }
@@ -294,29 +294,29 @@ void show_hardfault(uint32_t *sp)
     uint32_t lr = sp[5];
     uint32_t cfsr = SCB->CFSR;
     
-    azlog("--------------");
-    azlog("CRASH!");
-    azlog("Platform: ", g_azplatform_name);
-    azlog("FW Version: ", g_azlog_firmwareversion);
-    azlog("CFSR: ", cfsr);
-    azlog("SP: ", (uint32_t)sp);
-    azlog("PC: ", pc);
-    azlog("LR: ", lr);
-    azlog("R0: ", sp[0]);
-    azlog("R1: ", sp[1]);
-    azlog("R2: ", sp[2]);
-    azlog("R3: ", sp[3]);
+    logmsg("--------------");
+    logmsg("CRASH!");
+    logmsg("Platform: ", g_platform_name);
+    logmsg("FW Version: ", g_log_firmwareversion);
+    logmsg("CFSR: ", cfsr);
+    logmsg("SP: ", (uint32_t)sp);
+    logmsg("PC: ", pc);
+    logmsg("LR: ", lr);
+    logmsg("R0: ", sp[0]);
+    logmsg("R1: ", sp[1]);
+    logmsg("R2: ", sp[2]);
+    logmsg("R3: ", sp[3]);
 
     uint32_t *p = (uint32_t*)((uint32_t)sp & ~3);
     for (int i = 0; i < 8; i++)
     {
         if (p == &_estack) break; // End of stack
         
-        azlog("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
+        logmsg("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
         p += 4;
     }
 
-    azplatform_emergency_log_save();
+    platform_emergency_log_save();
 
     while (1)
     {
@@ -371,22 +371,22 @@ void __assert_func(const char *file, int line, const char *func, const char *exp
 {
     uint32_t dummy = 0;
 
-    azlog("--------------");
-    azlog("ASSERT FAILED!");
-    azlog("Platform: ", g_azplatform_name);
-    azlog("FW Version: ", g_azlog_firmwareversion);
-    azlog("Assert failed: ", file , ":", line, " in ", func, ":", expr);
+    logmsg("--------------");
+    logmsg("ASSERT FAILED!");
+    logmsg("Platform: ", g_platform_name);
+    logmsg("FW Version: ", g_log_firmwareversion);
+    logmsg("Assert failed: ", file , ":", line, " in ", func, ":", expr);
 
     uint32_t *p = (uint32_t*)((uint32_t)&dummy & ~3);
     for (int i = 0; i < 8; i++)
     {
         if (p == &_estack) break; // End of stack
 
-        azlog("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
+        logmsg("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
         p += 4;
     }
 
-    azplatform_emergency_log_save();
+    platform_emergency_log_save();
 
     while(1)
     {
@@ -401,11 +401,11 @@ void __assert_func(const char *file, int line, const char *func, const char *exp
 
 static void watchdog_handler(uint32_t *sp)
 {
-    azlog("-------------- WATCHDOG TIMEOUT");
+    logmsg("-------------- WATCHDOG TIMEOUT");
     show_hardfault(sp);
 }
 
-void azplatform_reset_watchdog()
+void platform_reset_watchdog()
 {
     // This uses a software watchdog based on systick timer interrupt.
     // It gives us opportunity to collect better debug info than the
@@ -417,20 +417,20 @@ void azplatform_reset_watchdog()
 /* Flash reprogramming */
 /***********************/
 
-bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FLASH_PAGE_SIZE])
+bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_PAGE_SIZE])
 {
     if (offset == 0)
     {
         if (buffer[3] != 0x20 || buffer[7] != 0x08)
         {
-            azlog("Invalid firmware file, starts with: ", bytearray(buffer, 16));
+            logmsg("Invalid firmware file, starts with: ", bytearray(buffer, 16));
             return false;
         }
     }
 
-    azdbg("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
-    assert(offset % AZPLATFORM_FLASH_PAGE_SIZE == 0);
-    assert(offset >= AZPLATFORM_BOOTLOADER_SIZE);
+    dbgmsg("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
+    assert(offset % PLATFORM_FLASH_PAGE_SIZE == 0);
+    assert(offset >= PLATFORM_BOOTLOADER_SIZE);
     
     fmc_unlock();
     fmc_bank0_unlock();
@@ -439,18 +439,18 @@ bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FL
     status = fmc_page_erase(FLASH_BASE + offset);
     if (status != FMC_READY)
     {
-        azlog("Erase failed: ", (int)status);
+        logmsg("Erase failed: ", (int)status);
         return false;
     }
 
     uint32_t *buf32 = (uint32_t*)buffer;
-    uint32_t num_words = AZPLATFORM_FLASH_PAGE_SIZE / 4;
+    uint32_t num_words = PLATFORM_FLASH_PAGE_SIZE / 4;
     for (int i = 0; i < num_words; i++)
     {
         status = fmc_word_program(FLASH_BASE + offset + i * 4, buf32[i]);
         if (status != FMC_READY)
         {
-            azlog("Flash write failed: ", (int)status);
+            logmsg("Flash write failed: ", (int)status);
             return false;
         }   
     }
@@ -463,16 +463,16 @@ bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FL
         uint32_t actual = *(volatile uint32_t*)(FLASH_BASE + offset + i * 4);
         if (actual != expected)
         {
-            azlog("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
+            logmsg("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
             return false;
         }
     }
     return true;
 }
 
-void azplatform_boot_to_main_firmware()
+void platform_boot_to_main_firmware()
 {
-    uint32_t *mainprogram_start = (uint32_t*)(0x08000000 + AZPLATFORM_BOOTLOADER_SIZE);
+    uint32_t *mainprogram_start = (uint32_t*)(0x08000000 + PLATFORM_BOOTLOADER_SIZE);
     SCB->VTOR = (uint32_t)mainprogram_start;
   
     __asm__(
@@ -485,7 +485,7 @@ void azplatform_boot_to_main_firmware()
 /* SCSI configuration based on DIPSW1 */
 /**************************************/
 
-void azplatform_config_hook(S2S_TargetCfg *config)
+void platform_config_hook(S2S_TargetCfg *config)
 {
     // Enable Apple quirks by dip switch
     if (g_enable_apple_quirks)

+ 15 - 15
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.h

@@ -12,7 +12,7 @@
 extern "C" {
 #endif
 
-extern const char *g_azplatform_name;
+extern const char *g_platform_name;
 
 #if defined(ZULUSCSI_V1_0)
 #   if defined(ZULUSCSI_V1_0_mini)
@@ -34,7 +34,7 @@ extern const char *g_azplatform_name;
 #endif
 
 // Debug logging functions
-void azplatform_log(const char *s);
+void platform_log(const char *s);
 
 // Minimal millis() implementation as GD32F205 does not
 // have an Arduino core yet.
@@ -60,25 +60,25 @@ static inline void delay_100ns()
 }
 
 // Initialize SPI and GPIO configuration
-void azplatform_init();
+void platform_init();
 
 // Initialization for main application, not used for bootloader
-void azplatform_late_init();
+void platform_late_init();
 
 // Disable the status LED
-void azplatform_disable_led(void);
+void platform_disable_led(void);
 
 // Setup soft watchdog
-void azplatform_reset_watchdog();
+void platform_reset_watchdog();
 
 // Reinitialize SD card connection and save log from interrupt context.
 // This can be used in crash handlers.
-void azplatform_emergency_log_save();
+void platform_emergency_log_save();
 
 // Set callback that will be called during data transfer to/from SD card.
 // This can be used to implement simultaneous transfer to SCSI bus.
 typedef void (*sd_callback_t)(uint32_t bytes_complete);
-void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
+void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
 
 // This function is called by scsiPhy.cpp.
 // It resets the systick counter to give 1 millisecond of uninterrupted transfer time.
@@ -86,16 +86,16 @@ void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
 void SysTick_Handle_PreEmptively();
 
 // Reprogram firmware in main program area.
-#define AZPLATFORM_BOOTLOADER_SIZE 32768
-#define AZPLATFORM_FLASH_TOTAL_SIZE (256 * 1024)
-#define AZPLATFORM_FLASH_PAGE_SIZE 2048
-bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FLASH_PAGE_SIZE]);
-void azplatform_boot_to_main_firmware();
+#define PLATFORM_BOOTLOADER_SIZE 32768
+#define PLATFORM_FLASH_TOTAL_SIZE (256 * 1024)
+#define PLATFORM_FLASH_PAGE_SIZE 2048
+bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_PAGE_SIZE]);
+void platform_boot_to_main_firmware();
 
 // Configuration customizations based on DIP switch settings
 // When DIPSW1 is on, Apple quirks are enabled by default.
-void azplatform_config_hook(S2S_TargetCfg *config);
-#define AZPLATFORM_CONFIG_HOOK(cfg) azplatform_config_hook(cfg)
+void platform_config_hook(S2S_TargetCfg *config);
+#define PLATFORM_CONFIG_HOOK(cfg) platform_config_hook(cfg)
 
 // Write a single SCSI pin.
 // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.

+ 4 - 4
lib/ZuluSCSI_platform_GD32F205/greenpak.cpp

@@ -155,22 +155,22 @@ bool greenpak_load_firmware()
 
     if (!greenpak_read(0, &dummy, 1))
     {
-        azlog("Optional GreenPAK not detected");
+        logmsg("Optional GreenPAK not detected");
         return false;
     }
     else
     {
-        azlog("Optional GreenPAK detected, loading firmware");
+        logmsg("Optional GreenPAK detected, loading firmware");
     }
 
     if (!greenpak_write(0, g_greenpak_fw, sizeof(g_greenpak_fw)))
     {
-        azlog("GreenPAK firmware loading failed");
+        logmsg("GreenPAK firmware loading failed");
         return false;
     }
     else
     {
-        azlog("GreenPAK firmware successfully loaded");
+        logmsg("GreenPAK firmware successfully loaded");
         LED_ON();
         delay(10);
         LED_OFF();

+ 3 - 3
lib/ZuluSCSI_platform_GD32F205/scsiPhy.cpp

@@ -117,7 +117,7 @@ static void scsi_rst_assert_interrupt()
 
     if (rst1 && rst2)
     {
-        azdbg("BUS RESET");
+        dbgmsg("BUS RESET");
         scsiDev.resetFlag = 1;
     }
 }
@@ -164,7 +164,7 @@ static void selectPhyMode()
 
     if (g_scsi_phy_mode != oldmode)
     {
-        azlog("SCSI PHY operating mode: ", g_scsi_phy_mode_names[g_scsi_phy_mode]);
+        logmsg("SCSI PHY operating mode: ", g_scsi_phy_mode_names[g_scsi_phy_mode]);
     }
 }
 
@@ -353,7 +353,7 @@ extern "C" void scsiStartWrite(const uint8_t* data, uint32_t count)
     }
     else
     {
-        azlog("Unknown SCSI PHY mode: ", (int)g_scsi_phy_mode);
+        logmsg("Unknown SCSI PHY mode: ", (int)g_scsi_phy_mode);
     }
 }
 

+ 5 - 5
lib/ZuluSCSI_platform_GD32F205/scsi_accel_dma.cpp

@@ -273,7 +273,7 @@ static void check_dma_next_buffer()
 // Convert new data from application buffer to DMA buffer
 extern "C" void SCSI_TIMER_DMACHA_IRQ()
 {
-    // azdbg("DMA irq A, counts: ", DMA_CHCNT(SCSI_TIMER_DMA, SCSI_TIMER_DMACHA), " ",
+    // dbgmsg("DMA irq A, counts: ", DMA_CHCNT(SCSI_TIMER_DMA, SCSI_TIMER_DMACHA), " ",
     //             DMA_CHCNT(SCSI_TIMER_DMA, SCSI_TIMER_DMACHB), " ",
     //             TIMER_CNT(SCSI_TIMER));
 
@@ -284,7 +284,7 @@ extern "C" void SCSI_TIMER_DMACHA_IRQ()
     {
         if (intf & full_flag)
         {
-            azlog("ERROR: SCSI DMA overrun: ", intf,
+            logmsg("ERROR: SCSI DMA overrun: ", intf,
                " bytes_app: ", g_scsi_dma.bytes_app,
                " bytes_dma: ", g_scsi_dma.bytes_dma,
                " dma_idx: ", g_scsi_dma.dma_idx,
@@ -311,7 +311,7 @@ extern "C" void SCSI_TIMER_DMACHA_IRQ()
 // Check if enough data is available to continue DMA transfer
 extern "C" void SCSI_TIMER_DMACHB_IRQ()
 {
-    // azdbg("DMA irq B, counts: ", DMA_CHCNT(SCSI_TIMER_DMA, SCSI_TIMER_DMACHA), " ",
+    // dbgmsg("DMA irq B, counts: ", DMA_CHCNT(SCSI_TIMER_DMA, SCSI_TIMER_DMACHA), " ",
     //             DMA_CHCNT(SCSI_TIMER_DMA, SCSI_TIMER_DMACHB), " ",
     //             TIMER_CNT(SCSI_TIMER));
     uint32_t intf = DMA_INTF(SCSI_TIMER_DMA);
@@ -394,7 +394,7 @@ void scsi_accel_dma_startWrite(const uint8_t* data, uint32_t count, volatile int
         }
     }
 
-    // azdbg("Starting DMA write of ", (int)count, " bytes");
+    // dbgmsg("Starting DMA write of ", (int)count, " bytes");
     scsi_dma_gpio_config(true);
     g_scsi_dma_state = SCSIDMA_WRITE;
     g_scsi_dma.app_buf = (uint8_t*)data;
@@ -452,7 +452,7 @@ void scsi_accel_dma_finishWrite(volatile int *resetFlag)
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            azlog("scsi_accel_dma_finishWrite() timeout, DMA counts ",
+            logmsg("scsi_accel_dma_finishWrite() timeout, DMA counts ",
                 DMA_CHCNT(SCSI_TIMER_DMA, SCSI_TIMER_DMACHA), " ",
                 DMA_CHCNT(SCSI_TIMER_DMA, SCSI_TIMER_DMACHB), " ",
                 TIMER_CNT(SCSI_TIMER));

+ 3 - 3
lib/ZuluSCSI_platform_GD32F205/scsi_accel_sync.cpp

@@ -135,7 +135,7 @@ void scsi_accel_sync_recv(uint8_t *data, uint32_t count, int* parityError, volat
             {
                 // We are in a pinch here: without ACK pulses coming, the EXMC and DMA peripherals
                 // are locked up. The only way out is a whole system reset.
-                azlog("SCSI Synchronous read timeout: resetting system");
+                logmsg("SCSI Synchronous read timeout: resetting system");
                 NVIC_SystemReset();
             }
         }
@@ -450,7 +450,7 @@ void scsi_accel_sync_send(const uint8_t* data, uint32_t count, volatile int *res
     }
     else
     {
-        azdbg("No optimized routine for syncOffset=", syncOffset, " syndPeriod=", syncPeriod, ", using fallback");
+        dbgmsg("No optimized routine for syncOffset=", syncOffset, " syndPeriod=", syncPeriod, ", using fallback");
         while (count-- > 0)
         {
             while (TIMER_CNT(SCSI_SYNC_TIMER) > count + syncOffset && !*resetFlag);
@@ -468,7 +468,7 @@ void scsi_accel_sync_send(const uint8_t* data, uint32_t count, volatile int *res
 
     if (*resetFlag)
     {
-        azdbg("Bus reset during sync transfer, total ", (int)count,
+        dbgmsg("Bus reset during sync transfer, total ", (int)count,
               " bytes, remaining ACK count ", (int)TIMER_CNT(SCSI_SYNC_TIMER));
     }
 

+ 14 - 14
lib/ZuluSCSI_platform_GD32F205/sd_card_sdio.cpp

@@ -23,7 +23,7 @@ static uint32_t g_sdio_sector_count;
 static bool logSDError(int line)
 {
     g_sdio_error_line = line;
-    azlog("SDIO SD card error on line ", line, ", error code ", (int)g_sdio_error);
+    logmsg("SDIO SD card error on line ", line, ", error code ", (int)g_sdio_error);
     return false;
 }
 
@@ -37,7 +37,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
     if (g_sdio_error != SD_OK)
     {
         // Don't spam the log when main program polls for card insertion.
-        azdbg("sd_init() failed: ", (int)g_sdio_error);
+        dbgmsg("sd_init() failed: ", (int)g_sdio_error);
         return false;
     }
 
@@ -98,19 +98,19 @@ bool SdioCard::readOCR(uint32_t* ocr)
 
 bool SdioCard::readData(uint8_t* dst)
 {
-    azlog("SdioCard::readData() called but not implemented!");
+    logmsg("SdioCard::readData() called but not implemented!");
     return false;
 }
 
 bool SdioCard::readStart(uint32_t sector)
 {
-    azlog("SdioCard::readStart() called but not implemented!");
+    logmsg("SdioCard::readStart() called but not implemented!");
     return false;
 }
 
 bool SdioCard::readStop()
 {
-    azlog("SdioCard::readStop() called but not implemented!");
+    logmsg("SdioCard::readStop() called but not implemented!");
     return false;
 }
 
@@ -147,7 +147,7 @@ bool SdioCard::stopTransmission(bool blocking)
         }
         if (isBusy())
         {
-            azlog("SdioCard::stopTransmission() timeout");
+            logmsg("SdioCard::stopTransmission() timeout");
             return false;
         }
         else
@@ -178,19 +178,19 @@ uint8_t SdioCard::type() const
 
 bool SdioCard::writeData(const uint8_t* src)
 {
-    azlog("SdioCard::writeData() called but not implemented!");
+    logmsg("SdioCard::writeData() called but not implemented!");
     return false;
 }
 
 bool SdioCard::writeStart(uint32_t sector)
 {
-    azlog("SdioCard::writeStart() called but not implemented!");
+    logmsg("SdioCard::writeStart() called but not implemented!");
     return false;
 }
 
 bool SdioCard::writeStop()
 {
-    azlog("SdioCard::writeStop() called but not implemented!");
+    logmsg("SdioCard::writeStop() called but not implemented!");
     return false;
 }
 
@@ -200,12 +200,12 @@ bool SdioCard::erase(uint32_t firstSector, uint32_t lastSector)
 }
 
 bool SdioCard::cardCMD6(uint32_t arg, uint8_t* status) {
-    azlog("SdioCard::cardCMD6() not implemented");
+    logmsg("SdioCard::cardCMD6() not implemented");
     return false;
 }
 
 bool SdioCard::readSCR(scr_t* scr) {
-    azlog("SdioCard::readSCR() not implemented");
+    logmsg("SdioCard::readSCR() not implemented");
     return false;
 }
 
@@ -216,7 +216,7 @@ static const uint8_t *m_stream_buffer;
 static uint32_t m_stream_count;
 static uint32_t m_stream_count_start;
 
-void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
+void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
 {
     m_stream_callback = func;
     m_stream_buffer = buffer;
@@ -245,7 +245,7 @@ static sdio_callback_t get_stream_callback(const uint8_t *buf, uint32_t count, c
         }
         else
         {
-            azdbg("SD card ", accesstype, "(", (int)sector,
+            dbgmsg("SD card ", accesstype, "(", (int)sector,
                   ") slow transfer, buffer", (uint32_t)buf, " vs. ", (uint32_t)(m_stream_buffer + m_stream_count));
             return NULL;
         }
@@ -282,7 +282,7 @@ bool SdioCard::readSectors(uint32_t sector, uint8_t* dst, size_t n)
         {
             if (!readSector(sector + i, dst + i * 512))
             {
-                azlog("End of drive read failed at ", sector, " + ", i);
+                logmsg("End of drive read failed at ", sector, " + ", i);
                 return false;
             }
         }

+ 7 - 7
lib/ZuluSCSI_platform_GD32F205/sd_card_spi.cpp

@@ -121,7 +121,7 @@ public:
         }
         else if (m_stream_callback)
         {
-            azdbg("Stream buffer mismatch: ", (uint32_t)buf, " vs. ", (uint32_t)(m_stream_buffer + m_stream_count));
+            dbgmsg("Stream buffer mismatch: ", (uint32_t)buf, " vs. ", (uint32_t)(m_stream_buffer + m_stream_count));
         }
 
         // Use DMA to stream dummy TX data and store RX data
@@ -143,7 +143,7 @@ public:
         {
             if (millis() - start > 500)
             {
-                azlog("ERROR: SPI DMA receive of ", (int)count, " bytes timeouted");
+                logmsg("ERROR: SPI DMA receive of ", (int)count, " bytes timeouted");
                 return 1;
             }
 
@@ -156,7 +156,7 @@ public:
 
         if (DMA_INTF(DMA0) & DMA_FLAG_ADD(DMA_FLAG_ERR, SD_SPI_RX_DMA_CHANNEL))
         {
-            azlog("ERROR: SPI DMA receive set DMA_FLAG_ERR");
+            logmsg("ERROR: SPI DMA receive set DMA_FLAG_ERR");
         }
 
         SPI_CTL1(SD_SPI) &= ~(SPI_CTL1_DMAREN | SPI_CTL1_DMATEN);
@@ -181,7 +181,7 @@ public:
         }
         else if (m_stream_callback)
         {
-            azdbg("Stream buffer mismatch: ", (uint32_t)buf, " vs. ", (uint32_t)(m_stream_buffer + m_stream_count));
+            dbgmsg("Stream buffer mismatch: ", (uint32_t)buf, " vs. ", (uint32_t)(m_stream_buffer + m_stream_count));
         }
 
         // Use DMA to stream TX data
@@ -198,7 +198,7 @@ public:
         {
             if (millis() - start > 500)
             {
-                azlog("ERROR: SPI DMA transmit of ", (int)count, " bytes timeouted");
+                logmsg("ERROR: SPI DMA transmit of ", (int)count, " bytes timeouted");
                 return;
             }
 
@@ -211,7 +211,7 @@ public:
 
         if (DMA_INTF(DMA0) & DMA_FLAG_ADD(DMA_FLAG_ERR, SD_SPI_TX_DMA_CHANNEL))
         {
-            azlog("ERROR: SPI DMA transmit set DMA_FLAG_ERR");
+            logmsg("ERROR: SPI DMA transmit set DMA_FLAG_ERR");
         }
 
         wait_idle();
@@ -258,7 +258,7 @@ void sdCsWrite(SdCsPin_t pin, bool level)
 GD32SPIDriver g_sd_spi_port;
 SdSpiConfig g_sd_spi_config(0, DEDICATED_SPI, SD_SCK_MHZ(30), &g_sd_spi_port);
 
-void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
+void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
 {
     g_sd_spi_port.set_sd_callback(func, buffer);    
 }

+ 62 - 62
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp

@@ -18,7 +18,7 @@ extern "C" {
 #include <hardware/flash.h>
 #include "rp2040_flash_do_cmd.h"
 
-const char *g_azplatform_name = PLATFORM_NAME;
+const char *g_platform_name = PLATFORM_NAME;
 static bool g_scsi_initiator = false;
 static uint32_t g_flash_chip_size = 0;
 static bool g_uart_initialized = false;
@@ -43,7 +43,7 @@ static void gpio_conf(uint gpio, enum gpio_function fn, bool pullup, bool pulldo
     }
 }
 
-void azplatform_init()
+void platform_init()
 {
     // Make sure second core is stopped
     multicore_reset_core1();
@@ -73,20 +73,20 @@ void azplatform_init()
     g_uart_initialized = true;
     mbed_set_error_hook(mbed_error_hook);
 
-    azlog("Platform: ", g_azplatform_name);
-    azlog("FW Version: ", g_azlog_firmwareversion);
+    logmsg("Platform: ", g_platform_name);
+    logmsg("FW Version: ", g_log_firmwareversion);
 
-    azlog("DIP switch settings: debug log ", (int)dbglog, ", termination ", (int)termination);
+    logmsg("DIP switch settings: debug log ", (int)dbglog, ", termination ", (int)termination);
 
-    g_azlog_debug = dbglog;
+    g_log_debug = dbglog;
     
     if (termination)
     {
-        azlog("SCSI termination is enabled");
+        logmsg("SCSI termination is enabled");
     }
     else
     {
-        azlog("NOTE: SCSI termination is disabled");
+        logmsg("NOTE: SCSI termination is disabled");
     }
 
     // Get flash chip size
@@ -94,7 +94,7 @@ void azplatform_init()
     uint8_t response_jedec[4] = {0};
     flash_do_cmd(cmd_read_jedec_id, response_jedec, 4);
     g_flash_chip_size = (1 << response_jedec[3]);
-    azlog("Flash chip size: ", (int)(g_flash_chip_size / 1024), " kB");
+    logmsg("Flash chip size: ", (int)(g_flash_chip_size / 1024), " kB");
 
     // SD card pins
     // Card is used in SDIO mode for main program, and in SPI mode for crash handler & bootloader.
@@ -152,17 +152,17 @@ static bool read_initiator_dip_switch()
 }
 
 // late_init() only runs in main application, SCSI not needed in bootloader
-void azplatform_late_init()
+void platform_late_init()
 {
     if (read_initiator_dip_switch())
     {
         g_scsi_initiator = true;
-        azlog("SCSI initiator mode selected by DIP switch, expecting SCSI disks on the bus");
+        logmsg("SCSI initiator mode selected by DIP switch, expecting SCSI disks on the bus");
     }
     else
     {
         g_scsi_initiator = false;
-        azlog("SCSI target/disk mode selected by DIP switch, acting as a SCSI disk");
+        logmsg("SCSI target/disk mode selected by DIP switch, acting as a SCSI disk");
     }
 
     /* Initialize SCSI pins to required modes.
@@ -230,16 +230,16 @@ void azplatform_late_init()
     }
 }
 
-bool azplatform_is_initiator_mode_enabled()
+bool platform_is_initiator_mode_enabled()
 {
     return g_scsi_initiator;
 }
 
-void azplatform_disable_led(void)
+void platform_disable_led(void)
 {   
     //        pin      function       pup   pdown  out    state fast
     gpio_conf(LED_PIN, GPIO_FUNC_SIO, false,false, false, false, false);
-    azlog("Disabling status LED");
+    logmsg("Disabling status LED");
 }
 
 /*****************************************/
@@ -249,9 +249,9 @@ void azplatform_disable_led(void)
 extern SdFs SD;
 extern uint32_t __StackTop;
 
-void azplatform_emergency_log_save()
+void platform_emergency_log_save()
 {
-    azplatform_set_sd_callback(NULL, NULL);
+    platform_set_sd_callback(NULL, NULL);
 
     SD.begin(SD_CONFIG_CRASH);
     FsFile crashfile = SD.open(CRASHFILE, O_WRONLY | O_CREAT | O_TRUNC);
@@ -266,32 +266,32 @@ void azplatform_emergency_log_save()
     }
 
     uint32_t startpos = 0;
-    crashfile.write(azlog_get_buffer(&startpos));
-    crashfile.write(azlog_get_buffer(&startpos));
+    crashfile.write(log_get_buffer(&startpos));
+    crashfile.write(log_get_buffer(&startpos));
     crashfile.flush();
     crashfile.close();
 }
 
 void mbed_error_hook(const mbed_error_ctx * error_context)
 {
-    azlog("--------------");
-    azlog("CRASH!");
-    azlog("Platform: ", g_azplatform_name);
-    azlog("FW Version: ", g_azlog_firmwareversion);
-    azlog("error_status: ", (uint32_t)error_context->error_status);
-    azlog("error_address: ", error_context->error_address);
-    azlog("error_value: ", error_context->error_value);
+    logmsg("--------------");
+    logmsg("CRASH!");
+    logmsg("Platform: ", g_platform_name);
+    logmsg("FW Version: ", g_log_firmwareversion);
+    logmsg("error_status: ", (uint32_t)error_context->error_status);
+    logmsg("error_address: ", error_context->error_address);
+    logmsg("error_value: ", error_context->error_value);
 
     uint32_t *p = (uint32_t*)((uint32_t)error_context->thread_current_sp & ~3);
     for (int i = 0; i < 8; i++)
     {
         if (p == &__StackTop) break; // End of stack
 
-        azlog("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
+        logmsg("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
         p += 4;
     }
 
-    azplatform_emergency_log_save();
+    platform_emergency_log_save();
 
     while (1)
     {
@@ -318,7 +318,7 @@ void mbed_error_hook(const mbed_error_ctx * error_context)
 /*****************************************/
 
 // This function is called for every log message.
-void azplatform_log(const char *s)
+void platform_log(const char *s)
 {
     if (g_uart_initialized)
     {
@@ -337,16 +337,16 @@ static void watchdog_callback(unsigned alarm_num)
     {
         if (!scsiDev.resetFlag || !g_scsiHostPhyReset)
         {
-            azlog("--------------");
-            azlog("WATCHDOG TIMEOUT, attempting bus reset");
-            azlog("GPIO states: out ", sio_hw->gpio_out, " oe ", sio_hw->gpio_oe, " in ", sio_hw->gpio_in);
+            logmsg("--------------");
+            logmsg("WATCHDOG TIMEOUT, attempting bus reset");
+            logmsg("GPIO states: out ", sio_hw->gpio_out, " oe ", sio_hw->gpio_oe, " in ", sio_hw->gpio_in);
 
             uint32_t *p = (uint32_t*)__get_PSP();
             for (int i = 0; i < 8; i++)
             {
                 if (p == &__StackTop) break; // End of stack
 
-                azlog("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
+                logmsg("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
                 p += 4;
             }
 
@@ -356,24 +356,24 @@ static void watchdog_callback(unsigned alarm_num)
 
         if (g_watchdog_timeout <= 0)
         {
-            azlog("--------------");
-            azlog("WATCHDOG TIMEOUT!");
-            azlog("Platform: ", g_azplatform_name);
-            azlog("FW Version: ", g_azlog_firmwareversion);
-            azlog("GPIO states: out ", sio_hw->gpio_out, " oe ", sio_hw->gpio_oe, " in ", sio_hw->gpio_in);
+            logmsg("--------------");
+            logmsg("WATCHDOG TIMEOUT!");
+            logmsg("Platform: ", g_platform_name);
+            logmsg("FW Version: ", g_log_firmwareversion);
+            logmsg("GPIO states: out ", sio_hw->gpio_out, " oe ", sio_hw->gpio_oe, " in ", sio_hw->gpio_in);
 
             uint32_t *p = (uint32_t*)__get_PSP();
             for (int i = 0; i < 8; i++)
             {
                 if (p == &__StackTop) break; // End of stack
 
-                azlog("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
+                logmsg("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
                 p += 4;
             }
 
-            azplatform_emergency_log_save();
+            platform_emergency_log_save();
 
-            azplatform_boot_to_main_firmware();
+            platform_boot_to_main_firmware();
         }
     }
 
@@ -382,7 +382,7 @@ static void watchdog_callback(unsigned alarm_num)
 
 // This function can be used to periodically reset watchdog timer for crash handling.
 // It can also be left empty if the platform does not use a watchdog timer.
-void azplatform_reset_watchdog()
+void platform_reset_watchdog()
 {
     g_watchdog_timeout = WATCHDOG_CRASH_TIMEOUT;
 
@@ -399,26 +399,26 @@ void azplatform_reset_watchdog()
 /* Flash reprogramming from bootloader   */
 /*****************************************/
 
-#ifdef AZPLATFORM_BOOTLOADER_SIZE
+#ifdef PLATFORM_BOOTLOADER_SIZE
 
 extern uint32_t __real_vectors_start;
 extern uint32_t __StackTop;
 static volatile void *g_bootloader_exit_req;
 
-bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FLASH_PAGE_SIZE])
+bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_PAGE_SIZE])
 {
-    if (offset == AZPLATFORM_BOOTLOADER_SIZE)
+    if (offset == PLATFORM_BOOTLOADER_SIZE)
     {
         if (buffer[3] != 0x20 || buffer[7] != 0x10)
         {
-            azlog("Invalid firmware file, starts with: ", bytearray(buffer, 16));
+            logmsg("Invalid firmware file, starts with: ", bytearray(buffer, 16));
             return false;
         }
     }
 
-    azdbg("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
-    assert(offset % AZPLATFORM_FLASH_PAGE_SIZE == 0);
-    assert(offset >= AZPLATFORM_BOOTLOADER_SIZE);
+    dbgmsg("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
+    assert(offset % PLATFORM_FLASH_PAGE_SIZE == 0);
+    assert(offset >= PLATFORM_BOOTLOADER_SIZE);
 
     // Avoid any mbed timer interrupts triggering during the flashing.
     __disable_irq();
@@ -431,11 +431,11 @@ bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FL
     // flashing, and again after reset to main firmware.
     xip_ctrl_hw->ctrl = 0;
 
-    flash_range_erase(offset, AZPLATFORM_FLASH_PAGE_SIZE);
-    flash_range_program(offset, buffer, AZPLATFORM_FLASH_PAGE_SIZE);
+    flash_range_erase(offset, PLATFORM_FLASH_PAGE_SIZE);
+    flash_range_program(offset, buffer, PLATFORM_FLASH_PAGE_SIZE);
 
     uint32_t *buf32 = (uint32_t*)buffer;
-    uint32_t num_words = AZPLATFORM_FLASH_PAGE_SIZE / 4;
+    uint32_t num_words = PLATFORM_FLASH_PAGE_SIZE / 4;
     for (int i = 0; i < num_words; i++)
     {
         uint32_t expected = buf32[i];
@@ -443,7 +443,7 @@ bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FL
 
         if (actual != expected)
         {
-            azlog("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
+            logmsg("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
             return false;
         }
     }
@@ -453,7 +453,7 @@ bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FL
     return true;
 }
 
-void azplatform_boot_to_main_firmware()
+void platform_boot_to_main_firmware()
 {
     // To ensure that the system state is reset properly, we perform
     // a SYSRESETREQ and jump straight from the reset vector to main application.
@@ -468,7 +468,7 @@ void btldr_reset_handler()
     if (g_bootloader_exit_req == &g_bootloader_exit_req)
     {
         // Boot to main application
-        application_base = (uint32_t*)(XIP_BASE + AZPLATFORM_BOOTLOADER_SIZE);
+        application_base = (uint32_t*)(XIP_BASE + PLATFORM_BOOTLOADER_SIZE);
     }
 
     SCB->VTOR = (uint32_t)application_base;
@@ -494,7 +494,7 @@ const void * btldr_vectors[2] = {&__StackTop, (void*)&btldr_reset_handler};
 // Reserve up to 352 kB for firmware.
 #define ROMDRIVE_OFFSET (352 * 1024)
 
-uint32_t azplatform_get_romdrive_maxsize()
+uint32_t platform_get_romdrive_maxsize()
 {
     if (g_flash_chip_size >= ROMDRIVE_OFFSET)
     {
@@ -507,7 +507,7 @@ uint32_t azplatform_get_romdrive_maxsize()
     }
 }
 
-bool azplatform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count)
+bool platform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count)
 {
     xip_ctrl_hw->stream_ctr = 0;
 
@@ -520,7 +520,7 @@ bool azplatform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count)
     xip_ctrl_hw->stream_ctr = count / 4;
 
     // Transfer happens in multiples of 4 bytes
-    assert(start < azplatform_get_romdrive_maxsize());
+    assert(start < platform_get_romdrive_maxsize());
     assert((count & 3) == 0);
     assert((((uint32_t)dest) & 3) == 0);
 
@@ -538,10 +538,10 @@ bool azplatform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count)
     return true;
 }
 
-bool azplatform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count)
+bool platform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count)
 {
-    assert(start < azplatform_get_romdrive_maxsize());
-    assert((count % AZPLATFORM_ROMDRIVE_PAGE_SIZE) == 0);
+    assert(start < platform_get_romdrive_maxsize());
+    assert((count % PLATFORM_ROMDRIVE_PAGE_SIZE) == 0);
 
     __disable_irq();
     flash_range_erase(start + ROMDRIVE_OFFSET, count);
@@ -658,7 +658,7 @@ public:
         for (int i = 0; i < size; i++)
         {
             char buf[2] = {((const char*)buffer)[i], 0};
-            azlog_raw(buf);
+            log_raw(buf);
         }
         return size;
     }

+ 18 - 18
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.h

@@ -12,7 +12,7 @@ extern "C" {
 #endif
 
 /* These are used in debug output and default SCSI strings */
-extern const char *g_azplatform_name;
+extern const char *g_platform_name;
 #define PLATFORM_NAME "ZuluSCSI RP2040"
 #define PLATFORM_REVISION "2.0"
 #define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_10
@@ -29,8 +29,8 @@ extern const char *g_azplatform_name;
 
 // Debug logging function, can be used to print to e.g. serial port.
 // May get called from interrupt handlers.
-void azplatform_log(const char *s);
-void azplatform_emergency_log_save();
+void platform_log(const char *s);
+void platform_emergency_log_save();
 
 // Timing and delay functions.
 // Arduino platform already provides these
@@ -50,46 +50,46 @@ static inline void delay_100ns()
 }
 
 // Initialize SD card and GPIO configuration
-void azplatform_init();
+void platform_init();
 
 // Initialization for main application, not used for bootloader
-void azplatform_late_init();
+void platform_late_init();
 
 // Disable the status LED
-void azplatform_disable_led(void);
+void platform_disable_led(void);
 
 // Query whether initiator mode is enabled on targets with PLATFORM_HAS_INITIATOR_MODE
-bool azplatform_is_initiator_mode_enabled();
+bool platform_is_initiator_mode_enabled();
 
 // Setup soft watchdog if supported
-void azplatform_reset_watchdog();
+void platform_reset_watchdog();
 
 // Set callback that will be called during data transfer to/from SD card.
 // This can be used to implement simultaneous transfer to SCSI bus.
 typedef void (*sd_callback_t)(uint32_t bytes_complete);
-void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
+void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
 
 // Reprogram firmware in main program area.
 #ifndef RP2040_DISABLE_BOOTLOADER
-#define AZPLATFORM_BOOTLOADER_SIZE (128 * 1024)
-#define AZPLATFORM_FLASH_TOTAL_SIZE (1024 * 1024)
-#define AZPLATFORM_FLASH_PAGE_SIZE 4096
-bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FLASH_PAGE_SIZE]);
-void azplatform_boot_to_main_firmware();
+#define PLATFORM_BOOTLOADER_SIZE (128 * 1024)
+#define PLATFORM_FLASH_TOTAL_SIZE (1024 * 1024)
+#define PLATFORM_FLASH_PAGE_SIZE 4096
+bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_PAGE_SIZE]);
+void platform_boot_to_main_firmware();
 #endif
 
 // ROM drive in the unused external flash area
 #ifndef RP2040_DISABLE_ROMDRIVE
 #define PLATFORM_HAS_ROM_DRIVE 1
 // Check maximum available space for ROM drive in bytes
-uint32_t azplatform_get_romdrive_maxsize();
+uint32_t platform_get_romdrive_maxsize();
 
 // Read ROM drive area
-bool azplatform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count);
+bool platform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count);
 
 // Reprogram ROM drive area
-#define AZPLATFORM_ROMDRIVE_PAGE_SIZE 4096
-bool azplatform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count);
+#define PLATFORM_ROMDRIVE_PAGE_SIZE 4096
+bool platform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count);
 #endif
 
 // Parity lookup tables for write and read from SCSI bus.

+ 16 - 16
lib/ZuluSCSI_platform_RP2040/rp2040_sdio.cpp

@@ -134,7 +134,7 @@ uint64_t sdio_crc16_4bit_checksum(uint32_t *data, uint32_t num_words)
 
 static void sdio_send_command(uint8_t command, uint32_t arg, uint8_t response_bits)
 {
-    // azdbg("SDIO Command: ", (int)command, " arg ", arg);
+    // dbgmsg("SDIO Command: ", (int)command, " arg ", arg);
 
     // Format the arguments in the way expected by the PIO code.
     uint32_t word0 =
@@ -183,7 +183,7 @@ sdio_status_t rp2040_sdio_command_R1(uint8_t command, uint32_t arg, uint32_t *re
         {
             if (command != 8) // Don't log for missing SD card
             {
-                azdbg("Timeout waiting for response in rp2040_sdio_command_R1(", (int)command, "), ",
+                dbgmsg("Timeout waiting for response in rp2040_sdio_command_R1(", (int)command, "), ",
                     "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_CMD_SM) - (int)g_sdio.pio_cmd_clk_offset,
                     " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_CMD_SM),
                     " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_CMD_SM));
@@ -201,7 +201,7 @@ sdio_status_t rp2040_sdio_command_R1(uint8_t command, uint32_t arg, uint32_t *re
         // Read out response packet
         uint32_t resp0 = pio_sm_get(SDIO_PIO, SDIO_CMD_SM);
         uint32_t resp1 = pio_sm_get(SDIO_PIO, SDIO_CMD_SM);
-        // azdbg("SDIO R1 response: ", resp0, " ", resp1);
+        // dbgmsg("SDIO R1 response: ", resp0, " ", resp1);
 
         // Calculate response checksum
         uint8_t crc = 0;
@@ -214,14 +214,14 @@ sdio_status_t rp2040_sdio_command_R1(uint8_t command, uint32_t arg, uint32_t *re
         uint8_t actual_crc = ((resp1 >> 0) & 0xFE);
         if (crc != actual_crc)
         {
-            azdbg("rp2040_sdio_command_R1(", (int)command, "): CRC error, calculated ", crc, " packet has ", actual_crc);
+            dbgmsg("rp2040_sdio_command_R1(", (int)command, "): CRC error, calculated ", crc, " packet has ", actual_crc);
             return SDIO_ERR_RESPONSE_CRC;
         }
 
         uint8_t response_cmd = ((resp0 >> 24) & 0xFF);
         if (response_cmd != command && command != 41)
         {
-            azdbg("rp2040_sdio_command_R1(", (int)command, "): received reply for ", (int)response_cmd);
+            dbgmsg("rp2040_sdio_command_R1(", (int)command, "): received reply for ", (int)response_cmd);
             return SDIO_ERR_RESPONSE_CODE;
         }
 
@@ -255,7 +255,7 @@ sdio_status_t rp2040_sdio_command_R2(uint8_t command, uint32_t arg, uint8_t resp
     {
         if ((uint32_t)(millis() - start) > 2)
         {
-            azdbg("Timeout waiting for response in rp2040_sdio_command_R2(", (int)command, "), ",
+            dbgmsg("Timeout waiting for response in rp2040_sdio_command_R2(", (int)command, "), ",
                   "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_CMD_SM) - (int)g_sdio.pio_cmd_clk_offset,
                   " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_CMD_SM),
                   " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_CMD_SM));
@@ -298,14 +298,14 @@ sdio_status_t rp2040_sdio_command_R2(uint8_t command, uint32_t arg, uint8_t resp
     uint8_t actual_crc = response[15] & 0xFE;
     if (crc != actual_crc)
     {
-        azdbg("rp2040_sdio_command_R2(", (int)command, "): CRC error, calculated ", crc, " packet has ", actual_crc);
+        dbgmsg("rp2040_sdio_command_R2(", (int)command, "): CRC error, calculated ", crc, " packet has ", actual_crc);
         return SDIO_ERR_RESPONSE_CRC;
     }
 
     uint8_t response_cmd = ((response_buf[0] >> 24) & 0xFF);
     if (response_cmd != 0x3F)
     {
-        azdbg("rp2040_sdio_command_R2(", (int)command, "): Expected reply code 0x3F");
+        dbgmsg("rp2040_sdio_command_R2(", (int)command, "): Expected reply code 0x3F");
         return SDIO_ERR_RESPONSE_CODE;
     }
 
@@ -323,7 +323,7 @@ sdio_status_t rp2040_sdio_command_R3(uint8_t command, uint32_t arg, uint32_t *re
     {
         if ((uint32_t)(millis() - start) > 2)
         {
-            azdbg("Timeout waiting for response in rp2040_sdio_command_R3(", (int)command, "), ",
+            dbgmsg("Timeout waiting for response in rp2040_sdio_command_R3(", (int)command, "), ",
                   "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_CMD_SM) - (int)g_sdio.pio_cmd_clk_offset,
                   " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_CMD_SM),
                   " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_CMD_SM));
@@ -339,7 +339,7 @@ sdio_status_t rp2040_sdio_command_R3(uint8_t command, uint32_t arg, uint32_t *re
     uint32_t resp0 = pio_sm_get(SDIO_PIO, SDIO_CMD_SM);
     uint32_t resp1 = pio_sm_get(SDIO_PIO, SDIO_CMD_SM);
     *response = ((resp0 & 0xFFFFFF) << 8) | ((resp1 >> 8) & 0xFF);
-    // azdbg("SDIO R3 response: ", resp0, " ", resp1);
+    // dbgmsg("SDIO R3 response: ", resp0, " ", resp1);
 
     return SDIO_OK;
 }
@@ -432,7 +432,7 @@ static void sdio_verify_rx_checksums(uint32_t maxcount)
             g_sdio.checksum_errors++;
             if (g_sdio.checksum_errors == 1)
             {
-                azlog("SDIO checksum error in reception: block ", blockidx,
+                logmsg("SDIO checksum error in reception: block ", blockidx,
                       " calculated ", checksum, " expected ", expected);
             }
         }
@@ -482,7 +482,7 @@ sdio_status_t rp2040_sdio_rx_poll(uint32_t *bytes_complete)
     }
     else if ((uint32_t)(millis() - g_sdio.transfer_start_time) > 1000)
     {
-        azdbg("rp2040_sdio_rx_poll() timeout, "
+        dbgmsg("rp2040_sdio_rx_poll() timeout, "
             "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_DATA_SM) - (int)g_sdio.pio_data_rx_offset,
             " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_DATA_SM),
             " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_DATA_SM),
@@ -604,17 +604,17 @@ sdio_status_t check_sdio_write_response(uint32_t card_response)
     }
     else if (wr_status == 5)
     {
-        azlog("SDIO card reports write CRC error, status ", card_response);
+        logmsg("SDIO card reports write CRC error, status ", card_response);
         return SDIO_ERR_WRITE_CRC;    
     }
     else if (wr_status == 6)
     {
-        azlog("SDIO card reports write failure, status ", card_response);
+        logmsg("SDIO card reports write failure, status ", card_response);
         return SDIO_ERR_WRITE_FAIL;    
     }
     else
     {
-        azlog("SDIO card reports unknown write status ", card_response);
+        logmsg("SDIO card reports unknown write status ", card_response);
         return SDIO_ERR_WRITE_FAIL;    
     }
 }
@@ -704,7 +704,7 @@ sdio_status_t rp2040_sdio_tx_poll(uint32_t *bytes_complete)
     }
     else if ((uint32_t)(millis() - g_sdio.transfer_start_time) > 1000)
     {
-        azdbg("rp2040_sdio_tx_poll() timeout, "
+        dbgmsg("rp2040_sdio_tx_poll() timeout, "
             "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_DATA_SM) - (int)g_sdio.pio_data_tx_offset,
             " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_DATA_SM),
             " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_DATA_SM),

+ 5 - 5
lib/ZuluSCSI_platform_RP2040/scsiHostPhy.cpp

@@ -44,7 +44,7 @@ bool scsiHostPhySelect(int target_id)
 
         if (SCSI_IN_DATA() != 0)
         {
-            azdbg("scsiHostPhySelect: bus is busy");
+            dbgmsg("scsiHostPhySelect: bus is busy");
             scsiLogInitiatorPhaseChange(BUS_FREE);
             SCSI_RELEASE_OUTPUTS();
             return false;
@@ -53,7 +53,7 @@ bool scsiHostPhySelect(int target_id)
 
     // Selection phase
     scsiLogInitiatorPhaseChange(SELECTION);
-    azdbg("------ SELECTING ", target_id);
+    dbgmsg("------ SELECTING ", target_id);
     SCSI_OUT(SEL, 1);
     delayMicroseconds(5);
     SCSI_OUT_DATA(1 << target_id);
@@ -179,7 +179,7 @@ static inline uint8_t scsiHostReadOneByte(int* parityError)
 
     if (parityError && r != (g_scsi_parity_lookup[r & 0xFF] ^ SCSI_IO_DATA_MASK))
     {
-        azlog("Parity error in scsiReadOneByte(): ", (uint32_t)r);
+        logmsg("Parity error in scsiReadOneByte(): ", (uint32_t)r);
         *parityError = 1;
     }
 
@@ -200,7 +200,7 @@ uint32_t scsiHostWrite(const uint8_t *data, uint32_t count)
             if (g_scsiHostPhyReset || SCSI_IN(IO) || SCSI_IN(CD) != cd_start || SCSI_IN(MSG) != msg_start)
             {
                 // Target switched out of DATA_OUT mode
-                azlog("scsiHostWrite: sent ", (int)i, " bytes, expected ", (int)count);
+                logmsg("scsiHostWrite: sent ", (int)i, " bytes, expected ", (int)count);
                 return i;
             }
         }
@@ -251,7 +251,7 @@ uint32_t scsiHostRead(uint8_t *data, uint32_t count)
     {
         if (count < fullcount)
         {
-            azlog("scsiHostRead: received ", (int)count, " bytes, expected ", (int)fullcount);
+            logmsg("scsiHostRead: received ", (int)count, " bytes, expected ", (int)fullcount);
         }
 
         return count;

+ 2 - 2
lib/ZuluSCSI_platform_RP2040/scsiPhy.cpp

@@ -107,7 +107,7 @@ static void scsi_rst_assert_interrupt()
 
     if (rst1 && rst2)
     {
-        azdbg("BUS RESET");
+        dbgmsg("BUS RESET");
         scsiDev.resetFlag = 1;
     }
 }
@@ -337,7 +337,7 @@ static inline uint8_t scsiReadOneByte(int* parityError)
 
     if (parityError && r != (g_scsi_parity_lookup[r & 0xFF] ^ SCSI_IO_DATA_MASK))
     {
-        azlog("Parity error in scsiReadOneByte(): ", (uint32_t)r);
+        logmsg("Parity error in scsiReadOneByte(): ", (uint32_t)r);
         *parityError = 1;
     }
 

+ 1 - 1
lib/ZuluSCSI_platform_RP2040/scsi_accel_host.cpp

@@ -110,7 +110,7 @@ uint32_t scsi_accel_host_read(uint8_t *buf, uint32_t count, int *parityError, vo
     uint8_t byte1 = ~(paritycheck >> 16);
     if (paritycheck != ((g_scsi_parity_lookup[byte1] << 16) | g_scsi_parity_lookup[byte0]))
     {
-        azlog("Parity error in scsi_accel_host_read(): ", paritycheck);
+        logmsg("Parity error in scsi_accel_host_read(): ", paritycheck);
         *parityError = 1;
     }
 

+ 4 - 4
lib/ZuluSCSI_platform_RP2040/scsi_accel_rp2040.cpp

@@ -345,7 +345,7 @@ static void scsi_accel_rp2040_stopWrite(volatile int *resetFlag)
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            azlog("scsi_accel_rp2040_stopWrite() timeout, FIFO levels ",
+            logmsg("scsi_accel_rp2040_stopWrite() timeout, FIFO levels ",
                 (int)pio_sm_get_tx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM), " ",
                 (int)pio_sm_get_rx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM), " PC ",
                 (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_DATA_SM));
@@ -374,7 +374,7 @@ void scsi_accel_rp2040_finishWrite(volatile int *resetFlag)
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            azlog("scsi_accel_rp2040_finishWrite() timeout,"
+            logmsg("scsi_accel_rp2040_finishWrite() timeout,"
              " state: ", (int)g_scsi_dma_state, " ", (int)g_scsi_dma.dma_bytes, "/", (int)g_scsi_dma.app_bytes, ", ", (int)g_scsi_dma.next_app_bytes,
              " PIO PC: ", (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_DATA_SM), " ", (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_SYNC_SM),
              " PIO FIFO: ", (int)pio_sm_get_tx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM), " ", (int)pio_sm_get_tx_fifo_level(SCSI_DMA_PIO, SCSI_SYNC_SM),
@@ -666,7 +666,7 @@ void scsi_accel_rp2040_finishRead(const uint8_t *data, uint32_t count, int *pari
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            azlog("scsi_accel_rp2040_finishRead timeout,"
+            logmsg("scsi_accel_rp2040_finishRead timeout,"
              " state: ", (int)g_scsi_dma_state, " ", (int)g_scsi_dma.dma_bytes, "/", (int)g_scsi_dma.app_bytes, ", ", (int)g_scsi_dma.next_app_bytes,
              " PIO PC: ", (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_DATA_SM), " ", (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_SYNC_SM),
              " PIO FIFO: ", (int)pio_sm_get_rx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM), " ", (int)pio_sm_get_tx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM),
@@ -686,7 +686,7 @@ void scsi_accel_rp2040_finishRead(const uint8_t *data, uint32_t count, int *pari
     // Check if any parity errors have been detected during the transfer so far
     if (parityError != NULL && (SCSI_DMA_PIO->irq & 1))
     {
-        azdbg("scsi_accel_rp2040_finishRead(", bytearray(data, count), ") detected parity error");
+        dbgmsg("scsi_accel_rp2040_finishRead(", bytearray(data, count), ") detected parity error");
         *parityError = true;
     }
 }

+ 24 - 24
lib/ZuluSCSI_platform_RP2040/sd_card_sdio.cpp

@@ -23,7 +23,7 @@ static uint32_t g_sdio_sector_count;
 static bool logSDError(int line)
 {
     g_sdio_error_line = line;
-    azlog("SDIO SD card error on line ", line, ", error code ", (int)g_sdio_error);
+    logmsg("SDIO SD card error on line ", line, ", error code ", (int)g_sdio_error);
     return false;
 }
 
@@ -33,7 +33,7 @@ static const uint8_t *m_stream_buffer;
 static uint32_t m_stream_count;
 static uint32_t m_stream_count_start;
 
-void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
+void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
 {
     m_stream_callback = func;
     m_stream_buffer = buffer;
@@ -54,7 +54,7 @@ static sd_callback_t get_stream_callback(const uint8_t *buf, uint32_t count, con
         }
         else
         {
-            azdbg("SD card ", accesstype, "(", (int)sector,
+            dbgmsg("SD card ", accesstype, "(", (int)sector,
                   ") slow transfer, buffer", (uint32_t)buf, " vs. ", (uint32_t)(m_stream_buffer + m_stream_count));
             return NULL;
         }
@@ -87,7 +87,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
 
     if (reply != 0x1AA || status != SDIO_OK)
     {
-        // azdbg("SDIO not responding to CMD8 SEND_IF_COND, status ", (int)status, " reply ", reply);
+        // dbgmsg("SDIO not responding to CMD8 SEND_IF_COND, status ", (int)status, " reply ", reply);
         return false;
     }
 
@@ -103,7 +103,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
 
         if ((uint32_t)(millis() - start) > 1000)
         {
-            azlog("SDIO card initialization timeout");
+            logmsg("SDIO card initialization timeout");
             return false;
         }
     } while (!(g_sdio_ocr & (1 << 31)));
@@ -111,21 +111,21 @@ bool SdioCard::begin(SdioConfig sdioConfig)
     // Get CID
     if (!checkReturnOk(rp2040_sdio_command_R2(CMD2, 0, (uint8_t*)&g_sdio_cid)))
     {
-        azdbg("SDIO failed to read CID");
+        dbgmsg("SDIO failed to read CID");
         return false;
     }
 
     // Get relative card address
     if (!checkReturnOk(rp2040_sdio_command_R1(CMD3, 0, &g_sdio_rca)))
     {
-        azdbg("SDIO failed to get RCA");
+        dbgmsg("SDIO failed to get RCA");
         return false;
     }
 
     // Get CSD
     if (!checkReturnOk(rp2040_sdio_command_R2(CMD9, g_sdio_rca, (uint8_t*)&g_sdio_csd)))
     {
-        azdbg("SDIO failed to read CSD");
+        dbgmsg("SDIO failed to read CSD");
         return false;
     }
 
@@ -134,7 +134,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
     // Select card
     if (!checkReturnOk(rp2040_sdio_command_R1(CMD7, g_sdio_rca, &reply)))
     {
-        azdbg("SDIO failed to select card");
+        dbgmsg("SDIO failed to select card");
         return false;
     }
 
@@ -142,7 +142,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
     if (!checkReturnOk(rp2040_sdio_command_R1(CMD55, g_sdio_rca, &reply)) ||
         !checkReturnOk(rp2040_sdio_command_R1(ACMD6, 2, &reply)))
     {
-        azdbg("SDIO failed to set bus width");
+        dbgmsg("SDIO failed to set bus width");
         return false;
     }
 
@@ -198,19 +198,19 @@ bool SdioCard::readOCR(uint32_t* ocr)
 
 bool SdioCard::readData(uint8_t* dst)
 {
-    azlog("SdioCard::readData() called but not implemented!");
+    logmsg("SdioCard::readData() called but not implemented!");
     return false;
 }
 
 bool SdioCard::readStart(uint32_t sector)
 {
-    azlog("SdioCard::readStart() called but not implemented!");
+    logmsg("SdioCard::readStart() called but not implemented!");
     return false;
 }
 
 bool SdioCard::readStop()
 {
-    azlog("SdioCard::readStop() called but not implemented!");
+    logmsg("SdioCard::readStop() called but not implemented!");
     return false;
 }
 
@@ -252,7 +252,7 @@ bool SdioCard::stopTransmission(bool blocking)
         }
         if (isBusy())
         {
-            azlog("SdioCard::stopTransmission() timeout");
+            logmsg("SdioCard::stopTransmission() timeout");
             return false;
         }
         else
@@ -277,35 +277,35 @@ uint8_t SdioCard::type() const
 
 bool SdioCard::writeData(const uint8_t* src)
 {
-    azlog("SdioCard::writeData() called but not implemented!");
+    logmsg("SdioCard::writeData() called but not implemented!");
     return false;
 }
 
 bool SdioCard::writeStart(uint32_t sector)
 {
-    azlog("SdioCard::writeStart() called but not implemented!");
+    logmsg("SdioCard::writeStart() called but not implemented!");
     return false;
 }
 
 bool SdioCard::writeStop()
 {
-    azlog("SdioCard::writeStop() called but not implemented!");
+    logmsg("SdioCard::writeStop() called but not implemented!");
     return false;
 }
 
 bool SdioCard::erase(uint32_t firstSector, uint32_t lastSector)
 {
-    azlog("SdioCard::erase() not implemented");
+    logmsg("SdioCard::erase() not implemented");
     return false;
 }
 
 bool SdioCard::cardCMD6(uint32_t arg, uint8_t* status) {
-    azlog("SdioCard::cardCMD6() not implemented");
+    logmsg("SdioCard::cardCMD6() not implemented");
     return false;
 }
 
 bool SdioCard::readSCR(scr_t* scr) {
-    azlog("SdioCard::readSCR() not implemented");
+    logmsg("SdioCard::readSCR() not implemented");
     return false;
 }
 
@@ -343,7 +343,7 @@ bool SdioCard::writeSector(uint32_t sector, const uint8_t* src)
 
     if (g_sdio_error != SDIO_OK)
     {
-        azlog("SdioCard::writeSector(", sector, ") failed: ", (int)g_sdio_error);
+        logmsg("SdioCard::writeSector(", sector, ") failed: ", (int)g_sdio_error);
     }
 
     return g_sdio_error == SDIO_OK;
@@ -388,7 +388,7 @@ bool SdioCard::writeSectors(uint32_t sector, const uint8_t* src, size_t n)
 
     if (g_sdio_error != SDIO_OK)
     {
-        azlog("SdioCard::writeSectors(", sector, ",...,", (int)n, ") failed: ", (int)g_sdio_error);
+        logmsg("SdioCard::writeSectors(", sector, ",...,", (int)n, ") failed: ", (int)g_sdio_error);
         stopTransmission(true);
         return false;
     }
@@ -429,7 +429,7 @@ bool SdioCard::readSector(uint32_t sector, uint8_t* dst)
 
     if (g_sdio_error != SDIO_OK)
     {
-        azlog("SdioCard::readSector(", sector, ") failed: ", (int)g_sdio_error);
+        logmsg("SdioCard::readSector(", sector, ") failed: ", (int)g_sdio_error);
     }
 
     if (dst != real_dst)
@@ -477,7 +477,7 @@ bool SdioCard::readSectors(uint32_t sector, uint8_t* dst, size_t n)
 
     if (g_sdio_error != SDIO_OK)
     {
-        azlog("SdioCard::readSectors(", sector, ",...,", (int)n, ") failed: ", (int)g_sdio_error);
+        logmsg("SdioCard::readSectors(", sector, ",...,", (int)n, ") failed: ", (int)g_sdio_error);
         stopTransmission(true);
         return false;
     }

+ 1 - 1
lib/ZuluSCSI_platform_RP2040/sd_card_spi.cpp

@@ -75,7 +75,7 @@ void sdCsWrite(SdCsPin_t pin, bool level)
 RP2040SPIDriver g_sd_spi_port;
 SdSpiConfig g_sd_spi_config(0, DEDICATED_SPI, SD_SCK_MHZ(25), &g_sd_spi_port);
 
-void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
+void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
 {
 }
 

+ 1 - 1
lib/ZuluSCSI_platform_template/README.md

@@ -50,7 +50,7 @@ To implement this, one or both of them must be able to execute transfers in back
 On most platforms this is possible for SD card access.
 The SCSI handshake mechanism is harder to implement using DMA.
 
-To implement parallelism with SD card DMA, implement `azplatform_set_sd_callback(func, buffer)`.
+To implement parallelism with SD card DMA, implement `platform_set_sd_callback(func, buffer)`.
 It sets a callback function which should be called by the SD card driver to report how many bytes have
 been transferred to/from `buffer` so far. The SD card driver should call this function in a loop while
 it is waiting for SD card transfer to finish. The code in `ZuluSCSI_disk.cpp` will implement the callback

+ 7 - 7
lib/ZuluSCSI_platform_template/ZuluSCSI_platform.cpp

@@ -7,27 +7,27 @@
 
 extern "C" {
 
-const char *g_azplatform_name = PLATFORM_NAME;
+const char *g_platform_name = PLATFORM_NAME;
 
 /***************/
 /* GPIO init   */
 /***************/
 
-void azplatform_init()
+void platform_init()
 {
     /* Initialize SCSI and SD card pins to required modes.
      * SCSI pins should be inactive / input at this point.
      */
 }
 
-void azplatform_late_init()
+void platform_late_init()
 {
     /* This function can usually be left empty.
      * It can be used for initialization code that should not run in bootloader.
      */
 }
 
-void azplatform_disable_led(void)
+void platform_disable_led(void)
 {
     /* This function disables the LED on the ZuluSCSI board
     *  Generally by switching the pin from output to input.
@@ -42,13 +42,13 @@ void azplatform_disable_led(void)
 // This function is called for every log message.
 // It can e.g. write the log to serial port in real time.
 // It can also be left empty to use only the debug log file on SD card.
-void azplatform_log(const char *s)
+void platform_log(const char *s)
 {
 }
 
 // This function can be used to periodically reset watchdog timer for crash handling.
 // It can also be left empty if the platform does not use a watchdog timer.
-void azplatform_reset_watchdog()
+void platform_reset_watchdog()
 {
 }
 
@@ -105,7 +105,7 @@ const uint32_t g_scsi_out_byte_to_bop[256] =
  */
 SdSpiConfig g_sd_spi_config(0, DEDICATED_SPI, SD_SCK_MHZ(25));
 
-void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
+void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer)
 {
     /* This function can be left empty.
      * If the platform supports DMA for SD card transfers, this function

+ 7 - 7
lib/ZuluSCSI_platform_template/ZuluSCSI_platform.h

@@ -15,13 +15,13 @@ extern "C" {
 #endif
 
 /* These are used in debug output and default SCSI strings */
-extern const char *g_azplatform_name;
+extern const char *g_platform_name;
 #define PLATFORM_NAME "Example"
 #define PLATFORM_REVISION "1.0"
 
 // Debug logging function, can be used to print to e.g. serial port.
 // May get called from interrupt handlers.
-void azplatform_log(const char *s);
+void platform_log(const char *s);
 
 // Timing and delay functions.
 // Arduino platform already provides these
@@ -41,21 +41,21 @@ static inline void delay_100ns()
 }
 
 // Initialize SD card and GPIO configuration
-void azplatform_init();
+void platform_init();
 
 // Initialization for main application, not used for bootloader
-void azplatform_late_init();
+void platform_late_init();
 
 // Disable the status LED
-void azplatform_disable_led(void);
+void platform_disable_led(void);
 
 // Setup soft watchdog if supported
-void azplatform_reset_watchdog();
+void platform_reset_watchdog();
 
 // Set callback that will be called during data transfer to/from SD card.
 // This can be used to implement simultaneous transfer to SCSI bus.
 typedef void (*sd_callback_t)(uint32_t bytes_complete);
-void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
+void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
 
 // Below are GPIO access definitions that are used from scsiPhy.cpp.
 // The definitions shown will work for STM32 style devices, other platforms

+ 1 - 1
lib/ZuluSCSI_platform_template/scsiPhy.cpp

@@ -93,7 +93,7 @@ static void scsi_rst_assert_interrupt()
 
     if (rst1 && rst2)
     {
-        azdbg("BUS RESET");
+        dbgmsg("BUS RESET");
         scsiDev.resetFlag = 1;
     }
 }

+ 54 - 42
src/ZuluSCSI.cpp

@@ -95,15 +95,15 @@ void save_logfile(bool always = false)
   static uint32_t prev_log_pos = 0;
   static uint32_t prev_log_len = 0;
   static uint32_t prev_log_save = 0;
-  uint32_t loglen = azlog_get_buffer_len();
+  uint32_t loglen = log_get_buffer_len();
 
   if (loglen != prev_log_len && g_sdcard_present)
   {
     // When debug is off, save log at most every LOG_SAVE_INTERVAL_MS
     // When debug is on, save after every SCSI command.
-    if (always || g_azlog_debug || (LOG_SAVE_INTERVAL_MS > 0 && (uint32_t)(millis() - prev_log_save) > LOG_SAVE_INTERVAL_MS))
+    if (always || g_log_debug || (LOG_SAVE_INTERVAL_MS > 0 && (uint32_t)(millis() - prev_log_save) > LOG_SAVE_INTERVAL_MS))
     {
-      g_logfile.write(azlog_get_buffer(&prev_log_pos));
+      g_logfile.write(log_get_buffer(&prev_log_pos));
       g_logfile.flush();
       
       prev_log_len = loglen;
@@ -121,7 +121,7 @@ void init_logfile()
   g_logfile = SD.open(LOGFILE, flags);
   if (!g_logfile.isOpen())
   {
-    azlog("Failed to open log file: ", SD.sdErrorCode());
+    logmsg("Failed to open log file: ", SD.sdErrorCode());
   }
   save_logfile(true);
 
@@ -131,19 +131,19 @@ void init_logfile()
 void print_sd_info()
 {
   uint64_t size = (uint64_t)SD.vol()->clusterCount() * SD.vol()->bytesPerCluster();
-  azlog("SD card detected, FAT", (int)SD.vol()->fatType(),
+  logmsg("SD card detected, FAT", (int)SD.vol()->fatType(),
           " volume size: ", (int)(size / 1024 / 1024), " MB");
   
   cid_t sd_cid;
 
   if(SD.card()->readCID(&sd_cid))
   {
-    azlog("SD MID: ", (uint8_t)sd_cid.mid, ", OID: ", (uint8_t)sd_cid.oid[0], " ", (uint8_t)sd_cid.oid[1]);
+    logmsg("SD MID: ", (uint8_t)sd_cid.mid, ", OID: ", (uint8_t)sd_cid.oid[0], " ", (uint8_t)sd_cid.oid[1]);
     
     char sdname[6] = {sd_cid.pnm[0], sd_cid.pnm[1], sd_cid.pnm[2], sd_cid.pnm[3], sd_cid.pnm[4], 0};
-    azlog("SD Name: ", sdname);
-    azlog("SD Date: ", (int)sd_cid.mdtMonth(), "/", sd_cid.mdtYear());
-    azlog("SD Serial: ", sd_cid.psn());
+    logmsg("SD Name: ", sdname);
+    logmsg("SD Date: ", (int)sd_cid.mdtMonth(), "/", sd_cid.mdtYear());
+    logmsg("SD Serial: ", sd_cid.psn());
   }
 }
 
@@ -158,13 +158,13 @@ bool findHDDImages()
   ini_gets("SCSI", "Dir", "/", imgdir, sizeof(imgdir), CONFIGFILE);
   int dirindex = 0;
 
-  azlog("Finding HDD images in directory ", imgdir, ":");
+  logmsg("Finding HDD images in directory ", imgdir, ":");
 
   SdFile root;
   root.open(imgdir);
   if (!root.isOpen())
   {
-    azlog("Could not open directory: ", imgdir);
+    logmsg("Could not open directory: ", imgdir);
   }
 
   SdFile file;
@@ -189,11 +189,11 @@ bool findHDDImages()
 
       if (imgdir[0] != '\0')
       {
-        azlog("Finding HDD images in additional directory Dir", (int)dirindex, " = \"", imgdir, "\":");
+        logmsg("Finding HDD images in additional directory Dir", (int)dirindex, " = \"", imgdir, "\":");
         root.open(imgdir);
         if (!root.isOpen())
         {
-          azlog("-- Could not open directory: ", imgdir);
+          logmsg("-- Could not open directory: ", imgdir);
         }
         continue;
       }
@@ -214,6 +214,12 @@ bool findHDDImages()
       bool is_re = (tolower(name[0]) == 'r' && tolower(name[1]) == 'e');
       bool is_tp = (tolower(name[0]) == 't' && tolower(name[1]) == 'p');
 
+      if(strcasecmp(name, "CLEAR_ROM") == 0)
+      {
+        scsiDiskClearRomDrive();
+        continue;
+      }
+
       if (is_hd || is_cd || is_fd || is_mo || is_re || is_tp)
       {
         // Check file extension
@@ -241,7 +247,7 @@ bool findHDDImages()
 
         if (is_compressed)
         {
-          azlog("-- Ignoring compressed file ", name);
+          logmsg("-- Ignoring compressed file ", name);
           continue;
         }
 
@@ -311,9 +317,17 @@ bool findHDDImages()
         strcat(fullname, name);
 
         // Check whether this SCSI ID has been configured yet
-        if (s2s_getConfigById(id))
+        const S2S_TargetCfg* cfg = s2s_getConfigById(id);
+        if (cfg)
         {
-          azlog("-- Ignoring ", fullname, ", SCSI ID ", id, " is already in use!");
+          logmsg("-- Ignoring ", fullname, ", SCSI ID ", id, " is already in use!");
+          continue;
+        }
+
+        // Apple computers reserve ID 7, so warn the user this configuration wont work
+        if(id == 7 && cfg->quirks == S2S_CFG_QUIRKS_APPLE )
+        {
+          logmsg("-- Ignoring ", fullname, ", SCSI ID ", id, " Quirks set to Apple so can not use SCSI ID 7!");
           continue;
         }
 
@@ -329,7 +343,7 @@ bool findHDDImages()
         // Open the image file
         if (id < NUM_SCSIID && is_romdrive)
         {
-          azlog("-- Loading ROM drive from ", fullname, " for id:", id);
+          logmsg("-- Loading ROM drive from ", fullname, " for id:", id);
           imageReady = scsiDiskProgramRomDrive(fullname, id, blk, type);
           
           if (imageReady)
@@ -338,7 +352,7 @@ bool findHDDImages()
           }
         }
         else if(id < NUM_SCSIID && lun < NUM_SCSILUN) {
-          azlog("-- Opening ", fullname, " for id:", id, " lun:", lun);
+          logmsg("-- Opening ", fullname, " for id:", id, " lun:", lun);
 
           imageReady = scsiDiskOpenHDDImage(id, fullname, id, lun, blk, type);
           if(imageReady)
@@ -347,17 +361,17 @@ bool findHDDImages()
           }
           else
           {
-            azlog("---- Failed to load image");
+            logmsg("---- Failed to load image");
           }
         } else {
-          azlog("-- Invalid lun or id for image ", fullname);
+          logmsg("-- Invalid lun or id for image ", fullname);
         }
       }
     }
   }
 
   if(usedDefaultId > 0) {
-    azlog("Some images did not specify a SCSI ID. Last file will be used at ID ", usedDefaultId);
+    logmsg("Some images did not specify a SCSI ID. Last file will be used at ID ", usedDefaultId);
   }
   root.close();
 
@@ -371,7 +385,7 @@ bool findHDDImages()
     if (cfg && (cfg->scsiId & S2S_CFG_TARGET_ENABLED))
     {
       int capacity_kB = ((uint64_t)cfg->scsiSectors * cfg->bytesPerSector) / 1024;
-      azlog("SCSI ID:", (int)(cfg->scsiId & 7),
+      logmsg("SCSI ID:", (int)(cfg->scsiId & 7),
             " BlockSize:", (int)cfg->bytesPerSector,
             " Type:", (int)cfg->deviceType,
             " Quirks:", (int)cfg->quirks,
@@ -422,11 +436,11 @@ static void reinitSCSI()
 {
   if (ini_getbool("SCSI", "Debug", 0, CONFIGFILE))
   {
-    g_azlog_debug = true;
+    g_log_debug = true;
   }
 
 #ifdef PLATFORM_HAS_INITIATOR_MODE
-  if (azplatform_is_initiator_mode_enabled())
+  if (platform_is_initiator_mode_enabled())
   {
     // Initialize scsiDev to zero values even though it is not used
     scsiInit();
@@ -453,11 +467,11 @@ static void reinitSCSI()
   else
   {
 #if RAW_FALLBACK_ENABLE
-    azlog("No images found, enabling RAW fallback partition");
+    logmsg("No images found, enabling RAW fallback partition");
     scsiDiskOpenHDDImage(RAW_FALLBACK_SCSI_ID, "RAW:0:0xFFFFFFFF", RAW_FALLBACK_SCSI_ID, 0,
                          RAW_FALLBACK_BLOCKSIZE);
 #else
-    azlog("No valid image files found!");
+    logmsg("No valid image files found!");
 #endif
     blinkStatus(BLINK_ERROR_NO_IMAGES);
   }
@@ -470,24 +484,22 @@ static void reinitSCSI()
 
 extern "C" void zuluscsi_setup(void)
 {
-  azplatform_init();
-  azplatform_late_init();
+  platform_init();
+  platform_late_init();
 
   g_sdcard_present = mountSDCard();
 
   if(!g_sdcard_present)
   {
-    azlog("SD card init failed, sdErrorCode: ", (int)SD.sdErrorCode(),
+    logmsg("SD card init failed, sdErrorCode: ", (int)SD.sdErrorCode(),
            " sdErrorData: ", (int)SD.sdErrorData());
-    
-    blinkStatus(BLINK_ERROR_NO_SD_CARD);
 
     if (scsiDiskCheckRomDrive())
     {
       reinitSCSI();
       if (g_romdrive_active)
       {
-        azlog("Enabled ROM drive without SD card");
+        logmsg("Enabled ROM drive without SD card");
         return;
       }
     }
@@ -496,17 +508,17 @@ extern "C" void zuluscsi_setup(void)
     {
       blinkStatus(BLINK_ERROR_NO_SD_CARD);
       delay(1000);
-      azplatform_reset_watchdog();
+      platform_reset_watchdog();
       g_sdcard_present = mountSDCard();
     } while (!g_sdcard_present);
-    azlog("SD card init succeeded after retry");
+    logmsg("SD card init succeeded after retry");
   }
 
   if (g_sdcard_present)
   {
     if (SD.clusterCount() == 0)
     {
-      azlog("SD card without filesystem!");
+      logmsg("SD card without filesystem!");
     }
 
     print_sd_info();
@@ -514,14 +526,14 @@ extern "C" void zuluscsi_setup(void)
     reinitSCSI();
   }
 
-  azlog("Initialization complete!");
+  logmsg("Initialization complete!");
 
   if (g_sdcard_present)
   {
     init_logfile();
     if (ini_getbool("SCSI", "DisableStatusLED", false, CONFIGFILE))
     {
-      azplatform_disable_led();
+      platform_disable_led();
     }
   }
 }
@@ -530,10 +542,10 @@ extern "C" void zuluscsi_main_loop(void)
 {
   static uint32_t sd_card_check_time = 0;
 
-  azplatform_reset_watchdog();
+  platform_reset_watchdog();
   
 #ifdef PLATFORM_HAS_INITIATOR_MODE
-  if (azplatform_is_initiator_mode_enabled())
+  if (platform_is_initiator_mode_enabled())
   {
     scsiInitiatorMainLoop();
     save_logfile();
@@ -565,7 +577,7 @@ extern "C" void zuluscsi_main_loop(void)
         if (!SD.card()->readOCR(&ocr))
         {
           g_sdcard_present = false;
-          azlog("SD card removed, trying to reinit");
+          logmsg("SD card removed, trying to reinit");
         }
       }
     }
@@ -580,7 +592,7 @@ extern "C" void zuluscsi_main_loop(void)
 
       if (g_sdcard_present)
       {
-        azlog("SD card reinit succeeded");
+        logmsg("SD card reinit succeeded");
         print_sd_info();
 
         reinitSCSI();
@@ -590,7 +602,7 @@ extern "C" void zuluscsi_main_loop(void)
       {
         blinkStatus(BLINK_ERROR_NO_SD_CARD);
         delay(1000);
-        azplatform_reset_watchdog();
+        platform_reset_watchdog();
       }
     } while (!g_sdcard_present && !g_romdrive_active);
   }

+ 23 - 23
src/ZuluSCSI_bootloader.cpp

@@ -6,7 +6,7 @@
 #include <SdFat.h>
 #include <string.h>
 
-#ifdef AZPLATFORM_BOOTLOADER_SIZE
+#ifdef PLATFORM_BOOTLOADER_SIZE
 
 extern SdFs SD;
 extern FsFile g_logfile;
@@ -27,7 +27,7 @@ bool find_firmware_image(FsFile &file, char name[MAX_FILE_PATH + 1])
             strncasecmp(name + namelen - 3, "bin", 3) == 0)
         {
             root.close();
-            azlog("Found firmware file: ", name);
+            logmsg("Found firmware file: ", name);
             return true;
         }
 
@@ -40,22 +40,22 @@ bool find_firmware_image(FsFile &file, char name[MAX_FILE_PATH + 1])
 
 bool program_firmware(FsFile &file)
 {
-    uint32_t fwsize = file.size() - AZPLATFORM_BOOTLOADER_SIZE;
-    uint32_t num_pages = (fwsize + AZPLATFORM_FLASH_PAGE_SIZE - 1) / AZPLATFORM_FLASH_PAGE_SIZE;
+    uint32_t fwsize = file.size() - PLATFORM_BOOTLOADER_SIZE;
+    uint32_t num_pages = (fwsize + PLATFORM_FLASH_PAGE_SIZE - 1) / PLATFORM_FLASH_PAGE_SIZE;
 
     // Make sure the buffer is aligned to word boundary
-    static uint32_t buffer32[AZPLATFORM_FLASH_PAGE_SIZE / 4];
+    static uint32_t buffer32[PLATFORM_FLASH_PAGE_SIZE / 4];
     uint8_t *buffer = (uint8_t*)buffer32;
 
-    if (fwsize > AZPLATFORM_FLASH_TOTAL_SIZE)
+    if (fwsize > PLATFORM_FLASH_TOTAL_SIZE)
     {
-        azlog("Firmware too large: ", (int)fwsize, " flash size ", (int)AZPLATFORM_FLASH_TOTAL_SIZE);
+        logmsg("Firmware too large: ", (int)fwsize, " flash size ", (int)PLATFORM_FLASH_TOTAL_SIZE);
         return false;
     }
 
-    if (!file.seek(AZPLATFORM_BOOTLOADER_SIZE))
+    if (!file.seek(PLATFORM_BOOTLOADER_SIZE))
     {
-        azlog("Seek failed");
+        logmsg("Seek failed");
         return false;
     }
 
@@ -66,15 +66,15 @@ bool program_firmware(FsFile &file)
         else
             LED_OFF();
         
-        if (file.read(buffer, AZPLATFORM_FLASH_PAGE_SIZE) <= 0)
+        if (file.read(buffer, PLATFORM_FLASH_PAGE_SIZE) <= 0)
         {
-            azlog("Firmware file read failed on page ", i);
+            logmsg("Firmware file read failed on page ", i);
             return false;
         }
 
-        if (!azplatform_rewrite_flash_page(AZPLATFORM_BOOTLOADER_SIZE + i * AZPLATFORM_FLASH_PAGE_SIZE, buffer))
+        if (!platform_rewrite_flash_page(PLATFORM_BOOTLOADER_SIZE + i * PLATFORM_FLASH_PAGE_SIZE, buffer))
         {
-            azlog("Flash programming failed on page ", i);
+            logmsg("Flash programming failed on page ", i);
             return false;
         }
     }
@@ -103,10 +103,10 @@ static bool mountSDCard()
 extern "C"
 int bootloader_main(void)
 {
-    azplatform_init();
-    g_azlog_debug = true;
+    platform_init();
+    g_log_debug = true;
 
-    azlog("Bootloader version: " __DATE__ " " __TIME__ " " PLATFORM_NAME);
+    logmsg("Bootloader version: " __DATE__ " " __TIME__ " " PLATFORM_NAME);
 
     if (mountSDCard() || mountSDCard())
     {
@@ -116,28 +116,28 @@ int bootloader_main(void)
         {
             if (program_firmware(fwfile))
             {
-                azlog("Firmware update successful!");
+                logmsg("Firmware update successful!");
                 fwfile.close();
                 if (!SD.remove(name))
                 {
-                    azlog("Failed to remove firmware file");
+                    logmsg("Failed to remove firmware file");
                 }
             }
             else
             {
-                azlog("Firmware update failed!");
-                azplatform_emergency_log_save();
+                logmsg("Firmware update failed!");
+                platform_emergency_log_save();
             }
             
         }
     }
     else
     {
-        azlog("Bootloader SD card init failed");
+        logmsg("Bootloader SD card init failed");
     }
 
-    azlog("Bootloader continuing to main firmware");
-    azplatform_boot_to_main_firmware();
+    logmsg("Bootloader continuing to main firmware");
+    platform_boot_to_main_firmware();
 
     return 0;
 }

+ 106 - 87
src/ZuluSCSI_disk.cpp

@@ -57,10 +57,10 @@ extern "C" {
 
 #ifndef PLATFORM_HAS_ROM_DRIVE
 // Dummy defines for platforms without ROM drive support
-#define AZPLATFORM_ROMDRIVE_PAGE_SIZE 1024
-uint32_t azplatform_get_romdrive_maxsize() { return 0; }
-bool azplatform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count) { return false; }
-bool azplatform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count) { return false; }
+#define PLATFORM_ROMDRIVE_PAGE_SIZE 1024
+uint32_t platform_get_romdrive_maxsize() { return 0; }
+bool platform_read_romdrive(uint8_t *dest, uint32_t start, uint32_t count) { return false; }
+bool platform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count) { return false; }
 #endif
 
 #ifndef PLATFORM_SCSIPHY_HAS_NONBLOCKING_READ
@@ -98,7 +98,7 @@ struct romdrive_hdr_t {
 // Check if the romdrive is present
 static bool check_romdrive(romdrive_hdr_t *hdr)
 {
-    if (!azplatform_read_romdrive((uint8_t*)hdr, 0, sizeof(romdrive_hdr_t)))
+    if (!platform_read_romdrive((uint8_t*)hdr, 0, sizeof(romdrive_hdr_t)))
     {
         return false;
     }
@@ -116,31 +116,51 @@ static bool check_romdrive(romdrive_hdr_t *hdr)
     return true;
 }
 
+// Clear the drive metadata header
+bool scsiDiskClearRomDrive()
+{
+#ifndef PLATFORM_HAS_ROM_DRIVE
+    logmsg("---- Platform does not support ROM drive");
+    return false;
+#else
+    romdrive_hdr_t hdr = {0x0};
+
+    if (!platform_write_romdrive((const uint8_t*)&hdr, 0, PLATFORM_ROMDRIVE_PAGE_SIZE))
+    {
+        logmsg("-- Failed to clear ROM drive");
+        return false;
+    }
+    logmsg("-- Cleared ROM drive");
+    SD.remove("CLEAR_ROM");
+    return true;
+#endif
+}
+
 // Load an image file to romdrive
 bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S2S_CFG_TYPE type)
 {
 #ifndef PLATFORM_HAS_ROM_DRIVE
-    azlog("---- Platform does not support ROM drive");
+    logmsg("---- Platform does not support ROM drive");
     return false;
 #endif
 
     FsFile file = SD.open(filename, O_RDONLY);
     if (!file.isOpen())
     {
-        azlog("---- Failed to open: ", filename);
+        logmsg("---- Failed to open: ", filename);
         return false;
     }
 
     uint64_t filesize = file.size();
-    uint32_t maxsize = azplatform_get_romdrive_maxsize() - AZPLATFORM_ROMDRIVE_PAGE_SIZE;
+    uint32_t maxsize = platform_get_romdrive_maxsize() - PLATFORM_ROMDRIVE_PAGE_SIZE;
 
-    azlog("---- SCSI ID: ", scsi_id, " blocksize ", blocksize, " type ", (int)type);
-    azlog("---- ROM drive maximum size is ", (int)maxsize,
+    logmsg("---- SCSI ID: ", scsi_id, " blocksize ", blocksize, " type ", (int)type);
+    logmsg("---- ROM drive maximum size is ", (int)maxsize,
           " bytes, image file is ", (int)filesize, " bytes");
     
     if (filesize > maxsize)
     {
-        azlog("---- Image size exceeds ROM space, not loading");
+        logmsg("---- Image size exceeds ROM space, not loading");
         file.close();
         return false;
     }
@@ -153,15 +173,15 @@ bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S
     hdr.drivetype = type;
 
     // Program the drive metadata header
-    if (!azplatform_write_romdrive((const uint8_t*)&hdr, 0, AZPLATFORM_ROMDRIVE_PAGE_SIZE))
+    if (!platform_write_romdrive((const uint8_t*)&hdr, 0, PLATFORM_ROMDRIVE_PAGE_SIZE))
     {
-        azlog("---- Failed to program ROM drive header");
+        logmsg("---- Failed to program ROM drive header");
         file.close();
         return false;
     }
     
     // Program the drive contents
-    uint32_t pages = (filesize + AZPLATFORM_ROMDRIVE_PAGE_SIZE - 1) / AZPLATFORM_ROMDRIVE_PAGE_SIZE;
+    uint32_t pages = (filesize + PLATFORM_ROMDRIVE_PAGE_SIZE - 1) / PLATFORM_ROMDRIVE_PAGE_SIZE;
     for (uint32_t i = 0; i < pages; i++)
     {
         if (i % 2)
@@ -169,10 +189,10 @@ bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S
         else
             LED_OFF();
 
-        if (file.read(scsiDev.data, AZPLATFORM_ROMDRIVE_PAGE_SIZE) <= 0 ||
-            !azplatform_write_romdrive(scsiDev.data, (i + 1) * AZPLATFORM_ROMDRIVE_PAGE_SIZE, AZPLATFORM_ROMDRIVE_PAGE_SIZE))
+        if (file.read(scsiDev.data, PLATFORM_ROMDRIVE_PAGE_SIZE) <= 0 ||
+            !platform_write_romdrive(scsiDev.data, (i + 1) * PLATFORM_ROMDRIVE_PAGE_SIZE, PLATFORM_ROMDRIVE_PAGE_SIZE))
         {
-            azlog("---- Failed to program ROM drive page ", (int)i);
+            logmsg("---- Failed to program ROM drive page ", (int)i);
             file.close();
             return false;
         }
@@ -186,7 +206,7 @@ bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S
     strlcat(newname, filename, sizeof(newname));
     strlcat(newname, "_loaded", sizeof(newname));
     SD.rename(filename, newname);
-    azlog("---- ROM drive programming successful, image file renamed to ", newname);
+    logmsg("---- ROM drive programming successful, image file renamed to ", newname);
 
     return true;
 }
@@ -204,19 +224,19 @@ bool scsiDiskActivateRomDrive()
     return false;
 #endif
 
-    uint32_t maxsize = azplatform_get_romdrive_maxsize() - AZPLATFORM_ROMDRIVE_PAGE_SIZE;
-    azlog("-- Platform supports ROM drive up to ", (int)(maxsize / 1024), " kB");
+    uint32_t maxsize = platform_get_romdrive_maxsize() - PLATFORM_ROMDRIVE_PAGE_SIZE;
+    logmsg("-- Platform supports ROM drive up to ", (int)(maxsize / 1024), " kB");
 
     romdrive_hdr_t hdr = {};
     if (!check_romdrive(&hdr))
     {
-        azlog("---- ROM drive image not detected");
+        logmsg("---- ROM drive image not detected");
         return false;
     }
 
     if (ini_getbool("SCSI", "DisableROMDrive", 0, CONFIGFILE))
     {
-        azlog("---- ROM drive disabled in ini file, not enabling");
+        logmsg("---- ROM drive disabled in ini file, not enabling");
         return false;
     }
 
@@ -224,23 +244,23 @@ bool scsiDiskActivateRomDrive()
     if (rom_scsi_id >= 0 && rom_scsi_id <= 7)
     {
         hdr.scsi_id = rom_scsi_id;
-        azlog("---- ROM drive SCSI id overriden in ini file, changed to ", (int)hdr.scsi_id);
+        logmsg("---- ROM drive SCSI id overriden in ini file, changed to ", (int)hdr.scsi_id);
     }
 
     if (s2s_getConfigById(hdr.scsi_id))
     {
-        azlog("---- ROM drive SCSI id ", (int)hdr.scsi_id, " is already in use, not enabling");
+        logmsg("---- ROM drive SCSI id ", (int)hdr.scsi_id, " is already in use, not enabling");
         return false;
     }
 
 
 
-    azlog("---- Activating ROM drive, SCSI id ", (int)hdr.scsi_id, " size ", (int)(hdr.imagesize / 1024), " kB");
+    logmsg("---- Activating ROM drive, SCSI id ", (int)hdr.scsi_id, " size ", (int)(hdr.imagesize / 1024), " kB");
     bool status = scsiDiskOpenHDDImage(hdr.scsi_id, "ROM:", hdr.scsi_id, 0, hdr.blocksize, hdr.drivetype);
 
     if (!status)
     {
-        azlog("---- ROM drive activation failed");
+        logmsg("---- ROM drive activation failed");
         return false;
     }
     else
@@ -287,13 +307,13 @@ public:
 
             if (*endptr != ':' || *endptr2 != '\0')
             {
-                azlog("Invalid format for raw filename: ", filename);
+                logmsg("Invalid format for raw filename: ", filename);
                 return;
             }
 
             if ((scsi_block_size % SD_SECTOR_SIZE) != 0)
             {
-                azlog("SCSI block size ", (int)scsi_block_size, " is not supported for RAW partitions (must be divisible by 512 bytes)");
+                logmsg("SCSI block size ", (int)scsi_block_size, " is not supported for RAW partitions (must be divisible by 512 bytes)");
                 return;
             }
 
@@ -303,7 +323,7 @@ public:
             uint32_t sectorCount = SD.card()->sectorCount();
             if (m_endsector >= sectorCount)
             {
-                azlog("Limiting RAW image mapping to SD card sector count: ", (int)sectorCount);
+                logmsg("Limiting RAW image mapping to SD card sector count: ", (int)sectorCount);
                 m_endsector = sectorCount - 1;
             }
         }
@@ -324,7 +344,7 @@ public:
             if (m_isreadonly_attr)
             {
                 m_fsfile = SD.open(filename, O_RDONLY);
-                azlog("---- Image file is read-only, writes disabled");
+                logmsg("---- Image file is read-only, writes disabled");
             }
             else
             {
@@ -345,10 +365,9 @@ public:
                 if (end != begin + sectorcount)
                 {
                     uint32_t allocsize = end - begin + 1;
-                    azlog("---- NOTE: File ", filename, " has FAT allocated size of ", (int)allocsize, " sectors and file size of ", (int)sectorcount, " sectors");
-                    azlog("---- Due to issue #80 in ZuluSCSI version 1.0.8 and 1.0.9 the allocated size was mistakenly reported to SCSI controller.");
-                    azlog("---- If the drive was formatted using those versions, you may have problems accessing it with newer firmware.");
-                    azlog("---- The old behavior can be restored with setting  [SCSI] UseFATAllocSize = 1 in " CONFIGFILE);
+                    // Due to issue #80 in ZuluSCSI version 1.0.8 and 1.0.9 the allocated size was mistakenly reported to SCSI controller.
+                    // If the drive was formatted using those versions, you may have problems accessing it with newer firmware.
+                    // The old behavior can be restored with setting  [SCSI] UseFATAllocSize = 1 in config file.
 
                     if (ini_getbool("SCSI", "UseFATAllocSize", 0, CONFIGFILE))
                     {
@@ -478,8 +497,8 @@ public:
         {
             uint32_t sectorcount = count / SD_SECTOR_SIZE;
             assert((uint64_t)sectorcount * SD_SECTOR_SIZE == count);
-            uint32_t start = m_cursector * SD_SECTOR_SIZE + AZPLATFORM_ROMDRIVE_PAGE_SIZE;
-            if (azplatform_read_romdrive((uint8_t*)buf, start, count))
+            uint32_t start = m_cursector * SD_SECTOR_SIZE + PLATFORM_ROMDRIVE_PAGE_SIZE;
+            if (platform_read_romdrive((uint8_t*)buf, start, count))
             {
                 m_cursector += sectorcount;
                 return count;
@@ -513,12 +532,12 @@ public:
         }
         else if (m_isrom)
         {
-            azlog("ERROR: attempted to write to ROM drive");
+            logmsg("ERROR: attempted to write to ROM drive");
             return 0;
         }
         else  if (m_isreadonly_attr)
         {
-            azlog("ERROR: attempted to write to a read only image");
+            logmsg("ERROR: attempted to write to a read only image");
             return 0;
         }
         else
@@ -738,7 +757,7 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
         
         if (img.scsiSectors == 0)
         {
-            azlog("---- Error: image file ", filename, " is empty");
+            logmsg("---- Error: image file ", filename, " is empty");
             img.file.close();
             return false;
         }
@@ -750,52 +769,52 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
         }
         else if (img.file.contiguousRange(&sector_begin, &sector_end))
         {
-            azlog("---- Image file is contiguous, SD card sectors ", (int)sector_begin, " to ", (int)sector_end);
+            dbgmsg("---- Image file is contiguous, SD card sectors ", (int)sector_begin, " to ", (int)sector_end);
         }
         else
         {
-            azlog("---- WARNING: file ", filename, " is not contiguous. This will increase read latency.");
+            logmsg("---- WARNING: file ", filename, " is not contiguous. This will increase read latency.");
         }
 
         if (type == S2S_CFG_OPTICAL)
         {
-            azlog("---- Configuring as CD-ROM drive based on image name");
+            logmsg("---- Configuring as CD-ROM drive based on image name");
             img.deviceType = S2S_CFG_OPTICAL;
         }
         else if (type == S2S_CFG_FLOPPY_14MB)
         {
-            azlog("---- Configuring as floppy drive based on image name");
+            logmsg("---- Configuring as floppy drive based on image name");
             img.deviceType = S2S_CFG_FLOPPY_14MB;
         }
         else if (type == S2S_CFG_MO)
         {
-            azlog("---- Configuring as magneto-optical based on image name");
+            logmsg("---- Configuring as magneto-optical based on image name");
             img.deviceType = S2S_CFG_MO;
         }
         else if (type == S2S_CFG_REMOVEABLE)
         {
-            azlog("---- Configuring as removable drive based on image name");
+            logmsg("---- Configuring as removable drive based on image name");
             img.deviceType = S2S_CFG_REMOVEABLE;
         }
         else if (type == S2S_CFG_SEQUENTIAL)
         {
-            azlog("---- Configuring as tape drive based on image name");
+            logmsg("---- Configuring as tape drive based on image name");
             img.deviceType = S2S_CFG_SEQUENTIAL;
         }
 
-#ifdef AZPLATFORM_CONFIG_HOOK
-        AZPLATFORM_CONFIG_HOOK(&img);
+#ifdef PLATFORM_CONFIG_HOOK
+        PLATFORM_CONFIG_HOOK(&img);
 #endif
 
         setDefaultDriveInfo(target_idx);
 
         if (img.prefetchbytes > 0)
         {
-            azlog("---- Read prefetch enabled: ", (int)img.prefetchbytes, " bytes");
+            logmsg("---- Read prefetch enabled: ", (int)img.prefetchbytes, " bytes");
         }
         else
         {
-            azlog("---- Read prefetch disabled");
+            logmsg("---- Read prefetch disabled");
         }
 
         return true;
@@ -811,7 +830,7 @@ static void checkDiskGeometryDivisible(image_config_t &img)
         uint32_t sectorsPerHeadTrack = img.sectorsPerTrack * img.headsPerCylinder;
         if (img.scsiSectors % sectorsPerHeadTrack != 0)
         {
-            azlog("WARNING: Host used command ", scsiDev.cdb[0],
+            logmsg("WARNING: Host used command ", scsiDev.cdb[0],
                 " which is affected by drive geometry. Current settings are ",
                 (int)img.sectorsPerTrack, " sectors x ", (int)img.headsPerCylinder, " heads = ",
                 (int)sectorsPerHeadTrack, " but image size of ", (int)img.scsiSectors,
@@ -904,7 +923,7 @@ void scsiDiskLoadConfig(int target_idx)
     {
         image_config_t &img = g_DiskImages[target_idx];
         int blocksize = (img.deviceType == S2S_CFG_OPTICAL) ? 2048 : 512;
-        azlog("-- Opening ", filename, " for id:", target_idx, ", specified in " CONFIGFILE);
+        logmsg("-- Opening ", filename, " for id:", target_idx, ", specified in " CONFIGFILE);
         scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, blocksize);
     }
 }
@@ -931,14 +950,14 @@ void s2s_configInit(S2S_BoardCfg* config)
 {
     if (SD.exists(CONFIGFILE))
     {
-        azlog("Reading configuration from " CONFIGFILE);
+        logmsg("Reading configuration from " CONFIGFILE);
     }
     else
     {
-        azlog("Config file " CONFIGFILE " not found, using defaults");
+        logmsg("Config file " CONFIGFILE " not found, using defaults");
     }
 
-    azlog("Active configuration:");
+    logmsg("Active configuration:");
     memset(config, 0, sizeof(S2S_BoardCfg));
     memcpy(config->magic, "BCFG", 4);
     config->flags = 0;
@@ -953,41 +972,41 @@ void s2s_configInit(S2S_BoardCfg* config)
     else if (maxSyncSpeed < 10 && config->scsiSpeed > S2S_CFG_SPEED_SYNC_5)
         config->scsiSpeed = S2S_CFG_SPEED_SYNC_5;
     
-    azlog("-- SelectionDelay: ", (int)config->selectionDelay);
+    logmsg("-- SelectionDelay: ", (int)config->selectionDelay);
 
     if (ini_getbool("SCSI", "EnableUnitAttention", false, CONFIGFILE))
     {
-        azlog("-- EnableUnitAttention is on");
+        logmsg("-- EnableUnitAttention is on");
         config->flags |= S2S_CFG_ENABLE_UNIT_ATTENTION;
     }
 
     if (ini_getbool("SCSI", "EnableSCSI2", true, CONFIGFILE))
     {
-        azlog("-- EnableSCSI2 is on");
+        logmsg("-- EnableSCSI2 is on");
         config->flags |= S2S_CFG_ENABLE_SCSI2;
     }
 
     if (ini_getbool("SCSI", "EnableSelLatch", false, CONFIGFILE))
     {
-        azlog("-- EnableSelLatch is on");
+        logmsg("-- EnableSelLatch is on");
         config->flags |= S2S_CFG_ENABLE_SEL_LATCH;
     }
 
     if (ini_getbool("SCSI", "MapLunsToIDs", false, CONFIGFILE))
     {
-        azlog("-- MapLunsToIDs is on");
+        logmsg("-- MapLunsToIDs is on");
         config->flags |= S2S_CFG_MAP_LUNS_TO_IDS;
     }
 
 #ifdef PLATFORM_HAS_PARITY_CHECK
     if (ini_getbool("SCSI", "EnableParity", true, CONFIGFILE))
     {
-        azlog("-- EnableParity is on");
+        logmsg("-- EnableParity is on");
         config->flags |= S2S_CFG_ENABLE_PARITY;
     }
     else
     {
-        azlog("-- EnableParity is off");
+        logmsg("-- EnableParity is off");
     }
 #endif
 }
@@ -1180,7 +1199,7 @@ static bool checkNextCDImage()
 
     if (filename[0] != '\0')
     {
-        azlog("Switching to next CD-ROM image for ", target_idx, ": ", filename);
+        logmsg("Switching to next CD-ROM image for ", target_idx, ": ", filename);
         image_config_t &img = g_DiskImages[target_idx];
         img.file.close();
         bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, 2048);
@@ -1202,14 +1221,14 @@ static void reinsertCDROM(image_config_t &img)
     if (img.image_index > 0)
     {
         // Multiple images for this drive, force restart from first one
-        azdbg("---- Restarting from first CD-ROM image");
+        dbgmsg("---- Restarting from first CD-ROM image");
         img.image_index = 9;
         checkNextCDImage();
     }
     else if (img.ejected)
     {
         // Reinsert the single image
-        azdbg("---- Closing CD-ROM tray");
+        dbgmsg("---- Closing CD-ROM tray");
         img.ejected = false;
         img.cdrom_events = 2; // New media
     }
@@ -1374,14 +1393,14 @@ static void doWrite(uint32_t lba, uint32_t blocks)
     uint32_t bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;
     uint32_t capacity = img.file.size() / bytesPerSector;
 
-    azdbg("------ Write ", (int)blocks, "x", (int)bytesPerSector, " starting at ", (int)lba);
+    dbgmsg("------ Write ", (int)blocks, "x", (int)bytesPerSector, " starting at ", (int)lba);
 
     if (unlikely(blockDev.state & DISK_WP) ||
         unlikely(scsiDev.target->cfg->deviceType == S2S_CFG_OPTICAL) ||
         unlikely(!img.file.isWritable()))
 
     {
-        azlog("WARNING: Host attempted write to read-only drive ID ", (int)(img.scsiId & S2S_CFG_TARGET_ID_BITS));
+        logmsg("WARNING: Host attempted write to read-only drive ID ", (int)(img.scsiId & S2S_CFG_TARGET_ID_BITS));
         scsiDev.status = CHECK_CONDITION;
         scsiDev.target->sense.code = ILLEGAL_REQUEST;
         scsiDev.target->sense.asc = WRITE_PROTECTED;
@@ -1389,7 +1408,7 @@ static void doWrite(uint32_t lba, uint32_t blocks)
     }
     else if (unlikely(((uint64_t) lba) + blocks > capacity))
     {
-        azlog("WARNING: Host attempted write at sector ", (int)lba, "+", (int)blocks,
+        logmsg("WARNING: Host attempted write at sector ", (int)lba, "+", (int)blocks,
               ", exceeding image size ", (int)capacity, " sectors (",
               (int)bytesPerSector, "B/sector)");
         scsiDev.status = CHECK_CONDITION;
@@ -1416,7 +1435,7 @@ static void doWrite(uint32_t lba, uint32_t blocks)
         image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
         if (!img.file.seek((uint64_t)transfer.lba * bytesPerSector))
         {
-            azlog("Seek to ", transfer.lba, " failed for SCSI ID", (int)scsiDev.target->targetId);
+            logmsg("Seek to ", transfer.lba, " failed for SCSI ID", (int)scsiDev.target->targetId);
             scsiDev.status = CHECK_CONDITION;
             scsiDev.target->sense.code = MEDIUM_ERROR;
             scsiDev.target->sense.asc = NO_SEEK_COMPLETE;
@@ -1467,7 +1486,7 @@ void diskDataOut_callback(uint32_t bytes_complete)
         if (len == 0)
             return;
 
-        // azdbg("SCSI read ", (int)start, " + ", (int)len);
+        // dbgmsg("SCSI read ", (int)start, " + ", (int)len);
         scsiStartRead(&scsiDev.data[start], len, &g_disk_transfer.parityError);
         g_disk_transfer.bytes_scsi_started += len;
     }
@@ -1567,17 +1586,17 @@ void diskDataOut()
             // when buffer space is freed.
             uint8_t *buf = &scsiDev.data[start];
             g_disk_transfer.sd_transfer_start = start;
-            // azdbg("SD write ", (int)start, " + ", (int)len, " ", bytearray(buf, len));
-            azplatform_set_sd_callback(&diskDataOut_callback, buf);
+            // dbgmsg("SD write ", (int)start, " + ", (int)len, " ", bytearray(buf, len));
+            platform_set_sd_callback(&diskDataOut_callback, buf);
             if (img.file.write(buf, len) != len)
             {
-                azlog("SD card write failed: ", SD.sdErrorCode());
+                logmsg("SD card write failed: ", SD.sdErrorCode());
                 scsiDev.status = CHECK_CONDITION;
                 scsiDev.target->sense.code = MEDIUM_ERROR;
                 scsiDev.target->sense.asc = WRITE_ERROR_AUTO_REALLOCATION_FAILED;
                 scsiDev.phase = STATUS;
             }
-            azplatform_set_sd_callback(NULL, NULL);
+            platform_set_sd_callback(NULL, NULL);
             g_disk_transfer.bytes_sd += len;
         }
     }
@@ -1613,11 +1632,11 @@ static void doRead(uint32_t lba, uint32_t blocks)
     uint32_t bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;
     uint32_t capacity = img.file.size() / bytesPerSector;
     
-    azdbg("------ Read ", (int)blocks, "x", (int)bytesPerSector, " starting at ", (int)lba);
+    dbgmsg("------ Read ", (int)blocks, "x", (int)bytesPerSector, " starting at ", (int)lba);
 
     if (unlikely(((uint64_t) lba) + blocks > capacity))
     {
-        azlog("WARNING: Host attempted read at sector ", (int)lba, "+", (int)blocks,
+        logmsg("WARNING: Host attempted read at sector ", (int)lba, "+", (int)blocks,
               ", exceeding image size ", (int)capacity, " sectors (",
               (int)bytesPerSector, "B/sector)");
         scsiDev.status = CHECK_CONDITION;
@@ -1648,7 +1667,7 @@ static void doRead(uint32_t lba, uint32_t blocks)
             uint32_t count = sectors_in_prefetch - start_offset;
             if (count > transfer.blocks) count = transfer.blocks;
             scsiStartWrite(g_scsi_prefetch.buffer + start_offset * bytesPerSector, count * bytesPerSector);
-            azdbg("------ Found ", (int)count, " sectors in prefetch cache");
+            dbgmsg("------ Found ", (int)count, " sectors in prefetch cache");
             transfer.currentBlock += count;
         }
 
@@ -1660,7 +1679,7 @@ static void doRead(uint32_t lba, uint32_t blocks)
 
         if (!img.file.seek((uint64_t)(transfer.lba + transfer.currentBlock) * bytesPerSector))
         {
-            azlog("Seek to ", transfer.lba, " failed for SCSI ID", (int)scsiDev.target->targetId);
+            logmsg("Seek to ", transfer.lba, " failed for SCSI ID", (int)scsiDev.target->targetId);
             scsiDev.status = CHECK_CONDITION;
             scsiDev.target->sense.code = MEDIUM_ERROR;
             scsiDev.target->sense.asc = NO_SEEK_COMPLETE;
@@ -1719,7 +1738,7 @@ static void start_dataInTransfer(uint8_t *buffer, uint32_t count)
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            azlog("start_dataInTransfer() timeout waiting for previous to finish");
+            logmsg("start_dataInTransfer() timeout waiting for previous to finish");
             scsiDev.resetFlag = 1;
         }
     }
@@ -1727,11 +1746,11 @@ static void start_dataInTransfer(uint8_t *buffer, uint32_t count)
 
     // Start transferring from SD card
     image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
-    azplatform_set_sd_callback(&diskDataIn_callback, buffer);
+    platform_set_sd_callback(&diskDataIn_callback, buffer);
 
     if (img.file.read(buffer, count) != count)
     {
-        azlog("SD card read failed: ", SD.sdErrorCode());
+        logmsg("SD card read failed: ", SD.sdErrorCode());
         scsiDev.status = CHECK_CONDITION;
         scsiDev.target->sense.code = MEDIUM_ERROR;
         scsiDev.target->sense.asc = UNRECOVERED_READ_ERROR;
@@ -1739,7 +1758,7 @@ static void start_dataInTransfer(uint8_t *buffer, uint32_t count)
     }
 
     diskDataIn_callback(count);
-    azplatform_set_sd_callback(NULL, NULL);
+    platform_set_sd_callback(NULL, NULL);
 }
 
 static void diskDataIn()
@@ -1805,16 +1824,16 @@ static void diskDataIn()
             // is part of a longer linear read.
             g_disk_transfer.bytes_sd = bytesPerSector;
             g_disk_transfer.bytes_scsi = bytesPerSector; // Tell callback not to send to SCSI
-            azplatform_set_sd_callback(&diskDataIn_callback, g_disk_transfer.buffer);
+            platform_set_sd_callback(&diskDataIn_callback, g_disk_transfer.buffer);
             int status = img.file.read(g_disk_transfer.buffer, bytesPerSector);
             if (status <= 0)
             {
-                azlog("Prefetch read failed");
+                logmsg("Prefetch read failed");
                 prefetch_sectors = 0;
                 break;
             }
             g_scsi_prefetch.bytes += status;
-            azplatform_set_sd_callback(NULL, NULL);
+            platform_set_sd_callback(NULL, NULL);
             prefetch_sectors--;
         }
 #endif
@@ -1848,13 +1867,13 @@ int scsiDiskCommand()
         {
             if (start)
             {
-                azdbg("------ CDROM close tray");
+                dbgmsg("------ CDROM close tray");
                 img.ejected = false;
                 img.cdrom_events = 2; // New media
             }
             else
             {
-                azdbg("------ CDROM open tray");
+                dbgmsg("------ CDROM open tray");
                 img.ejected = true;
                 img.cdrom_events = 3; // Media removal
             }

+ 2 - 0
src/ZuluSCSI_disk.h

@@ -17,6 +17,8 @@ void scsiDiskResetImages();
 bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int scsi_lun, int blocksize, S2S_CFG_TYPE type = S2S_CFG_FIXED);
 void scsiDiskLoadConfig(int target_idx);
 
+// Clear the ROM drive header from flash
+bool scsiDiskClearRomDrive();
 // Program ROM drive and rename image file
 bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S2S_CFG_TYPE type);
 

+ 40 - 40
src/ZuluSCSI_initiator.cpp

@@ -141,35 +141,35 @@ void scsiInitiatorMainLoop()
 
             if (readcapok)
             {
-                azlog("SCSI id ", g_initiator_state.target_id,
+                logmsg("SCSI id ", g_initiator_state.target_id,
                     " capacity ", (int)g_initiator_state.sectorcount,
                     " sectors x ", (int)g_initiator_state.sectorsize, " bytes");
 
                 g_initiator_state.sectorcount_all = g_initiator_state.sectorcount;
 
                 uint64_t total_bytes = (uint64_t)g_initiator_state.sectorcount * g_initiator_state.sectorsize;
-                azlog("Drive total size is ", (int)(total_bytes / (1024 * 1024)), " MiB");
+                logmsg("Drive total size is ", (int)(total_bytes / (1024 * 1024)), " MiB");
                 if (total_bytes >= 0xFFFFFFFF && SD.fatType() != FAT_TYPE_EXFAT)
                 {
                     // Note: the FAT32 limit is 4 GiB - 1 byte
-                    azlog("Image files equal or larger than 4 GiB are only possible on exFAT filesystem");
-                    azlog("Please reformat the SD card with exFAT format to image this drive fully");
+                    logmsg("Image files equal or larger than 4 GiB are only possible on exFAT filesystem");
+                    logmsg("Please reformat the SD card with exFAT format to image this drive fully");
 
                     g_initiator_state.sectorcount = (uint32_t)0xFFFFFFFF / g_initiator_state.sectorsize;
-                    azlog("Will image first 4 GiB - 1 = ", (int)g_initiator_state.sectorcount, " sectors");
+                    logmsg("Will image first 4 GiB - 1 = ", (int)g_initiator_state.sectorcount, " sectors");
                 }
             }
             else if (startstopok)
             {
-                azlog("SCSI id ", g_initiator_state.target_id, " responds but ReadCapacity command failed");
-                azlog("Possibly SCSI-1 drive? Attempting to read up to 1 GB.");
+                logmsg("SCSI id ", g_initiator_state.target_id, " responds but ReadCapacity command failed");
+                logmsg("Possibly SCSI-1 drive? Attempting to read up to 1 GB.");
                 g_initiator_state.sectorsize = 512;
                 g_initiator_state.sectorcount = g_initiator_state.sectorcount_all = 2097152;
                 g_initiator_state.max_sector_per_transfer = 128;
             }
             else
             {
-                azdbg("Failed to connect to SCSI id ", g_initiator_state.target_id);
+                dbgmsg("Failed to connect to SCSI id ", g_initiator_state.target_id);
                 g_initiator_state.sectorsize = 0;
                 g_initiator_state.sectorcount = g_initiator_state.sectorcount_all = 0;
             }
@@ -193,7 +193,7 @@ void scsiInitiatorMainLoop()
                 g_initiator_state.target_file = SD.open(filename, O_RDWR | O_CREAT | O_TRUNC);
                 if (!g_initiator_state.target_file.isOpen())
                 {
-                    azlog("Failed to open file for writing: ", filename);
+                    logmsg("Failed to open file for writing: ", filename);
                     return;
                 }
 
@@ -201,11 +201,11 @@ void scsiInitiatorMainLoop()
                 {
                     // Only preallocate on exFAT, on FAT32 preallocating can result in false garbage data in the
                     // file if write is interrupted.
-                    azlog("Preallocating image file");
+                    logmsg("Preallocating image file");
                     g_initiator_state.target_file.preAllocate((uint64_t)g_initiator_state.sectorcount * g_initiator_state.sectorsize);
                 }
 
-                azlog("Starting to copy drive data to ", filename);
+                logmsg("Starting to copy drive data to ", filename);
                 g_initiator_state.imaging = true;
             }
         }
@@ -216,13 +216,13 @@ void scsiInitiatorMainLoop()
         if (g_initiator_state.sectors_done >= g_initiator_state.sectorcount)
         {
             scsiStartStopUnit(g_initiator_state.target_id, false);
-            azlog("Finished imaging drive with id ", g_initiator_state.target_id);
+            logmsg("Finished imaging drive with id ", g_initiator_state.target_id);
             LED_OFF();
 
             if (g_initiator_state.sectorcount != g_initiator_state.sectorcount_all)
             {
-                azlog("NOTE: Image size was limited to first 4 GiB due to SD card filesystem limit");
-                azlog("Please reformat the SD card with exFAT format to image this drive fully");
+                logmsg("NOTE: Image size was limited to first 4 GiB due to SD card filesystem limit");
+                logmsg("Please reformat the SD card with exFAT format to image this drive fully");
             }
 
             g_initiator_state.drives_imaged |= (1 << g_initiator_state.target_id);
@@ -249,11 +249,11 @@ void scsiInitiatorMainLoop()
 
         if (!status)
         {
-            azlog("Failed to transfer ", numtoread, " sectors starting at ", (int)g_initiator_state.sectors_done);
+            logmsg("Failed to transfer ", numtoread, " sectors starting at ", (int)g_initiator_state.sectors_done);
 
             if (g_initiator_state.retrycount < 5)
             {
-                azlog("Retrying.. ", g_initiator_state.retrycount, "/5");
+                logmsg("Retrying.. ", g_initiator_state.retrycount, "/5");
                 delay(200);
                 scsiHostPhyReset();
                 delay(200);
@@ -263,13 +263,13 @@ void scsiInitiatorMainLoop()
 
                 if (g_initiator_state.retrycount > 1 && numtoread > 1)
                 {
-                    azlog("Multiple failures, retrying sector-by-sector");
+                    logmsg("Multiple failures, retrying sector-by-sector");
                     g_initiator_state.failposition = g_initiator_state.sectors_done + numtoread;
                 }
             }
             else
             {
-                azlog("Retry limit exceeded, skipping one sector");
+                logmsg("Retry limit exceeded, skipping one sector");
                 g_initiator_state.retrycount = 0;
                 g_initiator_state.sectors_done++;
                 g_initiator_state.target_file.seek((uint64_t)g_initiator_state.sectors_done * g_initiator_state.sectorsize);
@@ -282,7 +282,7 @@ void scsiInitiatorMainLoop()
             g_initiator_state.target_file.flush();
 
             int speed_kbps = numtoread * g_initiator_state.sectorsize / (millis() - time_start);
-            azlog("SCSI read succeeded, sectors done: ",
+            logmsg("SCSI read succeeded, sectors done: ",
                   (int)g_initiator_state.sectors_done, " / ", (int)g_initiator_state.sectorcount,
                   " speed ", speed_kbps, " kB/s");
         }
@@ -301,7 +301,7 @@ int scsiInitiatorRunCommand(int target_id,
 {
     if (!scsiHostPhySelect(target_id))
     {
-        azdbg("------ Target ", target_id, " did not respond");
+        dbgmsg("------ Target ", target_id, " did not respond");
         scsiHostPhyRelease();
         return -1;
     }
@@ -329,14 +329,14 @@ int scsiInitiatorRunCommand(int target_id,
             if (returnDataPhase) return 0;
             if (bufInLen == 0)
             {
-                azlog("DATA_IN phase but no data to receive!");
+                logmsg("DATA_IN phase but no data to receive!");
                 status = -3;
                 break;
             }
 
             if (scsiHostRead(bufIn, bufInLen) == 0)
             {
-                azlog("scsiHostRead failed, tried to read ", (int)bufInLen, " bytes");
+                logmsg("scsiHostRead failed, tried to read ", (int)bufInLen, " bytes");
                 status = -2;
                 break;
             }
@@ -346,14 +346,14 @@ int scsiInitiatorRunCommand(int target_id,
             if (returnDataPhase) return 0;
             if (bufOutLen == 0)
             {
-                azlog("DATA_OUT phase but no data to send!");
+                logmsg("DATA_OUT phase but no data to send!");
                 status = -3;
                 break;
             }
 
             if (scsiHostWrite(bufOut, bufOutLen) < bufOutLen)
             {
-                azlog("scsiHostWrite failed, was writing ", bytearray(bufOut, bufOutLen));
+                logmsg("scsiHostWrite failed, was writing ", bytearray(bufOut, bufOutLen));
                 status = -2;
                 break;
             }
@@ -363,7 +363,7 @@ int scsiInitiatorRunCommand(int target_id,
             uint8_t tmp = -1;
             scsiHostRead(&tmp, 1);
             status = tmp;
-            azdbg("------ STATUS: ", tmp);
+            dbgmsg("------ STATUS: ", tmp);
         }
     }
 
@@ -401,7 +401,7 @@ bool scsiInitiatorReadCapacity(int target_id, uint32_t *sectorcount, uint32_t *s
     {
         uint8_t sense_key;
         scsiRequestSense(target_id, &sense_key);
-        azlog("READ CAPACITY on target ", target_id, " failed, sense key ", sense_key);
+        logmsg("READ CAPACITY on target ", target_id, " failed, sense key ", sense_key);
         return false;
     }
     else
@@ -422,7 +422,7 @@ bool scsiRequestSense(int target_id, uint8_t *sense_key)
                                          response, sizeof(response),
                                          NULL, 0);
 
-    azdbg("RequestSense response: ", bytearray(response, 18));
+    dbgmsg("RequestSense response: ", bytearray(response, 18));
 
     *sense_key = response[2];
     return status == 0;
@@ -445,7 +445,7 @@ bool scsiStartStopUnit(int target_id, bool start)
     {
         uint8_t sense_key;
         scsiRequestSense(target_id, &sense_key);
-        azlog("START STOP UNIT on target ", target_id, " failed, sense key ", sense_key);
+        logmsg("START STOP UNIT on target ", target_id, " failed, sense key ", sense_key);
     }
 
     return status == 0;
@@ -490,18 +490,18 @@ bool scsiTestUnitReady(int target_id)
             if (sense_key == 6)
             {
                 uint8_t inquiry[36];
-                azlog("Target ", target_id, " reports UNIT_ATTENTION, running INQUIRY");
+                logmsg("Target ", target_id, " reports UNIT_ATTENTION, running INQUIRY");
                 scsiInquiry(target_id, inquiry);
             }
             else if (sense_key == 2)
             {
-                azlog("Target ", target_id, " reports NOT_READY, running STARTSTOPUNIT");
+                logmsg("Target ", target_id, " reports NOT_READY, running STARTSTOPUNIT");
                 scsiStartStopUnit(target_id, true);
             }
         }
         else
         {
-            azlog("Target ", target_id, " TEST UNIT READY response: ", status);
+            logmsg("Target ", target_id, " TEST UNIT READY response: ", status);
         }
     }
 
@@ -571,10 +571,10 @@ static void initiatorReadSDCallback(uint32_t bytes_complete)
         if (len == 0)
             return;
 
-        // azdbg("SCSI read ", (int)start, " + ", (int)len, ", sd ready cnt ", (int)sd_ready_cnt, " ", (int)bytes_complete, ", scsi done ", (int)g_initiator_transfer.bytes_scsi_done);
+        // dbgmsg("SCSI read ", (int)start, " + ", (int)len, ", sd ready cnt ", (int)sd_ready_cnt, " ", (int)bytes_complete, ", scsi done ", (int)g_initiator_transfer.bytes_scsi_done);
         if (scsiHostRead(&scsiDev.data[start], len) != len)
         {
-            azlog("Read failed at byte ", (int)g_initiator_transfer.bytes_scsi_done);
+            logmsg("Read failed at byte ", (int)g_initiator_transfer.bytes_scsi_done);
             g_initiator_transfer.all_ok = false;
         }
         g_initiator_transfer.bytes_scsi_done += len;
@@ -595,20 +595,20 @@ static void scsiInitiatorWriteDataToSd(FsFile &file, bool use_callback)
 
     // Start writing to SD card and simultaneously reading more from SCSI bus
     uint8_t *buf = &scsiDev.data[start];
-    // azdbg("SD write ", (int)start, " + ", (int)len);
+    // dbgmsg("SD write ", (int)start, " + ", (int)len);
 
     if (use_callback)
     {
-        azplatform_set_sd_callback(&initiatorReadSDCallback, buf);
+        platform_set_sd_callback(&initiatorReadSDCallback, buf);
     }
 
     g_initiator_transfer.bytes_sd_scheduled = g_initiator_transfer.bytes_sd + len;
     if (file.write(buf, len) != len)
     {
-        azlog("scsiInitiatorReadDataToFile: SD card write failed");
+        logmsg("scsiInitiatorReadDataToFile: SD card write failed");
         g_initiator_transfer.all_ok = false;
     }
-    azplatform_set_sd_callback(NULL, NULL);
+    platform_set_sd_callback(NULL, NULL);
     g_initiator_transfer.bytes_sd += len;
 }
 
@@ -652,7 +652,7 @@ bool scsiInitiatorReadDataToFile(int target_id, uint32_t start_sector, uint32_t
         uint8_t sense_key;
         scsiRequestSense(target_id, &sense_key);
 
-        azlog("scsiInitiatorReadDataToFile: READ failed: ", status, " sense key ", sense_key);
+        logmsg("scsiInitiatorReadDataToFile: READ failed: ", status, " sense key ", sense_key);
         scsiHostPhyRelease();
         return false;
     }
@@ -695,7 +695,7 @@ bool scsiInitiatorReadDataToFile(int target_id, uint32_t start_sector, uint32_t
 
     if (g_initiator_transfer.bytes_sd != g_initiator_transfer.bytes_scsi)
     {
-        azlog("SCSI read from sector ", (int)start_sector, " was incomplete: expected ",
+        logmsg("SCSI read from sector ", (int)start_sector, " was incomplete: expected ",
              (int)g_initiator_transfer.bytes_scsi, " got ", (int)g_initiator_transfer.bytes_sd, " bytes");
         g_initiator_transfer.all_ok = false;
     }
@@ -717,7 +717,7 @@ bool scsiInitiatorReadDataToFile(int target_id, uint32_t start_sector, uint32_t
             uint8_t tmp = 0;
             scsiHostRead(&tmp, 1);
             status = tmp;
-            azdbg("------ STATUS: ", tmp);
+            dbgmsg("------ STATUS: ", tmp);
         }
     }
 

+ 18 - 18
src/ZuluSCSI_log.cpp

@@ -2,8 +2,8 @@
 #include "ZuluSCSI_config.h"
 #include "ZuluSCSI_platform.h"
 
-const char *g_azlog_firmwareversion = ZULU_FW_VERSION " " __DATE__ " " __TIME__;
-bool g_azlog_debug = true;
+const char *g_log_firmwareversion = ZULU_FW_VERSION " " __DATE__ " " __TIME__;
+bool g_log_debug = true;
 
 // This memory buffer can be read by debugger and is also saved to zululog.txt
 #define LOGBUFMASK (LOGBUFSIZE - 1)
@@ -14,7 +14,7 @@ uint32_t g_log_magic;
 char g_logbuffer[LOGBUFSIZE + 1];
 uint32_t g_logpos;
 
-void azlog_raw(const char *str)
+void log_raw(const char *str)
 {
     // Keep log from reboot / bootloader if magic matches expected value
     if (g_log_magic != 0xAA55AA55)
@@ -33,11 +33,11 @@ void azlog_raw(const char *str)
     // Keep buffer null-terminated
     g_logbuffer[g_logpos & LOGBUFMASK] = '\0';
 
-    azplatform_log(str);
+    platform_log(str);
 }
 
 // Log byte as hex
-void azlog_raw(uint8_t value)
+void log_raw(uint8_t value)
 {
     const char *nibble = "0123456789ABCDEF";
     char hexbuf[5] = {
@@ -45,11 +45,11 @@ void azlog_raw(uint8_t value)
         nibble[(value >>  4) & 0xF], nibble[(value >>  0) & 0xF],
         0
     };
-    azlog_raw(hexbuf);
+    log_raw(hexbuf);
 }
 
 // Log integer as hex
-void azlog_raw(uint32_t value)
+void log_raw(uint32_t value)
 {
     const char *nibble = "0123456789ABCDEF";
     char hexbuf[11] = {
@@ -60,11 +60,11 @@ void azlog_raw(uint32_t value)
         nibble[(value >>  4) & 0xF], nibble[(value >>  0) & 0xF],
         0
     };
-    azlog_raw(hexbuf);
+    log_raw(hexbuf);
 }
 
 // Log integer as hex
-void azlog_raw(uint64_t value)
+void log_raw(uint64_t value)
 {
     const char *nibble = "0123456789ABCDEF";
     char hexbuf[19] = {
@@ -79,11 +79,11 @@ void azlog_raw(uint64_t value)
         nibble[(value >>  4) & 0xF], nibble[(value >>  0) & 0xF],
         0
     };
-    azlog_raw(hexbuf);
+    log_raw(hexbuf);
 }
 
 // Log integer as decimal
-void azlog_raw(int value)
+void log_raw(int value)
 {
     char decbuf[16] = {0};
     char *p = &decbuf[14];
@@ -99,29 +99,29 @@ void azlog_raw(int value)
         *--p = '-';
     }
 
-    azlog_raw(p);
+    log_raw(p);
 }
 
-void azlog_raw(bytearray array)
+void log_raw(bytearray array)
 {
     for (size_t i = 0; i < array.len; i++)
     {
-        azlog_raw(array.data[i]);
-        azlog_raw(" ");
+        log_raw(array.data[i]);
+        log_raw(" ");
         if (i > 32)
         {
-            azlog_raw("... (total ", (int)array.len, ")");
+            log_raw("... (total ", (int)array.len, ")");
             break;
         }
     }
 }
 
-uint32_t azlog_get_buffer_len()
+uint32_t log_get_buffer_len()
 {
     return g_logpos;
 }
 
-const char *azlog_get_buffer(uint32_t *startpos)
+const char *log_get_buffer(uint32_t *startpos)
 {
     uint32_t default_pos = 0;
     if (startpos == NULL)

+ 24 - 24
src/ZuluSCSI_log.h

@@ -6,32 +6,32 @@
 #include <stddef.h>
 
 // Get total number of bytes that have been written to log
-uint32_t azlog_get_buffer_len();
+uint32_t log_get_buffer_len();
 
 // Get log as a string.
 // If startpos is given, continues log reading from previous position and updates the position.
-const char *azlog_get_buffer(uint32_t *startpos);
+const char *log_get_buffer(uint32_t *startpos);
 
 // Whether to enable debug messages
-extern bool g_azlog_debug;
+extern bool g_log_debug;
 
 // Firmware version string
-extern const char *g_azlog_firmwareversion;
+extern const char *g_log_firmwareversion;
 
 // Log string
-void azlog_raw(const char *str);
+void log_raw(const char *str);
 
 // Log byte as hex
-void azlog_raw(uint8_t value);
+void log_raw(uint8_t value);
 
 // Log integer as hex
-void azlog_raw(uint32_t value);
+void log_raw(uint32_t value);
 
 // Log integer as hex
-void azlog_raw(uint64_t value);
+void log_raw(uint64_t value);
 
 // Log integer as decimal
-void azlog_raw(int value);
+void log_raw(int value);
 
 // Log array of bytes
 struct bytearray {
@@ -39,9 +39,9 @@ struct bytearray {
     const uint8_t *data;
     size_t len;
 };
-void azlog_raw(bytearray array);
+void log_raw(bytearray array);
 
-inline void azlog_raw()
+inline void log_raw()
 {
     // End of template recursion
 }
@@ -50,30 +50,30 @@ extern "C" unsigned long millis();
 
 // Variadic template for printing multiple items
 template<typename T, typename T2, typename... Rest>
-inline void azlog_raw(T first, T2 second, Rest... rest)
+inline void log_raw(T first, T2 second, Rest... rest)
 {
-    azlog_raw(first);
-    azlog_raw(second);
-    azlog_raw(rest...);
+    log_raw(first);
+    log_raw(second);
+    log_raw(rest...);
 }
 
 // Format a complete log message
 template<typename... Params>
-inline void azlog(Params... params)
+inline void logmsg(Params... params)
 {
-    azlog_raw("[", (int)millis(), "ms] ");
-    azlog_raw(params...);
-    azlog_raw("\n");
+    log_raw("[", (int)millis(), "ms] ");
+    log_raw(params...);
+    log_raw("\n");
 }
 
 // Format a complete debug message
 template<typename... Params>
-inline void azdbg(Params... params)
+inline void dbgmsg(Params... params)
 {
-    if (g_azlog_debug)
+    if (g_log_debug)
     {
-        azlog_raw("[", (int)millis(), "ms] DBG ");
-        azlog_raw(params...);
-        azlog_raw("\n");
+        log_raw("[", (int)millis(), "ms] DBG ");
+        log_raw(params...);
+        log_raw("\n");
     }
 }

+ 26 - 26
src/ZuluSCSI_log_trace.cpp

@@ -65,7 +65,7 @@ static void printNewPhase(int phase, bool initiator = false)
 {
     g_LogData = false;
     g_LogInitiatorCommand = false;
-    if (!g_azlog_debug)
+    if (!g_log_debug)
     {
         return;
     }
@@ -73,45 +73,45 @@ static void printNewPhase(int phase, bool initiator = false)
     switch(phase)
     {
         case BUS_FREE:
-            azdbg("-- BUS_FREE");
+            dbgmsg("-- BUS_FREE");
             break;
         
         case BUS_BUSY:
-            azdbg("-- BUS_BUSY");
+            dbgmsg("-- BUS_BUSY");
             break;
         
         case ARBITRATION:
-            azdbg("---- ARBITRATION");
+            dbgmsg("---- ARBITRATION");
             break;
         
         case SELECTION:
             if (initiator)
-                azdbg("---- SELECTION");
+                dbgmsg("---- SELECTION");
             else
-                azdbg("---- SELECTION: ", (int)(*SCSI_STS_SELECTED & 7));
+                dbgmsg("---- SELECTION: ", (int)(*SCSI_STS_SELECTED & 7));
             break;
         
         case RESELECTION:
-            azdbg("---- RESELECTION");
+            dbgmsg("---- RESELECTION");
             break;
         
         case STATUS:
             if (initiator)
             {
-                azdbg("---- STATUS");
+                dbgmsg("---- STATUS");
                 g_LogData = true;
             }
             else if (scsiDev.status == GOOD)
             {
-                azdbg("---- STATUS: 0 GOOD");
+                dbgmsg("---- STATUS: 0 GOOD");
             }
             else if (scsiDev.status == CHECK_CONDITION && scsiDev.target)
             {
-                azdbg("---- STATUS: 2 CHECK_CONDITION, sense ", (uint32_t)scsiDev.target->sense.asc);
+                dbgmsg("---- STATUS: 2 CHECK_CONDITION, sense ", (uint32_t)scsiDev.target->sense.asc);
             }
             else
             {
-                azdbg("---- STATUS: ", (int)scsiDev.status);
+                dbgmsg("---- STATUS: ", (int)scsiDev.status);
             }
             break;
         
@@ -122,32 +122,32 @@ static void printNewPhase(int phase, bool initiator = false)
         
         case DATA_IN:
             if (!initiator && scsiDev.target->syncOffset > 0)
-                azdbg("---- DATA_IN, syncOffset ", (int)scsiDev.target->syncOffset,
+                dbgmsg("---- DATA_IN, syncOffset ", (int)scsiDev.target->syncOffset,
                                    " syncPeriod ", (int)scsiDev.target->syncPeriod);
             else
-                azdbg("---- DATA_IN");
+                dbgmsg("---- DATA_IN");
             break;
         
         case DATA_OUT:
             if (!initiator && scsiDev.target->syncOffset > 0)
-                azdbg("---- DATA_OUT, syncOffset ", (int)scsiDev.target->syncOffset,
+                dbgmsg("---- DATA_OUT, syncOffset ", (int)scsiDev.target->syncOffset,
                                     " syncPeriod ", (int)scsiDev.target->syncPeriod);
             else
-                azdbg("---- DATA_OUT");
+                dbgmsg("---- DATA_OUT");
             break;
         
         case MESSAGE_IN:
-            azdbg("---- MESSAGE_IN");
+            dbgmsg("---- MESSAGE_IN");
             g_LogData = true;
             break;
         
         case MESSAGE_OUT:
-            azdbg("---- MESSAGE_OUT");
+            dbgmsg("---- MESSAGE_OUT");
             g_LogData = true;
             break;
         
         default:
-            azdbg("---- PHASE: ", phase);
+            dbgmsg("---- PHASE: ", phase);
             break;
     }
 }
@@ -162,7 +162,7 @@ void scsiLogPhaseChange(int new_phase)
     {
         if (old_phase == DATA_IN || old_phase == DATA_OUT)
         {
-            azdbg("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
+            dbgmsg("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
         }
         g_InByteCount = g_OutByteCount = 0;
         g_DataChecksum = 0;
@@ -176,7 +176,7 @@ void scsiLogPhaseChange(int new_phase)
             int syncper = scsiDev.target->syncPeriod;
             int syncoff = scsiDev.target->syncOffset;
             int mbyte_per_s = (1000 + syncper * 2) / (syncper * 4);
-            azlog("SCSI ID ", (int)scsiDev.target->targetId,
+            logmsg("SCSI ID ", (int)scsiDev.target->targetId,
                   " negotiated synchronous mode ", mbyte_per_s, " MB/s ",
                   "(period 4x", syncper, " ns, offset ", syncoff, " bytes)");
         }
@@ -196,7 +196,7 @@ void scsiLogInitiatorPhaseChange(int new_phase)
     {
         if (old_phase == DATA_IN || old_phase == DATA_OUT)
         {
-            azdbg("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
+            dbgmsg("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
         }
         g_InByteCount = g_OutByteCount = 0;
         g_DataChecksum = 0;
@@ -210,10 +210,10 @@ void scsiLogDataIn(const uint8_t *buf, uint32_t length)
 {
     if (g_LogData)
     {
-        azdbg("------ IN: ", bytearray(buf, length));
+        dbgmsg("------ IN: ", bytearray(buf, length));
     }
 
-    if (g_azlog_debug)
+    if (g_log_debug)
     {
         // BSD checksum algorithm
         for (uint32_t i = 0; i < length; i++)
@@ -230,15 +230,15 @@ void scsiLogDataOut(const uint8_t *buf, uint32_t length)
 {
     if (buf == scsiDev.cdb || g_LogInitiatorCommand)
     {
-        azdbg("---- COMMAND: ", getCommandName(buf[0]));
+        dbgmsg("---- COMMAND: ", getCommandName(buf[0]));
     }
     
     if (g_LogData)
     {
-        azdbg("------ OUT: ", bytearray(buf, length));
+        dbgmsg("------ OUT: ", bytearray(buf, length));
     }
 
-    if (g_azlog_debug)
+    if (g_log_debug)
     {
         // BSD checksum algorithm
         for (uint32_t i = 0; i < length; i++)