Add KBOOT.

This commit is contained in:
László Monda
2016-08-10 01:45:15 +02:00
commit e6c1fce5b4
9392 changed files with 3751375 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __USB_DISK_H__
#define __USB_DISK_H__ 1
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "usb_device_class.h"
#include "usb_device_msc.h"
#include "usb_device_ch9.h"
#include "usb_descriptor.h"
#include "flash/fsl_flash.h"
#include "executable_image.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
#define CONTROLLER_ID kUSB_ControllerEhci0
#endif
#if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
#define CONTROLLER_ID kUSB_ControllerKhci0
#endif
#define USB_DEVICE_INTERRUPT_PRIORITY (4)
/* Length of Each Logical Address Block */
#define LENGTH_OF_EACH_LBA (512)
/* total number of logical blocks present */
#define TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL (48)
/* Net Disk Size , default disk is 48*512, that is 24kByte, however , the disk reconnised by that PC only has 4k Byte,
* This is caused by that the file system also need memory*/
#define DISK_SIZE_NORMAL (TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL * LENGTH_OF_EACH_LBA)
#define LOGICAL_UNIT_SUPPORTED (1U)
#define USB_DEVICE_MSC_WRITE_BUFF_NUM 2
#define USB_DEVICE_MSC_WRITE_BUFF_SIZE 512
#define USB_DEVICE_MSC_READ_BUFF_SIZE 512
#define MSD_FLASH_BASE IMAGE_START_ADDRESS
// Program Flash block information
#define P_FLASH_BASE 0x00000000
#define P_FLASH_SIZE (FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE * FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT)
#define P_BLOCK_NUM FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT
#define P_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
typedef struct _usb_msc_struct
{
usb_device_handle deviceHandle;
class_handle_t mscHandle;
uint8_t storageDisk[DISK_SIZE_NORMAL];
uint8_t diskLock;
uint8_t read_write_error;
uint8_t currentConfiguration;
uint8_t currentInterfaceAlternateSetting[USB_MSC_INTERFACE_COUNT];
uint8_t speed;
uint8_t attach;
} usb_msc_struct_t;
extern flash_config_t s_flashInstance;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
void disk_init(void);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,183 @@
/*
* Copyright (c) 2013, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(_FAT_DIRECTORY_ENTRY_H_)
#define _FAT_DIRECTORY_ENTRY_H_
#include "bootloader_common.h"
#include <wchar.h>
//! @addtogroup fat_dir_entry
//! @{
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief FAT filesystem directory entry attributes.
enum _fat_directory_attributes
{
kReadOnlyAttribute = 0x01, //!< Read only.
kHiddenAttribute = 0x02, //!< Hidden.
kSystemAttribute = 0x04, //!< System.
kVolumeIdAttribute = 0x08, //!< Volume ID.
kDirectoryAttribute = 0x10, //!< Directory.
kArchiveAttribute = 0x20, //!< Archive
//! Attribute value to identify a long file name entry.
kLongNameAttribute = kReadOnlyAttribute | kHiddenAttribute | kSystemAttribute | kVolumeIdAttribute,
//! Marker flag for long name entry order field to indicate the final long name entry.
kLastLongNameEntry = 0x40,
//! The first name byte is set to this value to mark a directory entry as free.
kFreeEntryMarkerByte = 0xe5
};
#pragma pack(push)
#pragma pack(1)
//! @brief FAT filesystem directory entry.
//!
//! This union can represent either a standard file or directory entry, or a long file name entry.
//!
//! The upper 2 bits of the attribute byte are reserved and should always be set to 0 when a
//! file is created and never modify or look at it after that.
//!
//! The ntReserved field must be set to 0 when file is created and never modified or look at it after that.
//!
//! The creationTimeTenths field actually contains a count of tenths of a second. The granularity
//! of the seconds part of the creationTime is two seconds so this field is a count of tenths of a
//! second and its valid value range is 0-199 inclusive.
//!
//! Note that there is no last access time, only a date. This is the date of last read or
//! write. In the case of a write, this should be set to the same date as DIR_WrtDate.
//!
//! The firstClusterHigh field will always be 0 for a FAT12 or FAT16 volume.
//!
//! Note that file creation is considered a write.
typedef union FatDirectoryEntry
{
//! Standard file or directory entry with a short name.
struct
{
uint8_t name[11]; //!< Short file name.
uint8_t attributes; //!< File attributes.
uint8_t ntReserved; //!< Reserved.
uint8_t creationTimeTenths; //!< Millisecond stamp at file creation time.
uint16_t creationTime; //!< Time file was created.
uint16_t creationDate; //!< Date file was created.
uint16_t lastAccessDate; //!< Last access date.
uint16_t firstClusterHigh; //!< High two bytes of this entry's first cluster number.
uint16_t writeTime; //!< Time of last write.
uint16_t writeDate; //!< Date of last write.
uint16_t firstClusterLow; //!< Low two bytes of this entry's first cluster number.
uint32_t fileSize; //!< This file's size in bytes.
} entry;
//! Long file name directory entry.
struct
{
uint8_t order; //!< Order of this long file name entry. May be masked with #kLastLongNameEntry.
wchar_t name1[5]; //!< Characters 1-5 of the long name.
uint8_t attributes; //!< Must be set to #kLongNameAttribute.
uint8_t entryType; //!< Should be 0 for long file name directory entries.
uint8_t checksum; //!< Checksum of the short file name.
wchar_t name2[6]; //!< Characters 6-11 of the long name.
uint16_t firstClusterLow; //!< Must be set to 0 for compatibility.
wchar_t name3[2]; //!< Character 12-13 of the long name.
} longName;
} fat_directory_entry_t;
#pragma pack(pop)
//! @brief Macro to help build a standard directory entry.
#define MAKE_FAT_VOLUME_LABEL(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, t, d) \
{ \
.entry = { \
.name = { (c1), (c2), (c3), (c4), (c5), (c6), (c7), (c8), (c9), (c10), (c11) }, \
.attributes = kVolumeIdAttribute, \
.writeTime = (t), \
.writeDate = (d), \
} \
}
//! @brief Macro to help build a standard directory entry.
//!
//! Creation, last access, and write times/dates are all set to the same value.
//!
//! @param c1-c11 Characters of the file/directory name in 8.3 format.
//! @param a Attribute value.
//! @param t Time value.
//! @param d Date value.
//! @param cluster First cluster low. The first cluster high is set to 0.
//! @param s File size in bytes.
#define MAKE_FAT_DIR_ENTRY(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, a, t, d, cluster, s) \
{ \
.entry = {.name = { (c1), (c2), (c3), (c4), (c5), (c6), (c7), (c8), (c9), (c10), (c11) }, \
.attributes = (a), \
.creationTime = (t), \
.creationDate = (d), \
.lastAccessDate = (d), \
.writeTime = (t), \
.writeDate = (d), \
.firstClusterLow = (cluster), \
.fileSize = (s) } \
}
//! @brief Macro to help build a long name directory entry.
//!
//! @param o The order number for this entry.
//! @param c1-c13 Thirteen UTF16 characters.
//! @param k Checksum over the short name.
//! @param l Pass #kLastLongNameEntry if this is the last long file entry, or 0 otherwise.
#define MAKE_FAT_LONG_NAME(o, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, k, l) \
{ \
.longName = {.order = (o) | (l), \
.name1 = { (c1), (c2), (c3), (c4), (c5) }, \
.attributes = kLongNameAttribute, \
.checksum = (k), \
.name2 = { (c6), (c7), (c8), (c9), (c10), (c11) }, \
.name3 = { (c12), (c13) } } \
}
//! @brief Construct a FAT date value.
//!
//! Bits 0<><30>?: Day of month, valid value range 1-31 inclusive.<br/>
//! Bits 5<><35>?: Month of year, 1 = January, valid value range 1<><31>?2 inclusive.<br/>
//! Bits 9<><39>?5: Count of years from 1980, valid value range 0<><30>?27 inclusive (1980<38><30>?107).
#define MAKE_FAT_DATE(d, m, y) ((uint16_t)(((((y)-1980) & 0x7f) << 9) | (((m)&0xf) << 5) | ((d)&0x1f)))
//! @brief Construct a FAT time value.
//!
//! Bits 0<><30>?: 2-second count, valid value range 0<><30>?9 inclusive (0 <20><>?58 seconds).<br/>
//! Bits 5<><35>?0: Minutes, valid value range 0<><30>?9 inclusive.<br/>
//! Bits 11<31><31>?5: Hours, valid value range 0<><30>?3 inclusive.
#define MAKE_FAT_TIME(h, m, s) ((uint16_t)((((h)&0x1f) << 11) | (((m)&0x3f) << 5) | (((s) / 2) & 0x1f)))
//! @}
#endif // _FAT_DIRECTORY_ENTRY_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __USB_DEVICE_DESCRIPTOR_H__
#define __USB_DEVICE_DESCRIPTOR_H__
/*******************************************************************************
* Definitions
******************************************************************************/
#define USB_DEVICE_SPECIFIC_BCD_VERSION (0x0200U)
#define USB_DEVICE_DEMO_BCD_VERSION (0x0101U)
#define USB_DEVICE_MAX_POWER (0x32U)
#define USB_CONFIGURE_COUNT (1U)
#define USB_DEVICE_STRING_COUNT (4U)
#define USB_DEVICE_LANGUAGE_COUNT (1U)
#define USB_INTERFACE_COUNT (1U)
#define USB_MSC_CONFIGURE_INDEX (1U)
#define USB_MSC_ENDPOINT_COUNT (2U)
#define USB_MSC_BULK_IN_ENDPOINT (1U)
#define USB_MSC_BULK_OUT_ENDPOINT (2U)
/* usb descritpor length */
#define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL \
(USB_DESCRIPTOR_LENGTH_CONFIGURE + USB_DESCRIPTOR_LENGTH_INTERFACE + \
USB_DESCRIPTOR_LENGTH_ENDPOINT * USB_MSC_ENDPOINT_COUNT)
#define HS_MSC_BULK_IN_PACKET_SIZE (512U)
#define HS_MSC_BULK_OUT_PACKET_SIZE (512U)
#define FS_MSC_BULK_IN_PACKET_SIZE (64U)
#define FS_MSC_BULK_OUT_PACKET_SIZE (64U)
#define USB_STRING_DESCRIPTOR_HEADER_LENGTH (0x02U)
#define USB_STRING_DESCRIPTOR_0_LENGTH (0x02U)
#define USB_STRING_DESCRIPTOR_1_LENGTH (56U)
#define USB_STRING_DESCRIPTOR_2_LENGTH (32U)
#define USB_STRING_DESCRIPTOR_3_LENGTH (32U)
#define USB_STRING_DESCRIPTOR_ERROR_LENGTH (32U)
#define USB_MSC_INTERFACE_INDEX (0U)
#define USB_MSC_INTERFACE_COUNT (1U)
#define USB_DEVICE_CLASS (0x00U)
#define USB_DEVICE_SUBCLASS (0x00U)
#define USB_DEVICE_PROTOCOL (0x00U)
#define USB_MSC_CLASS (0x08U)
/* scsi command set */
#define USB_MSC_SUBCLASS (0x06U)
/* bulk only transport protocol */
#define USB_MSC_PROTOCOL (0x50U)
extern usb_device_class_struct_t g_UsbDeviceMscConfig;
extern usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed);
usb_status_t USB_DeviceGetDeviceDescriptor(usb_device_handle handle,
usb_device_get_device_descriptor_struct_t *deviceDescriptor);
usb_status_t USB_DeviceGetConfigurationDescriptor(
usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor);
usb_status_t USB_DeviceGetStringDescriptor(usb_device_handle handle,
usb_device_get_string_descriptor_struct_t *stringDescriptor);
#endif

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _USB_DEVICE_CONFIG_H_
#define _USB_DEVICE_CONFIG_H_
/*******************************************************************************
* Definitions
******************************************************************************/
/*!
* @addtogroup usb_device_configuration
* @{
*/
/*!
* @name Hardware instance define
* @{
*/
/*! @brief KHCI instance count */
#define USB_DEVICE_CONFIG_KHCI (1U)
/*! @brief EHCI instance count */
#define USB_DEVICE_CONFIG_EHCI (0U)
/*! @brief Device instance count, the sum of KHCI and EHCI instance counts*/
#define USB_DEVICE_CONFIG_NUM (USB_DEVICE_CONFIG_KHCI + USB_DEVICE_CONFIG_EHCI)
/* @} */
/*!
* @name class instance define
* @{
*/
/*! @brief HID instance count */
#define USB_DEVICE_CONFIG_HID (0U)
/*! @brief CDC ACM instance count */
#define USB_DEVICE_CONFIG_CDC_ACM (0U)
/*! @brief MSC instance count */
#define USB_DEVICE_CONFIG_MSC (1U)
/*! @brief Audio instance count */
#define USB_DEVICE_CONFIG_AUDIO (0U)
/*! @brief PHDC instance count */
#define USB_DEVICE_CONFIG_PHDC (0U)
/*! @brief Video instance count */
#define USB_DEVICE_CONFIG_VIDEO (0U)
/*! @brief CCID instance count */
#define USB_DEVICE_CONFIG_CCID (0U)
/*! @brief Printer instance count */
#define USB_DEVICE_CONFIG_PRINTER (0U)
/*! @brief DFU instance count */
#define USB_DEVICE_CONFIG_DFU (0U)
/* @} */
/*! @brief Whether device is self power. 1U supported, 0U not supported */
#define USB_DEVICE_CONFIG_SELF_POWER (1U)
/*! @brief Whether device remote wakeup supported. 1U supported, 0U not supported */
#define USB_DEVICE_CONFIG_REMOTE_WAKEUP (0U)
/*! @brief How many endpoints are supported in the stack. */
#define USB_DEVICE_CONFIG_ENDPOINTS (4U)
/*! @brief Whether the device task is enabled. */
#define USB_DEVICE_CONFIG_USE_TASK (0U)
/*! @brief How many the notification message are supported when the device task enabled. */
#define USB_DEVICE_CONFIG_MAX_MESSAGES (8U)
#if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U))
/*! @brief The MAX buffer length for the KHCI DMA workaround.*/
#define USB_DEVICE_CONFIG_KHCI_DMA_ALIGN_BUFFER_LENGTH (64U)
/*! @brief Whether handle the USB KHCI bus error. */
#define USB_DEVICE_CONFIG_KHCI_ERROR_HANDLING (0U)
#endif
#if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U))
/*! @brief How many the DTD are supported. */
#define USB_DEVICE_CONFIG_EHCI_MAX_DTD (16U)
/*! @brief Whether handle the USB EHCI bus error. */
#define USB_DEVICE_CONFIG_EHCI_ERROR_HANDLING (0U)
/*! @brief Whether test mode enabled. */
#define USB_DEVICE_CONFIG_EHCI_TEST_MODE (0U)
/*! @brief Whether the EHCI ID pin detect feature enabled. */
#define USB_DEVICE_CONFIG_EHCI_ID_PIN_DETECT (0U)
#endif
/*! @brief Whether the keep alive feature enabled. */
#define USB_DEVICE_CONFIG_KEEP_ALIVE_MODE (0U)
/*! @brief Whether the transfer buffer is cache-enabled or not. */
#define USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE (0U)
/*! @brief Whether the low power mode is enabled or not. */
#define USB_DEVICE_CONFIG_LOW_POWER_MODE (0U)
/*! @brief Whether the device detached feature is enabled or not. */
#define USB_DEVICE_CONFIG_DETACH_ENABLE (0U)
/* @} */
#endif /* _USB_DEVICE_CONFIG_H_ */

View File

@@ -0,0 +1,356 @@
/*
* Copyright (c) 2013, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "usb_msd_disk.h"
#include "fat_directory_entry.h"
/*******************************************************************************
* Definitions
******************************************************************************/
//! @brief Date and time constants for directory entries.
enum _date_time_constants
{
kFileDate = MAKE_FAT_DATE(12, 1, 2013), //!< 01-Dec-2013
kFileTime = MAKE_FAT_TIME(12, 0, 0) //!< 12:00:00 noon
};
/*******************************************************************************
* Variables
******************************************************************************/
//! @brief Partition boot sector.
//!
//! Defines the FAT16 file system.
//!
//! The 0xaa55 signature at the end of the sector is not stored in this data. Instead, it is
//! filled in at runtime. This is done in order to save const data space.
static const uint8_t k_pbs[] = {
0xEB,
0x3C,
0x90, // x86 JMP instruction
'M',
'S',
'W',
'I',
'N',
'4',
'.',
'1', // 'MSWIN4.1'
U16_LE(kDiskSectorSize), // bytes per sector = 512
0x01, // sectors per cluster = 1
U16_LE(1), // number of reserved sectors = 1 (FAT12/16)
0x02, // number of FATs = 2
U16_LE(32), // maximum number of root directory entries = 32
U16_LE(kDiskTotalLogicalBlocks - 1), // total volume sectors starting with PBS (16-bit count)
0xF0, // media type, must match FAT[0] = 0xf0 (removable media)
U16_LE(kDiskSectorsPerFat), // sectors per FAT = 1
U16_LE(1), // sectors per track = 1
U16_LE(1), // number of heads = 1
U32_LE(1), // sectors before start of PBS including MBR = 1
U32_LE(kDiskTotalLogicalBlocks - 1), // total volume sectors starting with PBS
0x00, // driver number (0x80 for hard disks) = 0
0x00, // reserved
0x29, // boot signature
'1',
'2',
'3',
'4', // volume ID = '1234'
'K',
'i',
'n',
'e',
't',
'i',
's',
' ',
'U',
'S',
'B', // volume label = 'Kinetis USB'
// ..448 reserved bytes
// 0x55,0xaa signature bytes - must be filled in at runtime
};
static const uint16_t k_fat1[] = {
0xfff0, // unused cluster 0 (low byte must match media type in PBS)
0xffff, // unused cluster 1
0xffff, // '.fseventsd' directory
0xffff, // 'System Volume Information' directory
0xffff, // 'IndexerVolumeGuid' file
0xffff, // 'info.txt' file
0xffff, // 'status.txt' file
};
//! @brief Root directory.
//!
//! Volume label: FSL Loader
//!
//! Contents:
//! - .fseventsd (FSEVEN~1)
//! - .metadata_never_index (METADA~1)
//! - .Trashes (TRASHE~1)
//! - System Volume Information (SYSTEM~1)
//! - info.txt
//! - status.txt
static const fat_directory_entry_t k_rootDir[] = {
// Volume label 'FSL Loader'
MAKE_FAT_VOLUME_LABEL('F', 'S', 'L', ' ', 'L', 'o', 'a', 'd', 'e', 'r', ' ', kFileTime, kFileDate),
// Mac OS X '.fseventsd' directory
MAKE_FAT_LONG_NAME(
1, L'.', L'f', L's', L'e', L'v', L'e', L'n', L't', L's', L'd', 0, 0xffff, 0xffff, 0xda, kLastLongNameEntry),
MAKE_FAT_DIR_ENTRY('F',
'S',
'E',
'V',
'E',
'N',
'~',
'1',
' ',
' ',
' ',
(kDirectoryAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kMacFseventsdDirSector),
0),
// Mac OS X '.metadata_never_index' file
MAKE_FAT_LONG_NAME(
2, L'e', L'r', L'_', L'i', L'n', L'd', L'e', L'x', 0, 0xffff, 0xffff, 0xffff, 0xffff, 0xa8, kLastLongNameEntry),
MAKE_FAT_LONG_NAME(1, L'.', L'm', L'e', L't', L'a', L'd', L'a', L't', L'a', L'_', L'n', L'e', L'v', 0xa8, 0),
MAKE_FAT_DIR_ENTRY('M',
'E',
'T',
'A',
'D',
'A',
'~',
'1',
' ',
' ',
' ',
(kArchiveAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
0,
0),
// Mac OS X '.Trashes' file
MAKE_FAT_LONG_NAME(
1, L'.', L'T', L'r', L'a', L's', L'h', L'e', L's', 0, 0xffff, 0xffff, 0xffff, 0xffff, 0x25, kLastLongNameEntry),
MAKE_FAT_DIR_ENTRY('T',
'R',
'A',
'S',
'H',
'E',
'~',
'1',
' ',
' ',
' ',
(kArchiveAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
0,
0),
// Windows 'System Volume Information' directory
MAKE_FAT_LONG_NAME(
2, L' ', L'I', L'n', L'f', L'o', L'r', L'm', L'a', L't', L'i', L'o', L'n', 0, 0x72, kLastLongNameEntry),
MAKE_FAT_LONG_NAME(1, L'S', L'y', L's', L't', L'e', L'm', L' ', L'V', L'o', L'l', L'u', L'm', L'e', 0x72, 0),
MAKE_FAT_DIR_ENTRY('S',
'Y',
'S',
'T',
'E',
'M',
'~',
'1',
' ',
' ',
' ',
(kDirectoryAttribute | kSystemAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kWindowsSysVolInfoDirSector),
0),
// Info and status files
MAKE_FAT_DIR_ENTRY('I',
'N',
'F',
'O',
' ',
' ',
' ',
' ',
'T',
'X',
'T',
kReadOnlyAttribute,
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kInfoFileSector),
1), // File size is filled in at runtime
MAKE_FAT_DIR_ENTRY('S',
'T',
'A',
'T',
'U',
'S',
' ',
' ',
'T',
'X',
'T',
kReadOnlyAttribute,
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kStatusFileSector),
1), // File size is filled in at runtime
};
//! @brief .fseventsd directory.
//!
//! Contents:
//! - .
//! - ..
//! - no_log
static const fat_directory_entry_t k_fseventsdDir[] = {
// . and .. directories
MAKE_FAT_DIR_ENTRY('.',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
(kDirectoryAttribute | kArchiveAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kMacFseventsdDirSector),
0),
MAKE_FAT_DIR_ENTRY(
'.', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', kDirectoryAttribute, kFileTime, kFileDate, 0, 0),
// Special 'no_log' file with reserved byte set to 0x08.
{.entry = {.name = { 'N', 'O', '_', 'L', 'O', 'G', ' ', ' ', ' ', ' ', ' ' },
.attributes = kArchiveAttribute,
.ntReserved = 0x08,
.creationTime = kFileTime,
.creationDate = kFileDate,
.lastAccessDate = kFileDate,
.firstClusterHigh = 0,
.writeTime = kFileTime,
.writeDate = kFileDate,
.firstClusterLow = 0,
.fileSize = 0 } },
};
static const wchar_t k_indexerVolumeGuidFile[] = L"{37203BF8-FD83-4321-A4C4-9A9ABF8FBCFD}";
//! @brief System Volume Information directory.
//!
//! Contents:
//! - .
//! - ..
//! - IndexerVolumeGuid (INDEXE~1)
static const fat_directory_entry_t k_sysVolInfoDir[] = {
// . and .. directories
MAKE_FAT_DIR_ENTRY('.',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
(kDirectoryAttribute | kArchiveAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kWindowsSysVolInfoDirSector),
0),
MAKE_FAT_DIR_ENTRY(
'.', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', kDirectoryAttribute, kFileTime, kFileDate, 0, 0),
// 'IndexerVolumeGuid' file
MAKE_FAT_LONG_NAME(
2, L'G', L'u', L'i', L'd', 0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0, 0, 0xff, kLastLongNameEntry),
MAKE_FAT_LONG_NAME(1, L'I', L'n', L'd', L'e', L'x', L'e', L'r', L'V', L'o', L'l', L'u', L'm', L'e', 0xff, 0),
MAKE_FAT_DIR_ENTRY('I',
'N',
'D',
'E',
'X',
'E',
'~',
'1',
' ',
' ',
' ',
kArchiveAttribute,
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kWindowsIndexerVolumeGuidSector),
(sizeof(k_indexerVolumeGuidFile) - 1)), // subtract 1 to remove the trailing null byte
};
const sector_info_t g_msdDiskSectors[] = {
{ kPbsSector, k_pbs, sizeof(k_pbs) },
{ kFat1Sector, (const uint8_t *)k_fat1, sizeof(k_fat1) },
{ kRootDir1Sector, (const uint8_t *)k_rootDir, sizeof(k_rootDir) },
// Support for Mac OS X: .fseventsd directory
{ kMacFseventsdDirSector, (const uint8_t *)k_fseventsdDir, sizeof(k_fseventsdDir) },
// Support for Window 8.1: System Volume Information directory
{ kWindowsSysVolInfoDirSector, (const uint8_t *)k_sysVolInfoDir, sizeof(k_sysVolInfoDir) },
{ kWindowsIndexerVolumeGuidSector, (const uint8_t *)k_indexerVolumeGuidFile,
sizeof(k_indexerVolumeGuidFile) - 1 }, // subtract 1 to remove the trailing null byte
// contains info.txt
// { kInfoFileSector, (const uint8_t *)((const uint8_t *)BlockBuf + 512), 512 },
//
// // contains status.txt
// { kStatusFileSector, (const uint8_t *)((const uint8_t *)BlockBuf + 1024), 512 },
// Terminator
{ 0 }
};

View File

@@ -0,0 +1,122 @@
/*
* Copyright (c) 2013, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(_USB_MSD_DISK_H_)
#define _USB_MSD_DISK_H_
//#include "bootloader_common.h"
#include "fsl_common.h"
//! @addtogroup usb_msd_disk
//! @{
/*******************************************************************************
* Definitions
******************************************************************************/
//! @name Data format macros
//@{
//! @brief Format a 32-bit little endian word as four bytes separated by commas.
#define U32_LE(n) ((n)&0xff), (((n) >> 8) & 0xff), (((n) >> 16) & 0xff), (((n) >> 24) & 0xff)
//! @brief Format a 16-bit little endian half-word as two bytes separated by commas.
#define U16_LE(n) ((n)&0xff), (((n) >> 8) & 0xff)
//@}
//! @brief Disk related constants.
enum _disk_constants
{
kDiskSectorSize = 512, //!< Size in bytes of each sector of the disk.
kDiskTotalLogicalBlocks = 2048, //!< Total number of sectors in the disk.
kDiskSizeInBytes = kDiskTotalLogicalBlocks * kDiskSectorSize, //!< Size in bytes of the total disk.
kDiskLogicalUnits = 1, //!< Number of SCSI LUNs.
kDiskHeaderSectorCount = 1, //!< PBS
kDiskFat16EntrySize = 2, //!< Two bytes per FAT16 entry.
kDiskClusterSize = 1, //!< Number of sectors per cluster.
kDiskDataClusterCount = (kDiskTotalLogicalBlocks - kDiskHeaderSectorCount) / kDiskClusterSize,
kDiskSectorsPerFat = (kDiskDataClusterCount * kDiskFat16EntrySize + kDiskSectorSize - 1) /
kDiskSectorSize, //!< Number of sectors occupied by each FAT, rounded up.
};
//! @brief Sector number constants.
enum _sector_numbers
{
kPbsSector = 0, //!< Partition Boot Sector
kFat1Sector = kPbsSector + 1, //!< FAT1
kFat2Sector = kFat1Sector + kDiskSectorsPerFat, //!< FAT2 (unused)
kRootDir1Sector = kFat2Sector + kDiskSectorsPerFat, //!< Root directory 1 (16 x 32-byte entries)
kRootDir2Sector, //!< Root directory 2 (16 x 32-byte entries)
kMacFseventsdDirSector, //!< Mac OS X '.fseventsd' directory
kWindowsSysVolInfoDirSector, //!< Windows 8.1 'System Volume Information' directory
kWindowsIndexerVolumeGuidSector, //!< Windows 8.1 'IndexerVolumeGuid' file
kInfoFileSector, //!< Info .txt file
kStatusFileSector, //!< Status .txt file
kFirstUnusedSector, //!< First sector available for data.
kFirstClusterSector = kRootDir1Sector, //!< Sector number of the first cluster.
};
//! @brief Convert a sector number to a cluster number.
#define CLUSTER_FROM_SECTOR(s) (((s)-kFirstClusterSector) / kDiskClusterSize)
//! @brief Root directory entry constants.
enum _root_dir_entry_numbers
{
kInfoFileDirEntry = 11,
kStatusFileDirEntry = 12,
kFirstUnusedDirEntry = 13
};
//! @brief Sector information.
//!
//! Information about canned sectors. The sector data does not have to completely fill the
//! sector. Any remainder bytes will be cleared to zero in the sector read function.
typedef struct SectorInfo
{
uint32_t sector; //!< Sector number.
const uint8_t *data; //!< Data for the sector.
uint32_t length; //!< Number of bytes of data.
} sector_info_t;
/*******************************************************************************
* Variables
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
extern const sector_info_t g_msdDiskSectors[];
#if defined(__cplusplus)
}
#endif /* __cplusplus */
//! @}
#endif // _USB_MSD_DISK_H_