Fix disk1 access (unencrypted!)
This commit is contained in:
parent
66fdb15378
commit
6bc0dec5bf
3 changed files with 34 additions and 6 deletions
|
@ -66,9 +66,6 @@ int flash_encrypt_write_sector(uint32_t sector, uint8_t *buf)
|
||||||
return -1;
|
return -1;
|
||||||
wc_Chacha_SetIV(&cha, hdr_cache.host_seed, sector);
|
wc_Chacha_SetIV(&cha, hdr_cache.host_seed, sector);
|
||||||
wc_Chacha_Process(&cha, buf, buf, SPI_FLASH_SECTOR_SIZE);
|
wc_Chacha_Process(&cha, buf, buf, SPI_FLASH_SECTOR_SIZE);
|
||||||
|
|
||||||
flash_sector_erase(DRIVE_FLASH_OFFSET + sector * SPI_FLASH_SECTOR_SIZE);
|
|
||||||
|
|
||||||
flash_write(DRIVE_FLASH_OFFSET + sector * SPI_FLASH_SECTOR_SIZE, buf,
|
flash_write(DRIVE_FLASH_OFFSET + sector * SPI_FLASH_SECTOR_SIZE, buf,
|
||||||
SPI_FLASH_SECTOR_SIZE);
|
SPI_FLASH_SECTOR_SIZE);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -98,6 +98,8 @@ static bool ejected = false;
|
||||||
static struct disk_lba sector_cache[BLOCKS_PER_SECTOR];
|
static struct disk_lba sector_cache[BLOCKS_PER_SECTOR];
|
||||||
static int sector_cached = -1;
|
static int sector_cached = -1;
|
||||||
|
|
||||||
|
static volatile int cache_busy = 1;
|
||||||
|
|
||||||
static int sector_cache_load(uint32_t sector)
|
static int sector_cache_load(uint32_t sector)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -115,15 +117,24 @@ static int sector_cache_load(uint32_t sector)
|
||||||
sector_cached = sector;
|
sector_cached = sector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void sector_cache_sched_commit(void)
|
||||||
|
{
|
||||||
|
cache_busy = 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void sector_cache_commit(void)
|
static void sector_cache_commit(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint32_t sector = sector_cached;
|
uint32_t sector = sector_cached;
|
||||||
if (sector * SPI_FLASH_SECTOR_SIZE > DRIVE_FLASH_SIZE)
|
if (sector * SPI_FLASH_SECTOR_SIZE > DRIVE_FLASH_SIZE) {
|
||||||
|
cache_busy = 0;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
//flash_encrypt_write_sector(sector, sector_cache[0].data);
|
//flash_encrypt_write_sector(sector, sector_cache[0].data);
|
||||||
|
flash_sector_erase(sector * SPI_FLASH_SECTOR_SIZE + DRIVE_FLASH_OFFSET);
|
||||||
flash_write(sector * SPI_FLASH_SECTOR_SIZE + DRIVE_FLASH_OFFSET,
|
flash_write(sector * SPI_FLASH_SECTOR_SIZE + DRIVE_FLASH_OFFSET,
|
||||||
sector_cache[0].data, SPI_FLASH_SECTOR_SIZE);
|
sector_cache[0].data, SPI_FLASH_SECTOR_SIZE);
|
||||||
|
cache_busy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct drive {
|
struct drive {
|
||||||
|
@ -254,7 +265,8 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
|
||||||
sec_off = lba - (sector * BLOCKS_PER_SECTOR);
|
sec_off = lba - (sector * BLOCKS_PER_SECTOR);
|
||||||
|
|
||||||
if ( sector != sector_cached) {
|
if ( sector != sector_cached) {
|
||||||
sector_cache_load(sector);
|
if (!cache_busy)
|
||||||
|
sector_cache_load(sector);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memcpy(buffer, sector_cache[sec_off].data + offset, bufsize);
|
memcpy(buffer, sector_cache[sec_off].data + offset, bufsize);
|
||||||
|
@ -291,10 +303,12 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
|
||||||
sector = lba / BLOCKS_PER_SECTOR;
|
sector = lba / BLOCKS_PER_SECTOR;
|
||||||
sec_off = lba - (sector * BLOCKS_PER_SECTOR);
|
sec_off = lba - (sector * BLOCKS_PER_SECTOR);
|
||||||
if ( sector != sector_cached) {
|
if ( sector != sector_cached) {
|
||||||
|
while(cache_busy)
|
||||||
|
sleep_ms(1);
|
||||||
sector_cache_load(sector);
|
sector_cache_load(sector);
|
||||||
}
|
}
|
||||||
memcpy(sector_cache[sec_off].data + offset, buffer, bufsize);
|
memcpy(sector_cache[sec_off].data + offset, buffer, bufsize);
|
||||||
sector_cache_commit();
|
sector_cache_sched_commit();
|
||||||
asm volatile("DMB");
|
asm volatile("DMB");
|
||||||
return bufsize;
|
return bufsize;
|
||||||
}
|
}
|
||||||
|
@ -380,4 +394,9 @@ void disk_crypto_activate(int status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void msc_task(void) {
|
||||||
|
if (cache_busy)
|
||||||
|
sector_cache_commit();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -304,8 +304,19 @@ void poll_buttons(void)
|
||||||
|
|
||||||
uint8_t *fbuf = NULL;
|
uint8_t *fbuf = NULL;
|
||||||
|
|
||||||
|
void tud_mount_cb(void)
|
||||||
|
{
|
||||||
|
gpio_put(RED_LED, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tud_umount_cb(void)
|
||||||
|
{
|
||||||
|
gpio_put(RED_LED, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint8_t flash_buf[4];
|
static uint8_t flash_buf[4];
|
||||||
|
extern void msc_task(void);
|
||||||
int main(void) {
|
int main(void) {
|
||||||
int i;
|
int i;
|
||||||
system_boot();
|
system_boot();
|
||||||
|
@ -322,6 +333,7 @@ int main(void) {
|
||||||
ui_task();
|
ui_task();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
msc_task();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of session. Goodbye. */
|
/* End of session. Goodbye. */
|
||||||
|
|
Loading…
Reference in a new issue