add template disk image

this is a pre-initialized, FAT12 image that is compatible with
Windows (which is the harder of the OSes to please)
This commit is contained in:
bunnie 2024-11-20 20:40:05 +08:00
parent e181c0d460
commit d9709997fb

View file

@ -16,17 +16,21 @@ use super::*;
// 0x6101_X000 "heap" would go here, except we don't have one
// 0x6100_0000 rw data for rust is at base of RAM
pub(crate) const RAMDISK_ADDRESS: usize = utralib::HW_SRAM_MEM + 128 * 1024;
pub(crate) const RAMDISK_LEN: usize = 1024 * 1024; // 1MiB of RAM allocated to "disk"
pub(crate) const RAMDISK_LEN: usize = 1536 * 1024; // 1.5MiB of RAM allocated to "disk"
pub(crate) const SECTOR_SIZE: u16 = 512;
pub(crate) const HEAP_ADDRESS: usize = RAMDISK_ADDRESS + RAMDISK_LEN;
pub(crate) const HEAP_LEN: usize = 128 * 1024;
// MBR template
// 0x0b~0x0C 2 bytes means block size, default 0x200 bytes
// 0x20~0x23 4 bytes means block number, default 0x400 block
#[rustfmt::skip] // keep this in 16-byte width
// TODO: change volume label from BAOSOR to BAOSEC
pub(crate) const MBR_TEMPLATE: [u8; SECTOR_SIZE as usize] = [
0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53, 0x35, 0x2E, 0x30, 0x00, 0x02, 0x20, 0x01, 0x00,
0x02, 0x00, 0x02, 0x00, 0x00, 0xF8, 0x00, 0x01, 0x3f, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0x00, 0x00, 0x80, 0x00, 0x29, 0x72, 0x1a, 0x65, 0xA4, 0x4E, 0x4F, 0x20, 0x4E, 0x41,
0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53, 0x35, 0x2E, 0x30, 0x00, 0x02, 0x20, 0x06, 0x00,
0x02, 0x00, 0x02, 0x00, 0x0C, 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x29, 0xBB, 0xBF, 0xB7, 0xB0, 0x4E, 0x4F, 0x20, 0x4E, 0x41,
0x4D, 0x45, 0x20, 0x20, 0x20, 0x20, 0x46, 0x41, 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x33, 0xC9,
0x8E, 0xD1, 0xBC, 0xF0, 0x7B, 0x8E, 0xD9, 0xB8, 0x00, 0x20, 0x8E, 0xC0, 0xFC, 0xBD, 0x00, 0x7C,
0x38, 0x4E, 0x24, 0x7D, 0x24, 0x8B, 0xC1, 0x99, 0xE8, 0x3C, 0x01, 0x72, 0x1C, 0x83, 0xEB, 0x3A,
@ -55,14 +59,70 @@ pub(crate) const MBR_TEMPLATE: [u8; SECTOR_SIZE as usize] = [
0x68, 0x65, 0x72, 0x20, 0x6D, 0x65, 0x64, 0x69, 0x61, 0x2E, 0xFF, 0x0D, 0x0A, 0x44, 0x69, 0x73,
0x6B, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0xFF, 0x0D, 0x0A, 0x50, 0x72, 0x65, 0x73, 0x73, 0x20,
0x61, 0x6E, 0x79, 0x20, 0x6B, 0x65, 0x79, 0x20, 0x74, 0x6F, 0x20, 0x72, 0x65, 0x73, 0x74, 0x61,
0x72, 0x74, 0x0D, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAC, 0xCB, 0xD8, 0x55, 0xAA
0x72, 0x74, 0x0D, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAC, 0xCB, 0xD8, 0x55, 0xAA,
];
pub(crate) const FAT_TABLE: [u8; 0x08] = [0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F];
pub(crate) const TABLE_OFFSET_FAT1: usize = 0xC00;
pub(crate) const TABLE_OFFSET_FAT2: usize = 0xE00;
#[rustfmt::skip] // keep this in 16-byte width
pub (crate) const ROOT_DIR: [u8; 0x80] = [
0x42, 0x41, 0x4F, 0x53, 0x4F, 0x52, 0x20, 0x20, 0x20, 0x20, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCD, 0x78, 0x74, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x42, 0x20, 0x00, 0x49, 0x00, 0x6E, 0x00, 0x66, 0x00, 0x6F, 0x00, 0x0F, 0x00, 0x72, 0x72, 0x00,
0x6D, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x6E, 0x00, 0x00, 0x00,
0x01, 0x53, 0x00, 0x79, 0x00, 0x73, 0x00, 0x74, 0x00, 0x65, 0x00, 0x0F, 0x00, 0x72, 0x6D, 0x00,
0x20, 0x00, 0x56, 0x00, 0x6F, 0x00, 0x6C, 0x00, 0x75, 0x00, 0x00, 0x00, 0x6D, 0x00, 0x65, 0x00,
0x53, 0x59, 0x53, 0x54, 0x45, 0x4D, 0x7E, 0x31, 0x20, 0x20, 0x20, 0x16, 0x00, 0x36, 0xCF, 0x78,
0x74, 0x59, 0x74, 0x59, 0x00, 0x00, 0xD0, 0x78, 0x74, 0x59, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
];
pub(crate) const ROOT_DIR_OFFSET: usize = 0x1000;
#[rustfmt::skip] // keep this in 16-byte width
pub (crate) const FAT_DATA1: [u8; 0x100] = [
0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x00, 0x36, 0xCF, 0x78,
0x74, 0x59, 0x74, 0x59, 0x00, 0x00, 0xD0, 0x78, 0x74, 0x59, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x2E, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x00, 0x36, 0xCF, 0x78,
0x74, 0x59, 0x74, 0x59, 0x00, 0x00, 0xD0, 0x78, 0x74, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x42, 0x47, 0x00, 0x75, 0x00, 0x69, 0x00, 0x64, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x01, 0x49, 0x00, 0x6E, 0x00, 0x64, 0x00, 0x65, 0x00, 0x78, 0x00, 0x0F, 0x00, 0xFF, 0x65, 0x00,
0x72, 0x00, 0x56, 0x00, 0x6F, 0x00, 0x6C, 0x00, 0x75, 0x00, 0x00, 0x00, 0x6D, 0x00, 0x65, 0x00,
0x49, 0x4E, 0x44, 0x45, 0x58, 0x45, 0x7E, 0x31, 0x20, 0x20, 0x20, 0x20, 0x00, 0x4E, 0xCF, 0x78,
0x74, 0x59, 0x74, 0x59, 0x00, 0x00, 0xD0, 0x78, 0x74, 0x59, 0x03, 0x00, 0x4C, 0x00, 0x00, 0x00,
0x42, 0x74, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0xCE, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x01, 0x57, 0x00, 0x50, 0x00, 0x53, 0x00, 0x65, 0x00, 0x74, 0x00, 0x0F, 0x00, 0xCE, 0x74, 0x00,
0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x73, 0x00, 0x2E, 0x00, 0x00, 0x00, 0x64, 0x00, 0x61, 0x00,
0x57, 0x50, 0x53, 0x45, 0x54, 0x54, 0x7E, 0x31, 0x44, 0x41, 0x54, 0x20, 0x00, 0xB5, 0xD8, 0x78,
0x74, 0x59, 0x74, 0x59, 0x00, 0x00, 0xD9, 0x78, 0x74, 0x59, 0x04, 0x00, 0x0C, 0x00, 0x00, 0x00,
];
pub(crate) const FAT_DATA1_OFFSET: usize = 0x5000;
#[rustfmt::skip] // keep this in 16-byte width
pub(crate) const FAT_DATA2: [u8; 0x50] = [
0x7B, 0x00, 0x34, 0x00, 0x33, 0x00, 0x39, 0x00, 0x44, 0x00, 0x41, 0x00, 0x31, 0x00, 0x32, 0x00,
0x44, 0x00, 0x2D, 0x00, 0x37, 0x00, 0x33, 0x00, 0x42, 0x00, 0x39, 0x00, 0x2D, 0x00, 0x34, 0x00,
0x43, 0x00, 0x41, 0x00, 0x34, 0x00, 0x2D, 0x00, 0x38, 0x00, 0x38, 0x00, 0x46, 0x00, 0x39, 0x00,
0x2D, 0x00, 0x44, 0x00, 0x41, 0x00, 0x32, 0x00, 0x43, 0x00, 0x46, 0x00, 0x33, 0x00, 0x31, 0x00,
0x38, 0x00, 0x45, 0x00, 0x32, 0x00, 0x37, 0x00, 0x35, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00,
];
pub(crate) const FAT_DATA2_OFFSET: usize = 0x9000;
#[rustfmt::skip] // keep this in 16-byte width
pub(crate) const FAT_DATA3: [u8; 0x10] = [
0x0C, 0x00, 0x00, 0x00, 0x28, 0x34, 0x07, 0x9C, 0x7C, 0xBD, 0x65, 0xF9, 0x00, 0x00, 0x00, 0x00,
];
pub(crate) const FAT_DATA3_OFFSET: usize = 0xD000;
pub(crate) const CSW_ADDR: usize = CRG_UDC_MEMBASE + CRG_UDC_APP_BUFOFFSET + CRG_UDC_APP_BUF_LEN;
pub(crate) const CBW_ADDR: usize = CRG_UDC_MEMBASE + CRG_UDC_APP_BUFOFFSET;
pub(crate) const EP1_IN_BUF: usize = CRG_UDC_MEMBASE + CRG_UDC_APP_BUFOFFSET + 1024;
pub(crate) const EP1_IN_BUF_LEN: usize = 1024;
#[allow(dead_code)]
pub(crate) const EP1_OUT_BUF: usize = CRG_UDC_MEMBASE + CRG_UDC_APP_BUFOFFSET + 2048;
#[allow(dead_code)]
pub(crate) const EP1_OUT_BUF_LEN: usize = 1024;
pub(crate) const MASS_STORAGE_EPADDR_IN: u8 = 0x81;
@ -225,7 +285,7 @@ pub fn usb_ep1_bulk_out_complete(this: &mut CorigineUsb, buf_addr: usize, info:
}
pub fn usb_ep1_bulk_in_complete(this: &mut CorigineUsb, _buf_addr: usize, info: u32, _error: u8) {
crate::println!("bulk IN handler");
// crate::println!("bulk IN handler");
let length = info & 0xFFFF;
if UmsState::DataPhase == this.ms_state {
//DATA
@ -321,7 +381,7 @@ fn process_request_sense(this: &mut CorigineUsb, cbw: Cbw) {
csw.residue = 0;
csw.status = 0;
csw.send(this);
crate::println!("UMS_STATE_STATUS_PHASE\r\n");
// crate::println!("UMS_STATE_STATUS_PHASE\r\n");
} else if cbw.flags & 0x80 != 0 {
if cbw.data_transfer_length < 18 {
let ep1_in = unsafe { core::slice::from_raw_parts_mut(EP1_IN_BUF as *mut u8, EP1_IN_BUF_LEN) };
@ -505,7 +565,6 @@ fn process_write_command(this: &mut CorigineUsb, cbw: Cbw) {
length |= cbw.cdb[8] as u32;
length *= SECTOR_SIZE as u32;
crate::println!("write of {} bytes", length);
if cbw.flags & 0x80 != 0 {
csw.residue = cbw.data_transfer_length;