diff --git a/include/arm11/hardware/cfg11.h b/include/arm11/hardware/cfg11.h
index 0eb3176..ddce226 100644
--- a/include/arm11/hardware/cfg11.h
+++ b/include/arm11/hardware/cfg11.h
@@ -23,7 +23,7 @@
#define CFG11_REGS_BASE (IO_MEM_ARM9_ARM11 + 0x40000)
#define REG_CFG11_FIQ_CNT *((vu8* )(CFG11_REGS_BASE + 0x0104))
-#define REG_CFG11_SPI_CNT *((vu32*)(CFG11_REGS_BASE + 0x01C0))
+#define REG_CFG11_SPI_CNT *((vu16*)(CFG11_REGS_BASE + 0x01C0))
#define REG_UNK_10140400 *((vu8* )(CFG11_REGS_BASE + 0x0400))
#define REG_UNK_10140410 *((vu32*)(CFG11_REGS_BASE + 0x0410))
#define REG_CFG11_BOOTROM_OVERLAY_CNT *((vu8* )(CFG11_REGS_BASE + 0x0420))
diff --git a/include/arm11/hardware/spi.h b/include/arm11/hardware/spi.h
index 9b6f0b1..b227de3 100644
--- a/include/arm11/hardware/spi.h
+++ b/include/arm11/hardware/spi.h
@@ -35,10 +35,11 @@
{
SPI_DEV_UNK1 = 0,
SPI_DEV_NVRAM = 1,
- SPI_DEV_UNK2 = 2,
+ SPI_DEV_UNK3 = 2,
SPI_DEV_CODEC = 3,
- SPI_DEV_UNK3 = 0,
- SPI_DEV_UNK4 = 0,
+ SPI_DEV_UNK5 = 4,
+ SPI_DEV_UNK6 = 5,
+ SPI_DEV_UNK7 = 6,
} SpiDevice;
diff --git a/include/arm11/hardware/spiflash.h b/include/arm11/hardware/spiflash.h
new file mode 100644
index 0000000..98de7f2
--- /dev/null
+++ b/include/arm11/hardware/spiflash.h
@@ -0,0 +1,31 @@
+#pragma once
+
+/*
+ * This file is part of fastboot 3DS
+ * Copyright (C) 2019 derrek, profi200
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "types.h"
+
+
+#define SPIFLASH_CMD_RDSR (0x05)
+#define SPIFLASH_CMD_READ (0x03)
+
+
+
+// true if spiflash is installed, false otherwise
+bool spiflash_get_status(void);
+void spiflash_read(u32 offset, u32 size, u32 *buf);
diff --git a/include/arm9/dev.h b/include/arm9/dev.h
index aa05365..85d24a9 100644
--- a/include/arm9/dev.h
+++ b/include/arm9/dev.h
@@ -37,4 +37,3 @@
extern const dev_struct *dev_sdcard;
extern const dev_struct *dev_rawnand;
extern const dev_struct *dev_decnand;
-extern const dev_struct *dev_flash;
diff --git a/include/arm9/hardware/spiflash.h b/include/arm9/hardware/spiflash.h
deleted file mode 100644
index d935be1..0000000
--- a/include/arm9/hardware/spiflash.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-
-/*
- * This file is part of fastboot 3DS
- * Copyright (C) 2017 derrek, profi200
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "types.h"
-
-
-#define SPIFLASH_CMD_RDSR (0x05)
-#define SPIFLASH_CMD_READ (0x03)
-
-
-
-// true if spiflash is installed, false otherwise
-bool spiflash_get_status();
-void spiflash_read(u32 offset, u32 size, u8 *buf);
diff --git a/source/arm11/hardware/spi.c b/source/arm11/hardware/spi.c
index 16df7ee..c5a1b81 100644
--- a/source/arm11/hardware/spi.c
+++ b/source/arm11/hardware/spi.c
@@ -61,12 +61,13 @@
u8 csBaud;
} spiDevTable[] =
{
- {SPI_BUS1, 0u<<6 | SPI_BAUD_512KHz},
- {SPI_BUS3, 1u<<6 | 0}, // TODO: Bus, baudrate
- {SPI_BUS1, 2u<<6 | 0}, // TODO: Bus, baudrate
+ {SPI_BUS3, 0u<<6 | SPI_BAUD_512KHz},
+ {SPI_BUS3, 1u<<6 | 0}, // TODO: Baudrate
+ {SPI_BUS3, 2u<<6 | 0}, // TODO: Baudrate
{SPI_BUS1, 0u<<6 | SPI_BAUD_4MHz},
- {SPI_BUS1, 1u<<6 | 0}, // TODO: Bus, baudrate
- {SPI_BUS1, 2u<<6 | 0} // TODO: Bus, baudrate
+ {SPI_BUS1, 1u<<6 | 0}, // TODO: Baudrate
+ {SPI_BUS1, 2u<<6 | 0}, // TODO: Baudrate
+ {SPI_BUS2, 0u<<6 | 0} // TODO: Baudrate
};
diff --git a/source/arm11/hardware/spiflash.c b/source/arm11/hardware/spiflash.c
new file mode 100644
index 0000000..8941f7c
--- /dev/null
+++ b/source/arm11/hardware/spiflash.c
@@ -0,0 +1,46 @@
+/*
+ * This file is part of fastboot 3DS
+ * Copyright (C) 2019 derrek, profi200
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "types.h"
+#include "arm11/hardware/spiflash.h"
+#include "arm11/hardware/spi.h"
+
+
+
+bool spiflash_get_status(void)
+{
+ alignas(4) u8 cmdBuf[4];
+
+ cmdBuf[0] = SPIFLASH_CMD_RDSR;
+ SPI_writeRead(SPI_DEV_NVRAM, (u32*)cmdBuf, (u32*)cmdBuf, 1, 1, true);
+
+ if(cmdBuf[0] & 1) return false;
+ return true;
+}
+
+void spiflash_read(u32 offset, u32 size, u32 *buf)
+{
+ alignas(4) u8 cmdBuf[4];
+
+ cmdBuf[0] = SPIFLASH_CMD_READ;
+ cmdBuf[1] = (offset>>16) & 0xFFu;
+ cmdBuf[2] = (offset>>8) & 0xFFu;
+ cmdBuf[3] = offset & 0xFFu;
+ SPI_writeRead(SPI_DEV_NVRAM, (u32*)cmdBuf, NULL, 4, 0, false);
+ SPI_writeRead(SPI_DEV_NVRAM, NULL, buf, 0, size, true);
+}
diff --git a/source/arm9/dev.c b/source/arm9/dev.c
index a47ef63..6dc9a30 100644
--- a/source/arm9/dev.c
+++ b/source/arm9/dev.c
@@ -25,7 +25,6 @@
#include "arm9/ncsd.h"
#include "arm9/hardware/sdmmc.h"
#include "arm9/hardware/cfg9.h"
-#include "arm9/hardware/spiflash.h"
#include "arm9/hardware/interrupt.h"
#include "fs.h"
#include "arm9/hardware/crypto.h"
@@ -114,26 +113,6 @@
const dev_struct *dev_decnand = &dev_dnand.dev;
-// wifi flash device
-bool wififlash_init(void);
-bool wififlash_read_sector(u32 sector, u32 count, void *buf);
-bool wififlash_close(void);
-bool wififlash_is_active(void);
-u32 wififlash_get_sector_count(void);
-
-dev_struct dev_wififlash = {
- "nvram",
- false,
- wififlash_init,
- wififlash_read_sector,
- NULL,
- wififlash_close,
- wififlash_is_active,
- wififlash_get_sector_count
-};
-const dev_struct *dev_flash = &dev_wififlash;
-
-
static void sdioHandler(UNUSED u32 id);
// -------------------------------- sd card glue functions --------------------------------
@@ -476,38 +455,3 @@
{
return sdmmc_rnand_is_active() && dev_dnand.dev.initialized;
}
-
-
-// ------------------------------ wifi flash glue functions ------------------------------
-
-bool wififlash_init(void)
-{
- if(dev_wififlash.initialized) return true;
- if(!spiflash_get_status()) return false;
- dev_wififlash.initialized = true;
- return true;
-}
-
-bool wififlash_read_sector(u32 sector, u32 count, void *buf)
-{
- if(!dev_wififlash.initialized) return false;
- spiflash_read(sector<<9, count<<9, buf);
- return true;
-}
-
-bool wififlash_close(void)
-{
- dev_wififlash.initialized = false;
- return true;
-}
-
-bool wififlash_is_active(void)
-{
- return dev_wififlash.initialized;
-}
-
-u32 wififlash_get_sector_count(void)
-{
- if(!dev_wififlash.initialized) return 0;
- return 0x20000>>9;
-}
diff --git a/source/arm9/hardware/spiflash.c b/source/arm9/hardware/spiflash.c
deleted file mode 100644
index 2312a33..0000000
--- a/source/arm9/hardware/spiflash.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * This file is part of fastboot 3DS
- * Copyright (C) 2017 derrek, profi200
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "mem_map.h"
-#include "types.h"
-#include "arm9/hardware/spiflash.h"
-
-
-#define SPI_REGS_BUS2_BASE (IO_MEM_ARM9_ARM11 + 0x60000)
-#define REG_SPI_BUS2_CNT *((vu16*)(SPI_REGS_BUS2_BASE + 0x00))
-#define REG_SPI_BUS2_DATA *((vu8* )(SPI_REGS_BUS2_BASE + 0x02))
-
-
-
-static void spi_busy_wait()
-{
- while(REG_SPI_BUS2_CNT & 0x80);
-}
-
-static void spi_put_byte(u8 data)
-{
- REG_SPI_BUS2_DATA = data;
- spi_busy_wait();
-}
-
-static u8 spi_receive_byte()
-{
- // clock out a dummy byte
- REG_SPI_BUS2_DATA = 0x00;
- spi_busy_wait();
- return REG_SPI_BUS2_DATA;
-}
-
-// select spiflash if select=true, deselect otherwise
-static void spiflash_select(bool select)
-{
- // select device 1, enable SPI bus
- REG_SPI_BUS2_CNT = 0x8100 | (select << 11);
-}
-
-bool spiflash_get_status()
-{
- u8 resp;
-
- spi_busy_wait();
- spiflash_select(1);
- spi_put_byte(SPIFLASH_CMD_RDSR);
- spiflash_select(0);
- resp = spi_receive_byte();
-
- if(resp & 1) return false;
- return true;
-}
-
-void spiflash_read(u32 offset, u32 size, u8 *buf)
-{
- spi_busy_wait();
- spiflash_select(1);
- spi_put_byte(SPIFLASH_CMD_READ);
-
- // write addr (24-bit, msb first)
- for(int i=0; i<3; i++)
- {
- offset <<= 8;
- spi_put_byte((offset >> 24) & 0xFF);
- }
-
- // read bytes
- for(u32 i=0; i