From 30111d9299b39fb5f1050f9fd4422939a37cb519 Mon Sep 17 00:00:00 2001 From: bsongis Date: Tue, 8 Apr 2014 10:26:08 +0200 Subject: [PATCH] Bootloader MAC fixes from Mike --- radio/src/bootloader/boot.cpp | 7 +++++-- .../sky9x/usb/device/massstorage/MSDLun.c | 2 +- .../sky9x/usb/device/massstorage/SBC.h | 18 ++++++++++++++++ .../sky9x/usb/device/massstorage/SBCMethods.c | 16 ++++++++++++-- .../Class/msc/src/usbd_msc_scsi.c | 15 +++++++++++++ .../src/targets/taranis/usbd_storage_msd.cpp | 21 ++++++++++++++++++- 6 files changed, 73 insertions(+), 6 deletions(-) diff --git a/radio/src/bootloader/boot.cpp b/radio/src/bootloader/boot.cpp index 223cfcf30..5b17b4fac 100644 --- a/radio/src/bootloader/boot.cpp +++ b/radio/src/bootloader/boot.cpp @@ -715,8 +715,11 @@ int main() uint8_t event = getEvent(); - if (usbPlugged()) { - state = ST_USB; + if (state != ST_USB) { + if (usbPlugged()) { + state = ST_USB; + usbPluggedIn(); + } } if (state == ST_START) { diff --git a/radio/src/targets/sky9x/usb/device/massstorage/MSDLun.c b/radio/src/targets/sky9x/usb/device/massstorage/MSDLun.c index 61cfe825d..00c8376d3 100644 --- a/radio/src/targets/sky9x/usb/device/massstorage/MSDLun.c +++ b/radio/src/targets/sky9x/usb/device/massstorage/MSDLun.c @@ -54,7 +54,7 @@ static SBCInquiryData inquiryData = { SBC_PERIPHERAL_DEVICE_CONNECTED,// Peripheral device is connected 0x00, // Reserved bits 0x01, // Media is removable - SBC_SPC_VERSION_4, // SPC-4 supported + 0x02, // SBC_SPC_VERSION_4, // SPC-4 supported 0x2, // Response data format, must be 0x2 0, // Hierarchical addressing not supported 0, // ACA not supported diff --git a/radio/src/targets/sky9x/usb/device/massstorage/SBC.h b/radio/src/targets/sky9x/usb/device/massstorage/SBC.h index 47854c80c..1aed2b5b9 100644 --- a/radio/src/targets/sky9x/usb/device/massstorage/SBC.h +++ b/radio/src/targets/sky9x/usb/device/massstorage/SBC.h @@ -94,6 +94,8 @@ #define SBC_VERIFY_10 0x2F /// Request a list of the possible capacities that can be formatted on medium #define SBC_READ_FORMAT_CAPACITIES 0x23 + +#define SBC_START_STOP 0x19 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ @@ -620,6 +622,21 @@ typedef struct { } __attribute__ ((packed)) SBCReadWriteErrorRecovery; // GCC +//------------------------------------------------------------------------------ +/// \brief start/stop command +/// \see +//------------------------------------------------------------------------------ +typedef struct { + + unsigned char bModeDataLength; //!< Length of mode data to follow + unsigned char bImmediate:1, //!< + bReserved1:7; //!< Reserved bits + unsigned char pReserved[2]; //!< Reserved bytes + unsigned char startStop:1, //!< DPO/FUA bits supported ? + eject:1, //!< Reserved bits + bReserved2:6; //!< Is medium write-protected ? +} __attribute__ ((packed)) SBCStartStop; // GCC + //------------------------------------------------------------------------------ /// \brief Generic structure for holding information about SBC commands /// \see SBCInquiry @@ -642,6 +659,7 @@ typedef union { SBCWrite10 write10; //!< WRITE (10) command SBCMediumRemoval mediumRemoval; //!< PREVENT/ALLOW MEDIUM REMOVAL command SBCModeSense6 modeSense6; //!< MODE SENSE (6) command + SBCStartStop startStopCmd; //!< START-STOP command } SBCCommand; diff --git a/radio/src/targets/sky9x/usb/device/massstorage/SBCMethods.c b/radio/src/targets/sky9x/usb/device/massstorage/SBCMethods.c index 856bd2e87..0f69cd111 100644 --- a/radio/src/targets/sky9x/usb/device/massstorage/SBCMethods.c +++ b/radio/src/targets/sky9x/usb/device/massstorage/SBCMethods.c @@ -1430,7 +1430,7 @@ unsigned char SBC_GetCommandInformation(void *command, //------------------------------------ case SBC_PREVENT_ALLOW_MEDIUM_REMOVAL: - case 0x1B: + case SBC_START_STOP: //------------------------------------ (*type) = MSDD_NO_TRANSFER; break; @@ -1590,7 +1590,6 @@ unsigned char SBC_ProcessCommand(MSDLun *lun, //------------------------------------ case SBC_PREVENT_ALLOW_MEDIUM_REMOVAL: - case 0x1B: //------------------------------------ TRACE_INFO_WP("PrevAllowRem "); @@ -1600,6 +1599,19 @@ unsigned char SBC_ProcessCommand(MSDLun *lun, result = MSDD_STATUS_SUCCESS; break; + case SBC_START_STOP: + TRACE_INFO_WP("StartStop "); + + result = command->startStopCmd.startStop ; + if (result == 0) { + lun->status = LUN_EJECTED ; + } + else { + lun->status = LUN_CHANGED ; + } + result = MSDD_STATUS_SUCCESS; + break; + #if 0 //------------------------------------ case SBC_READ_FORMAT_CAPACITIES: diff --git a/radio/src/targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c b/radio/src/targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c index 93a20de01..7f3bfc325 100644 --- a/radio/src/targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c +++ b/radio/src/targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c @@ -432,9 +432,24 @@ void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC) * @param params: Command parameters * @retval status */ + +extern uint8_t lunReady[] ; + static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params) { MSC_BOT_DataLen = 0; + + if (lun < 2) { + if (params[4] & 1) { + // lun to be active + lunReady[lun] = 1 ; + } + else { + // lun to be ejected + lunReady[lun] = 0 ; + } + } + return 0; } diff --git a/radio/src/targets/taranis/usbd_storage_msd.cpp b/radio/src/targets/taranis/usbd_storage_msd.cpp index 79ddf8619..db9d2e2f8 100644 --- a/radio/src/targets/taranis/usbd_storage_msd.cpp +++ b/radio/src/targets/taranis/usbd_storage_msd.cpp @@ -161,6 +161,19 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si return 0; } +uint8_t lunReady[2] ; + +void usbPluggedIn() +{ + if (lunReady[0] == 0) { + lunReady[0] = 1; + } + + if (lunReady[1] == 0) { + lunReady[1] = 1; + } +} + /** * @brief check whether the medium is ready * @param lun : logical unit number @@ -169,9 +182,15 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si int8_t STORAGE_IsReady (uint8_t lun) { if (lun == 1) { - return 0; + if (lunReady[1] == 0) { + return -1 ; + } + return 0 ; } else { + if (lunReady[0] == 0) { + return -1 ; + } return SD_CARD_PRESENT() ? 0 : -1; } }