Kaynağa Gözat

Save a few more bytes in the bootloader and clean up unused code.

Eric Helgeson 3 ay önce
ebeveyn
işleme
a5001b6f29

+ 14 - 12
lib/BlueSCSI_platform_RP2MCU/BlueSCSI_platform.cpp

@@ -347,6 +347,18 @@ bool checkIs2023a() {
     return is2023a;
 }
 
+void platform_setup_sd() {
+    // SD card pins
+    // Card is used in SDIO mode for main program, and in SPI mode for crash handler & bootloader.
+    //        pin             function       pup   pdown  out    state fast
+    gpio_conf(SD_SPI_SCK,     GPIO_FUNC_SPI, true, false, true,  true, true);
+    gpio_conf(SD_SPI_MOSI,    GPIO_FUNC_SPI, true, false, true,  true, true);
+    gpio_conf(SD_SPI_MISO,    GPIO_FUNC_SPI, true, false, false, true, true);
+    gpio_conf(SD_SPI_CS,      GPIO_FUNC_SIO, true, false, true,  true, true);
+    gpio_conf(SDIO_D1,        GPIO_FUNC_SIO, true, false, false, true, true);
+    gpio_conf(SDIO_D2,        GPIO_FUNC_SIO, true, false, false, true, true);
+}
+
 void platform_init()
 {
 #ifndef PICO_RP2040
@@ -474,17 +486,7 @@ void platform_init()
     restore_interrupts(saved_irq);
     g_flash_chip_size = (1 << response_jedec[3]);
     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.
-    //        pin             function       pup   pdown  out    state fast
-    gpio_conf(SD_SPI_SCK,     GPIO_FUNC_SPI, true, false, true,  true, true);
-    gpio_conf(SD_SPI_MOSI,    GPIO_FUNC_SPI, true, false, true,  true, true);
-    gpio_conf(SD_SPI_MISO,    GPIO_FUNC_SPI, true, false, false, true, true);
-    gpio_conf(SD_SPI_CS,      GPIO_FUNC_SIO, true, false, true,  true, true);
-    gpio_conf(SDIO_D1,        GPIO_FUNC_SIO, true, false, false, true, true);
-    gpio_conf(SDIO_D2,        GPIO_FUNC_SIO, true, false, false, true, true);
-
+    platform_setup_sd();
     // LED pin
     if (!rp2040.isPicoW())
         gpio_conf(LED_PIN,    GPIO_FUNC_SIO, false,false, true,  false, false);
@@ -507,8 +509,8 @@ void platform_init()
     gpio_conf(GPIO_USB_POWER, GPIO_FUNC_SIO, false, false, false,  false, false);
 #endif
     checkIs2023a();
-
 }
+
 void platform_enable_initiator_mode()
 {
     g_scsi_initiator = true;

+ 3 - 0
lib/BlueSCSI_platform_RP2MCU/BlueSCSI_platform.h

@@ -85,6 +85,9 @@ static inline void delay_100ns()
 // Initialize SD card and GPIO configuration
 void platform_init();
 
+// Setup SD GPIO
+void platform_setup_sd();
+
 // Initialization for main application, not used for bootloader
 void platform_late_init();
 

+ 5 - 6
src/BlueSCSI.cpp

@@ -1,6 +1,6 @@
 /*
  *  BlueSCSI v2
- *  Copyright (c) 2023 Eric Helgeson, Androda, and contributors.
+ *  Copyright (c) 2023-2025 Eric Helgeson, Androda, and contributors.
  *
  *  This project is based on ZuluSCSI, BlueSCSI v1, and SCSI2SD:
  *
@@ -880,7 +880,7 @@ static void check_for_unused_update_files()
     if (!file.isDir())
     {
       size_t filename_len = file.getName(filename, sizeof(filename));
-      if (strncasecmp(filename, "bluescsi", sizeof("bluescsi" - 1)) == 0 &&
+      if (strncasecmp(filename, "bluescsi", sizeof("bluescsi") - 1) == 0 &&
           strncasecmp(filename + filename_len - 4, ".bin", 4) == 0)
       {
         bin_files_found = true;
@@ -1095,10 +1095,9 @@ static void bluescsi_setup_sd_card(bool wait_for_card = true)
       logmsg("Continuing without SD card");
     }
   }
-  check_for_unused_update_files();
-  firmware_update();
-
-
+  // We only have 2 boards, we don't use this Zip file parsing.
+  //check_for_unused_update_files();
+  //firmware_update();
 
   if (g_sdcard_present)
   {

+ 9 - 9
src/BlueSCSI_bootloader.cpp

@@ -36,6 +36,7 @@ bool find_firmware_image(FsFile &file, char name[MAX_FILE_PATH + 1])
     FsFile root;
     root.open("/");
 
+    bool found = false;
     while (file.openNext(&root, O_READ))
     {
         if (file.isDir()) continue;
@@ -44,20 +45,19 @@ bool find_firmware_image(FsFile &file, char name[MAX_FILE_PATH + 1])
         const char* board_name = PLATFORM_PID;
 
         if (namelen >= sizeof(FIRMWARE_PREFIX) + 3 &&
+            strncasecmp(name + namelen - 3, "bin", 3) == 0 &&
             strncasecmp(name, FIRMWARE_PREFIX, sizeof(FIRMWARE_PREFIX) - 1) == 0 &&
-            strstr(name, board_name) != NULL &&
-            strncasecmp(name + namelen - 3, "bin", 3) == 0)
+            strstr(name, board_name) != NULL)
         {
-            root.close();
-            logmsg("Found firmware file: ", name);
-            return true;
+            found = true;
+            break; // Exit loop, keeping the file open for the caller
         }
 
-        file.close();
+        file.close(); // Close file if it's not a match
     }
 
-    root.close();
-    return false;
+    root.close(); // Single close point for the root directory
+    return found;
 }
 
 #ifndef PLATFORM_FLASH_SECTOR_ERASE
@@ -143,7 +143,7 @@ static bool mountSDCard()
 extern "C"
 int bootloader_main(void)
 {
-    platform_init();
+    platform_setup_sd();
     g_log_debug = true;
 
     // logmsg("Bootloader version: " __DATE__ " " __TIME__ " " PLATFORM_NAME);

+ 1 - 1
src/build_bootloader.py

@@ -74,7 +74,7 @@ bootloader_bin = env.ElfToBin(
 def print_bootloader_size(source, target, env):
     bootloader_bin_path = str(target[0].get_abspath())
     size = os.path.getsize(bootloader_bin_path)
-    max_size = 135168  # 132k
+    max_size = 131072  # 128k
     percentage = (size / max_size) * 100
     print(f"Bootloader binary size: {size} / {max_size} bytes ({percentage:.2f}%)")