add support for emummc ums, this is terrible plz fix
This commit is contained in:
@@ -19,6 +19,8 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <storage/emmc.h>
|
||||||
|
#include <storage/emummc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <usb/usbd.h>
|
#include <usb/usbd.h>
|
||||||
@@ -495,8 +497,14 @@ static int _scsi_read(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do the SDMMC read.
|
// Do the SDMMC read.
|
||||||
if (!sdmmc_storage_read(ums->lun.storage, ums->lun.offset + lba_offset, amount, sdmmc_buf))
|
if(ums->lun.storage){
|
||||||
amount = 0;
|
if (!sdmmc_storage_read(ums->lun.storage, ums->lun.offset + lba_offset, amount, sdmmc_buf))
|
||||||
|
amount = 0;
|
||||||
|
}else{
|
||||||
|
if(!emummc_storage_file_based_read(ums->lun.offset + lba_offset, amount, sdmmc_buf)){
|
||||||
|
amount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for the async USB transfer to finish.
|
// Wait for the async USB transfer to finish.
|
||||||
if (!first_read)
|
if (!first_read)
|
||||||
@@ -650,9 +658,15 @@ static int _scsi_write(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt)
|
|||||||
goto empty_write;
|
goto empty_write;
|
||||||
|
|
||||||
// Perform the write.
|
// Perform the write.
|
||||||
if (!sdmmc_storage_write(ums->lun.storage, ums->lun.offset + lba_offset,
|
if(ums->lun.storage){
|
||||||
amount >> UMS_DISK_LBA_SHIFT, (u8 *)bulk_ctxt->bulk_out_buf))
|
if (!sdmmc_storage_write(ums->lun.storage, ums->lun.offset + lba_offset,
|
||||||
amount = 0;
|
amount >> UMS_DISK_LBA_SHIFT, (u8 *)bulk_ctxt->bulk_out_buf))
|
||||||
|
amount = 0;
|
||||||
|
}else{
|
||||||
|
if(!emummc_storage_file_based_read(ums->lun.offset + lba_offset, amount >> UMS_DISK_LBA_SHIFT, (u8*)bulk_ctxt->bulk_out_buf)){
|
||||||
|
amount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DPRINTF("file write %X @ %X\n", amount, lba_offset);
|
DPRINTF("file write %X @ %X\n", amount, lba_offset);
|
||||||
|
|
||||||
@@ -722,8 +736,14 @@ static int _scsi_verify(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sdmmc_storage_read(ums->lun.storage, ums->lun.offset + lba_offset, amount, bulk_ctxt->bulk_in_buf))
|
if(ums->lun.storage){
|
||||||
amount = 0;
|
if (!sdmmc_storage_read(ums->lun.storage, ums->lun.offset + lba_offset, amount, bulk_ctxt->bulk_in_buf))
|
||||||
|
amount = 0;
|
||||||
|
}else{
|
||||||
|
if(!emummc_storage_file_based_read(ums->lun.offset + lba_offset, amount, bulk_ctxt->bulk_in_buf)){
|
||||||
|
amount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DPRINTF("File read %X @ %X\n", amount, lba_offset);
|
DPRINTF("File read %X @ %X\n", amount, lba_offset);
|
||||||
|
|
||||||
@@ -756,8 +776,12 @@ static int _scsi_inquiry(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt)
|
|||||||
buf[3] = 20; // Additional length.
|
buf[3] = 20; // Additional length.
|
||||||
|
|
||||||
buf += 4;
|
buf += 4;
|
||||||
s_printf((char *)buf, "%04X%s",
|
if(ums->lun.storage){
|
||||||
ums->lun.storage->cid.serial, ums->lun.type == MMC_SD ? " SD " : " eMMC ");
|
s_printf((char *)buf, "%04X%s",
|
||||||
|
ums->lun.storage->cid.serial, ums->lun.type == MMC_SD ? " SD " : " eMMC ");
|
||||||
|
}else{
|
||||||
|
strcpy((char*)buf, "0000 emuMMC");
|
||||||
|
}
|
||||||
|
|
||||||
switch (ums->lun.partition)
|
switch (ums->lun.partition)
|
||||||
{
|
{
|
||||||
@@ -1871,9 +1895,38 @@ int usb_device_gadget_ums(usb_ctxt_t *usbs)
|
|||||||
|
|
||||||
ums.lun.sdmmc = &sd_sdmmc;
|
ums.lun.sdmmc = &sd_sdmmc;
|
||||||
ums.lun.storage = &sd_storage;
|
ums.lun.storage = &sd_storage;
|
||||||
|
}else if(usbs->type == MMC_EMUMMC_FILE){
|
||||||
|
// sd must be already mounted and emummc file based initialized
|
||||||
|
if(!sd_get_card_mounted()){
|
||||||
|
ums.set_text(ums.label, "#FFDD00 Failed to init SD!#");
|
||||||
|
res = 1;
|
||||||
|
goto init_fail;
|
||||||
|
}
|
||||||
|
ums.lun.storage = NULL;
|
||||||
|
ums.lun.sdmmc = NULL;
|
||||||
}
|
}
|
||||||
else
|
else if(usbs->type == MMC_EMUMMC_RAW_EMMC){
|
||||||
{
|
if (!emmc_initialize(false))
|
||||||
|
{
|
||||||
|
ums.set_text(ums.label, "#FFDD00 Failed to init eMMC!#");
|
||||||
|
res = 1;
|
||||||
|
goto init_fail;
|
||||||
|
}
|
||||||
|
emmc_set_partition(EMMC_GPP);
|
||||||
|
|
||||||
|
ums.lun.sdmmc = &emmc_sdmmc;
|
||||||
|
ums.lun.storage = &emmc_storage;
|
||||||
|
}else if(usbs->type == MMC_EMUMMC_RAW_SD){
|
||||||
|
if (!sd_initialize(false))
|
||||||
|
{
|
||||||
|
ums.set_text(ums.label, "#FFDD00 Failed to init SD!#");
|
||||||
|
res = 1;
|
||||||
|
goto init_fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
ums.lun.sdmmc = &emmc_sdmmc;
|
||||||
|
ums.lun.storage = &emmc_storage;
|
||||||
|
}else{
|
||||||
if (!emmc_initialize(false))
|
if (!emmc_initialize(false))
|
||||||
{
|
{
|
||||||
ums.set_text(ums.label, "#FFDD00 Failed to init eMMC!#");
|
ums.set_text(ums.label, "#FFDD00 Failed to init eMMC!#");
|
||||||
@@ -1902,10 +1955,23 @@ int usb_device_gadget_ums(usb_ctxt_t *usbs)
|
|||||||
// If partition sectors are not set get them from hardware.
|
// If partition sectors are not set get them from hardware.
|
||||||
if (!ums.lun.num_sectors)
|
if (!ums.lun.num_sectors)
|
||||||
{
|
{
|
||||||
if (usbs->type == MMC_EMMC && (ums.lun.partition - 1)) // eMMC BOOT0/1.
|
switch(usbs->type){
|
||||||
ums.lun.num_sectors = emmc_storage.ext_csd.boot_mult << 8;
|
case MMC_EMMC:
|
||||||
else
|
if(ums.lun.partition - 1){
|
||||||
ums.lun.num_sectors = ums.lun.storage->sec_cnt; // eMMC GPP or SD.
|
ums.lun.num_sectors = emmc_storage.ext_csd.boot_mult << 8;
|
||||||
|
}else{
|
||||||
|
ums.lun.num_sectors = ums.lun.storage->sec_cnt;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MMC_SD:
|
||||||
|
ums.lun.num_sectors = ums.lun.storage->sec_cnt;
|
||||||
|
break;
|
||||||
|
case MMC_EMUMMC_FILE:
|
||||||
|
case MMC_EMUMMC_RAW_SD:
|
||||||
|
case MMC_EMUMMC_RAW_EMMC:
|
||||||
|
ums.set_text(ums.label, "#FFDD00 No sector count set for emuMMC!#");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user