Selaa lähdekoodia

Hardcode a default config, which is written to flash on first boot.

The bootloader fails checksums if the config is defined within a
code section, then later modified.
Hacking the .hex file isn't possible either because PSoC Programmer
checks that the non-bootloadable part of the flash is empty.
Michael McMaster 10 vuotta sitten
vanhempi
sitoutus
1907a3ebc0
1 muutettua tiedostoa jossa 29 lisäystä ja 0 poistoa
  1. 29 0
      lib/SCSI2SD/software/SCSI2SD/src/config.c

+ 29 - 0
lib/SCSI2SD/software/SCSI2SD/src/config.c

@@ -34,6 +34,17 @@
 
 static const uint16_t FIRMWARE_VERSION = 0x0424;
 
+// 1 flash row
+static const uint8_t DEFAULT_CONFIG[256] =
+{
+	0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x3F, 0x00,
+	0x00, 0x02, 0x3F, 0x00, 0xFF, 0x00, 0x20, 0x63, 0x6F, 0x64, 0x65, 0x73,
+	0x72, 0x63, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x53,
+	0x43, 0x53, 0x49, 0x32, 0x53, 0x44, 0x20, 0x31, 0x2E, 0x30, 0x31, 0x32,
+	0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
+	0x37, 0x38, 0x00, 0x00
+};
+
 enum USB_ENDPOINTS
 {
 	USB_EP_OUT = 1,
@@ -61,6 +72,24 @@ void configInit()
 	USBFS_Start(0, USBFS_5V_OPERATION);
 	usbInEpState = usbDebugEpState = USB_IDLE;
 	usbReady = 0; // We don't know if host is connected yet.
+
+	int invalid = 1;
+	uint8_t* rawConfig = getConfigByIndex(0);
+	int i;
+	for (i = 0; i < 64; ++i)
+	{
+		if (rawConfig[i])
+		{
+			invalid = 0;
+			break;
+		}
+	}
+	if (invalid)
+	{
+		// Save a default config.
+		CySetTemp();
+		CyWriteRowData(SCSI_CONFIG_ARRAY, SCSI_CONFIG_0_ROW, DEFAULT_CONFIG);
+	}
 }
 
 static void