Add KBOOT.
This commit is contained in:
158
validation/embedded_host/src/bootloader_config.h
Normal file
158
validation/embedded_host/src/bootloader_config.h
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2014-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 __BOOTLOADER_CONFIG_H__
|
||||
#define __BOOTLOADER_CONFIG_H__
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Bootloader configuration options
|
||||
//
|
||||
|
||||
//! @name Peripheral configuration macros
|
||||
//@{
|
||||
|
||||
#if !defined(BL_CONFIG_UART)
|
||||
#define BL_CONFIG_UART (1)
|
||||
#endif
|
||||
#if !defined(BL_CONFIG_SCUART)
|
||||
#define BL_CONFIG_SCUART (1)
|
||||
#endif
|
||||
#if !defined(BL_CONFIG_LPUART)
|
||||
#define BL_CONFIG_LPUART (1)
|
||||
#endif
|
||||
|
||||
#if !defined(BL_CONFIG_CAN)
|
||||
#define BL_CONFIG_CAN (1)
|
||||
#endif
|
||||
|
||||
#if !defined(BL_CONFIG_I2C)
|
||||
#define BL_CONFIG_I2C (1)
|
||||
#endif
|
||||
|
||||
#if !defined(BL_CONFIG_SPI)
|
||||
#define BL_CONFIG_SPI (1)
|
||||
#endif
|
||||
#if !defined(BL_CONFIG_DSPI)
|
||||
#define BL_CONFIG_DSPI (1)
|
||||
#endif
|
||||
|
||||
#if !defined(BL_CONFIG_USB)
|
||||
#define BL_CONFIG_USB (1)
|
||||
#endif
|
||||
#if !defined(BL_CONFIG_USB_HID)
|
||||
#define BL_CONFIG_USB_HID (0)
|
||||
#endif
|
||||
#if !defined(BL_CONFIG_USB_MSC)
|
||||
#define BL_CONFIG_USB_MSC (1)
|
||||
#endif
|
||||
|
||||
#if !defined(BL_CONFIG_USB_HID)
|
||||
#define BL_CONFIG_USB_HID (1)
|
||||
#endif
|
||||
#if !defined(BL_CONFIG_HS_USB_HID)
|
||||
#define BL_CONFIG_HS_USB_HID (0) // For TOWER and FRDM boards
|
||||
#endif
|
||||
|
||||
#if !defined(BL_CONFIG_HS_USB_MSC)
|
||||
#define BL_CONFIG_HS_USB_MSC (1) // For TOWER and FRDM boards
|
||||
#endif
|
||||
//@}
|
||||
|
||||
#if !defined(BL_TARGET_FLASH) && !defined(BL_TARGET_RAM)
|
||||
#define BL_TARGET_FLASH (1)
|
||||
#endif
|
||||
|
||||
#if !defined(BL_TARGET_RAM)
|
||||
#define BL_FEATURE_CRC_CHECK (1)
|
||||
#endif
|
||||
|
||||
#define BL_FEATURE_QSPI_MODULE (0)
|
||||
|
||||
#define BL_FEATURE_ENCRYPTION (1)
|
||||
|
||||
#define BL_FEATURE_UART_AUTOBAUD_IRQ (1)
|
||||
|
||||
// Bootloader peripheral detection default timeout in milliseconds
|
||||
// After coming out of reset the bootloader will spin in a peripheral detection
|
||||
// loop for this amount of time. A zero value means no time out.
|
||||
#if DEBUG
|
||||
#define BL_DEFAULT_PERIPHERAL_DETECT_TIMEOUT 0
|
||||
#else
|
||||
#define BL_DEFAULT_PERIPHERAL_DETECT_TIMEOUT 5000
|
||||
#endif // DEBUG
|
||||
|
||||
#define BL_FEATURE_POWERDOWN (0)
|
||||
|
||||
// Bootloader powerdown timeout in milliseconds
|
||||
// The bootloader enters a low power mode after waiting for this amount of time. A zero value means // no time out. Only
|
||||
// applicable if BL_FEATURE_POWERDOWN is enabled.
|
||||
#if DEBUG
|
||||
#define BL_DEFAULT_POWERDOWN_TIMEOUT 10000
|
||||
#else
|
||||
#define BL_DEFAULT_POWERDOWN_TIMEOUT 600000
|
||||
#endif // DEBUG
|
||||
|
||||
// The bootloader will check this address for the application vector table upon startup.
|
||||
#if !defined(BL_APP_VECTOR_TABLE_ADDRESS)
|
||||
#define BL_APP_VECTOR_TABLE_ADDRESS 0xa000
|
||||
#endif
|
||||
|
||||
/* Serial Port Info */
|
||||
|
||||
/**************************************************************************
|
||||
* Note:
|
||||
*
|
||||
* Because of the changes to the UART modules, we can no longer define
|
||||
* the TERM_PORT as a base pointer. The uart functions have been modified
|
||||
* accommodate this change. Now, TERM_PORT_NUM must be defined as the
|
||||
* number of the UART port desired to use
|
||||
*
|
||||
* TERM_PORT_NUM = 0 -- This allows you to use UART0; default pins are
|
||||
* PTA14 and PTA15
|
||||
*
|
||||
* TERM_PORT_NUM = 1 -- This allows you to use UART1; default pins are
|
||||
* PTC3 and PTC4
|
||||
*
|
||||
* TERM_PORT_NUM = 2 -- This allows you to use UART2; default pins are
|
||||
* PTD2 and PTD3
|
||||
*
|
||||
*************************************************************************/
|
||||
#define TERM_PORT_NUM 0
|
||||
|
||||
#define TERMINAL_BAUD 19200
|
||||
#undef HW_FLOW_CONTROL
|
||||
|
||||
#endif // __BOOTLOADER_CONFIG_H__
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
502
validation/embedded_host/src/disk/disk.c
Normal file
502
validation/embedded_host/src/disk/disk.c
Normal file
File diff suppressed because it is too large
Load Diff
104
validation/embedded_host/src/disk/disk.h
Normal file
104
validation/embedded_host/src/disk/disk.h
Normal 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
|
||||
183
validation/embedded_host/src/disk/fat_directory_entry.h
Normal file
183
validation/embedded_host/src/disk/fat_directory_entry.h
Normal 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_
|
||||
507
validation/embedded_host/src/disk/usb_descriptor.c
Normal file
507
validation/embedded_host/src/disk/usb_descriptor.c
Normal file
File diff suppressed because it is too large
Load Diff
93
validation/embedded_host/src/disk/usb_descriptor.h
Normal file
93
validation/embedded_host/src/disk/usb_descriptor.h
Normal 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
|
||||
140
validation/embedded_host/src/disk/usb_device_config.h
Normal file
140
validation/embedded_host/src/disk/usb_device_config.h
Normal 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_ */
|
||||
356
validation/embedded_host/src/disk/usb_msd_disk.c
Normal file
356
validation/embedded_host/src/disk/usb_msd_disk.c
Normal 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 }
|
||||
};
|
||||
122
validation/embedded_host/src/disk/usb_msd_disk.h
Normal file
122
validation/embedded_host/src/disk/usb_msd_disk.h
Normal 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_
|
||||
81
validation/embedded_host/src/image_program/SB_image.c
Normal file
81
validation/embedded_host/src/image_program/SB_image.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 "SB_image.h"
|
||||
#include "blsh/host_command.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
static uint32_t get_SB_image_length(uint32_t image_address);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
recordStatus_t SB_image_program(uint32_t image_address)
|
||||
{
|
||||
uint32_t image_length = get_SB_image_length(image_address);
|
||||
|
||||
if (handle_receiveSBFile_command(IMAGE_START_ADDRESS, image_length) != kStatus_Success)
|
||||
{
|
||||
return kRecordStatus_Fail;
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief get SB image length
|
||||
*
|
||||
* @param image_address image address in target flash.
|
||||
* @return the length of sb image
|
||||
*/
|
||||
static uint32_t get_SB_image_length(uint32_t image_address)
|
||||
{
|
||||
/* uint8_t hex[4] = {0}; */
|
||||
uint32_t image_blocks = 0;
|
||||
|
||||
image_blocks = read_flash_char(image_address, SB_IMAGE_BLOCKS_OFFSET + 3) << 24;
|
||||
image_blocks |= read_flash_char(image_address, SB_IMAGE_BLOCKS_OFFSET + 2) << 16;
|
||||
image_blocks |= read_flash_char(image_address, SB_IMAGE_BLOCKS_OFFSET + 1) << 8;
|
||||
image_blocks |= read_flash_char(image_address, SB_IMAGE_BLOCKS_OFFSET);
|
||||
|
||||
/* Size of each block is 16 bytes */
|
||||
return (image_blocks << 4);
|
||||
}
|
||||
59
validation/embedded_host/src/image_program/SB_image.h
Normal file
59
validation/embedded_host/src/image_program/SB_image.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 __SB_image_H__
|
||||
#define __SB_image_H__
|
||||
|
||||
#include "executable_image.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
enum
|
||||
{
|
||||
/*! Image blocks offset */
|
||||
SB_IMAGE_BLOCKS_OFFSET = 28,
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @brief parse SB image */
|
||||
recordStatus_t SB_image_program(uint32_t image_address);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __SB_image_H__ */
|
||||
64
validation/embedded_host/src/image_program/binary_image.c
Normal file
64
validation/embedded_host/src/image_program/binary_image.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 "binary_image.h"
|
||||
#include "blsh/host_command.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
recordStatus_t binary_image_program(uint32_t image_address, uint32_t image_length)
|
||||
{
|
||||
for (s_image_buffer_index = 0; s_image_buffer_index < image_length; s_image_buffer_index++)
|
||||
{
|
||||
s_image_buffer[s_image_buffer_index] = read_flash_char(image_address, s_image_buffer_index);
|
||||
}
|
||||
s_image_start_address = 0x8000;
|
||||
|
||||
if (handle_writeMemory_command(s_image_start_address, s_image_buffer, s_image_buffer_index) != kStatus_Success)
|
||||
{
|
||||
return kRecordStatus_Fail;
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
54
validation/embedded_host/src/image_program/binary_image.h
Normal file
54
validation/embedded_host/src/image_program/binary_image.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 __binary_image_H__
|
||||
#define __binary_image_H__
|
||||
|
||||
#include "executable_image.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* @brief parse srecord image */
|
||||
recordStatus_t binary_image_program(uint32_t image_address, uint32_t image_length);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __binary_image_H__ */
|
||||
117
validation/embedded_host/src/image_program/executable_image.c
Normal file
117
validation/embedded_host/src/image_program/executable_image.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 "executable_image.h"
|
||||
#include "blsh/bllibc.h"
|
||||
#include "srecord_image.h"
|
||||
#include "intelhex_image.h"
|
||||
#include "binary_image.h"
|
||||
#include "SB_image.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
uint8_t s_image_buffer[IMAGE_BUFFER_SIZE] = { 0 };
|
||||
uint32_t s_image_buffer_index = 0;
|
||||
uint32_t s_image_start_address = 0;
|
||||
uint32_t s_image_next_address = 0;
|
||||
uint32_t s_image_base_address = 0;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
uint8_t read_flash_char(uint32_t address, uint32_t index)
|
||||
{
|
||||
return *(uint8_t *)(address + index);
|
||||
}
|
||||
|
||||
uint8_t get_image_type()
|
||||
{
|
||||
if (read_flash_char(IMAGE_START_ADDRESS, SRECORD_SIGN_OFFSET) == SRECORD_SIGN)
|
||||
{
|
||||
return kImageType_Srecord;
|
||||
}
|
||||
else if (read_flash_char(IMAGE_START_ADDRESS, INTELHEX_SIGN_OFFSET) == INTELHEX_SIGN)
|
||||
{
|
||||
return kImageType_Intelhex;
|
||||
}
|
||||
else if ((read_flash_char(IMAGE_START_ADDRESS, SB_SIGN_OFFSET1) == SB_SIGN1) &&
|
||||
(read_flash_char(IMAGE_START_ADDRESS, SB_SIGN_OFFSET2) == SB_SIGN2) &&
|
||||
(read_flash_char(IMAGE_START_ADDRESS, SB_SIGN_OFFSET3) == SB_SIGN3) &&
|
||||
(read_flash_char(IMAGE_START_ADDRESS, SB_SIGN_OFFSET4) == SB_SIGN4))
|
||||
{
|
||||
return kImageType_SB;
|
||||
}
|
||||
else if ((read_flash_char(IMAGE_START_ADDRESS, 0) != 0xff) || (read_flash_char(IMAGE_START_ADDRESS, 1) != 0xff) ||
|
||||
(read_flash_char(IMAGE_START_ADDRESS, 2) != 0xff) || (read_flash_char(IMAGE_START_ADDRESS, 3) != 0xff))
|
||||
{
|
||||
return kImageType_Binary;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kImageType_Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
recordStatus_t flash_image(flash_image_status_t function)
|
||||
{
|
||||
uint8_t image_type = get_image_type();
|
||||
uint32_t status = kRecordStatus_InvalidStart;
|
||||
|
||||
if (image_type == kImageType_Srecord)
|
||||
{
|
||||
status = srecord_image_program(IMAGE_START_ADDRESS);
|
||||
}
|
||||
else if (image_type == kImageType_Intelhex)
|
||||
{
|
||||
status = intelhex_image_program(IMAGE_START_ADDRESS);
|
||||
}
|
||||
else if (image_type == kImageType_SB)
|
||||
{
|
||||
status = SB_image_program(IMAGE_START_ADDRESS);
|
||||
}
|
||||
else if (image_type == kImageType_Binary)
|
||||
{
|
||||
// status = binary_image_program(IMAGE_START_ADDRESS, 1788);
|
||||
status = kRecordStatus_InvalidType;
|
||||
}
|
||||
|
||||
if (function != 0)
|
||||
{
|
||||
function(status);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
127
validation/embedded_host/src/image_program/executable_image.h
Normal file
127
validation/embedded_host/src/image_program/executable_image.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 __executable_image_H__
|
||||
#define __executable_image_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
#define IMAGE_BUFFER_SIZE 1024 * 16
|
||||
#define IMAGE_START_ADDRESS 0x00010000
|
||||
|
||||
/*! Image type value. */
|
||||
enum
|
||||
{
|
||||
kImageType_SB = 0,
|
||||
kImageType_Srecord = 1,
|
||||
kImageType_Intelhex = 2,
|
||||
kImageType_Binary = 3,
|
||||
kImageType_Invalid = 4
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/*! The sb image sign. */
|
||||
SB_SIGN1 = 'S',
|
||||
SB_SIGN2 = 'T',
|
||||
SB_SIGN3 = 'M',
|
||||
SB_SIGN4 = 'P',
|
||||
/*! The sign offeset form start address. */
|
||||
SB_SIGN_OFFSET1 = 20,
|
||||
SB_SIGN_OFFSET2 = 21,
|
||||
SB_SIGN_OFFSET3 = 22,
|
||||
SB_SIGN_OFFSET4 = 23
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/*! The srecord image sign. */
|
||||
SRECORD_SIGN = 'S',
|
||||
/*! The sign offeset form start address. */
|
||||
SRECORD_SIGN_OFFSET = 0
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/*! The intelhex image sign. */
|
||||
INTELHEX_SIGN = ':',
|
||||
/*! The sign offeset form start address. */
|
||||
INTELHEX_SIGN_OFFSET = 0
|
||||
};
|
||||
|
||||
enum _recordStatus_t
|
||||
{
|
||||
kRecordStatus_Success = 0,
|
||||
kRecordStatus_Fail = 1,
|
||||
kRecordStatus_InvalidLength = 2,
|
||||
kRecordStatus_InvalidStart = 3,
|
||||
kRecordStatus_InvalidType = 4,
|
||||
kRecordStatus_InvalidChecksum = 5,
|
||||
kRecordStatus_FlashOver = 6,
|
||||
kRecordStatus_FlashPartly = 7,
|
||||
kRecordStatus_EraseOver = 8,
|
||||
kRecordStatus_ErasePartly = 9
|
||||
};
|
||||
typedef uint8_t recordStatus_t;
|
||||
|
||||
//! @brief Type of callback for flash image status
|
||||
typedef void (*flash_image_status_t)(recordStatus_t status);
|
||||
|
||||
extern uint8_t s_image_buffer[IMAGE_BUFFER_SIZE];
|
||||
extern uint32_t s_image_buffer_index;
|
||||
extern uint32_t s_image_start_address;
|
||||
extern uint32_t s_image_next_address;
|
||||
extern uint32_t s_image_base_address;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @brief read a char from flash region */
|
||||
uint8_t read_flash_char(uint32_t address, uint32_t index);
|
||||
|
||||
/*! @brief get image type */
|
||||
uint8_t get_image_type();
|
||||
|
||||
/*! @brief falsh_image function */
|
||||
recordStatus_t flash_image(flash_image_status_t function);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __executable_image_H__ */
|
||||
477
validation/embedded_host/src/image_program/intelhex_image.c
Normal file
477
validation/embedded_host/src/image_program/intelhex_image.c
Normal file
@@ -0,0 +1,477 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 "fsl_common.h"
|
||||
#include "intelhex_image.h"
|
||||
#include "blsh/bllibc.h"
|
||||
#include "blsh/host_command.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
typedef struct _intelhex_record_t
|
||||
{
|
||||
uint8_t dataCount; /*!< The number of bytes in the data field. */
|
||||
uint32_t address; /*!< The address offset of the data. */
|
||||
uint8_t type; /*!< Type of the data field. 00: Data */
|
||||
/*!< 01: End of File */
|
||||
/*!< 02: Extended Segment Address */
|
||||
/*!< 03: Start Segment Address */
|
||||
/*!< 04: Extended Linear Address */
|
||||
/*!< 05: Start Linear Address */
|
||||
uint8_t data[256]; /*!< Pointer to data, or NULL if no data for this record. */
|
||||
uint8_t checksum; /*!< The checksum byte used to verify the record. */
|
||||
} intelhex_record_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
static intelhex_record_t s_new_record = { 0 };
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
static recordStatus_t intelhex_record_parse_line(uint8_t *line, uint8_t line_length);
|
||||
static recordStatus_t intelhex_record_build_image(intelhex_record_t *new_record);
|
||||
static recordStatus_t intelhex_record_erase_target(uint32_t image_address);
|
||||
static recordStatus_t intelhex_record_erase_region(intelhex_record_t *new_record);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
recordStatus_t intelhex_image_program(uint32_t image_address)
|
||||
{
|
||||
uint8_t image_char = 0;
|
||||
uint32_t image_index = 0;
|
||||
uint8_t line_buffer[256] = { 0 };
|
||||
uint8_t line_index = 0;
|
||||
recordStatus_t status = kRecordStatus_Fail;
|
||||
|
||||
/* Traverse the first time to erase target flash regions */
|
||||
intelhex_record_erase_target(image_address);
|
||||
|
||||
/* Clear globle variable */
|
||||
s_image_buffer_index = 0;
|
||||
s_image_start_address = 0;
|
||||
s_image_next_address = 0;
|
||||
s_image_base_address = 0;
|
||||
|
||||
/* Traverse the second time to program target */
|
||||
while (status != kRecordStatus_FlashOver)
|
||||
{
|
||||
image_char = read_flash_char(image_address, image_index);
|
||||
image_index++;
|
||||
|
||||
if (image_char == '\n')
|
||||
{
|
||||
status = intelhex_record_parse_line(line_buffer, line_index);
|
||||
if (status != kRecordStatus_Success)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
line_index = 0;
|
||||
|
||||
/* Build image and program target */
|
||||
status = intelhex_record_build_image(&s_new_record);
|
||||
|
||||
if (status == kRecordStatus_Fail)
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
}
|
||||
else if (image_char == '\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
line_buffer[line_index++] = image_char;
|
||||
}
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief parse one line of intelhex record image
|
||||
*
|
||||
* @param line one line of the intelhex record.
|
||||
* @param line_length the length of the line.
|
||||
* @return parse status
|
||||
*/
|
||||
static recordStatus_t intelhex_record_parse_line(uint8_t *line, uint8_t line_length)
|
||||
{
|
||||
uint32_t checksum = 0;
|
||||
uint32_t i = 0;
|
||||
intelhex_record_t *new_record = &s_new_record;
|
||||
|
||||
/* Must be at least a certain length */
|
||||
if (line_length < INTELHEX_MIN_LENGTH)
|
||||
{
|
||||
return kRecordStatus_InvalidLength;
|
||||
}
|
||||
|
||||
/* Start char must be ':' */
|
||||
if (line[0] != INTELHEX_START_CHAR)
|
||||
{
|
||||
return kRecordStatus_InvalidStart;
|
||||
}
|
||||
|
||||
/* Parse count field */
|
||||
new_record->dataCount = read_hex_byte(line, 1);
|
||||
checksum += new_record->dataCount;
|
||||
|
||||
/* verify the record length now that we know the count */
|
||||
if (line_length != 11 + new_record->dataCount * 2)
|
||||
{
|
||||
return kRecordStatus_InvalidLength;
|
||||
}
|
||||
|
||||
/* Read address */
|
||||
uint32_t address = 0;
|
||||
for (i = 0; i < 2; ++i)
|
||||
{
|
||||
uint8_t address_byte = read_hex_byte(line, INTELHEX_ADDRESS_START_CHAR_INDEX + i * 2);
|
||||
address = (address << 8) | address_byte;
|
||||
checksum += address_byte;
|
||||
}
|
||||
new_record->address = address;
|
||||
|
||||
/* Handle data type */
|
||||
new_record->type = read_hex_byte(line, INTELHEX_TYPE_START_CHAR_INDEX);
|
||||
checksum += new_record->type;
|
||||
switch (new_record->type)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
break;
|
||||
default:
|
||||
return kRecordStatus_InvalidType;
|
||||
}
|
||||
|
||||
/* Read data */
|
||||
if (new_record->dataCount)
|
||||
{
|
||||
for (i = 0; i < new_record->dataCount; ++i)
|
||||
{
|
||||
uint8_t data_byte = read_hex_byte(line, INTELHEX_DATA_START_CHAR_INDEX + i * 2);
|
||||
new_record->data[i] = data_byte;
|
||||
checksum += data_byte;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read and compare checksum byte */
|
||||
checksum = (~checksum + 1) & 0xff; /* low byte of one's complement of sum of other bytes */
|
||||
new_record->checksum = read_hex_byte(line, line_length - 2);
|
||||
if (checksum != new_record->checksum)
|
||||
{
|
||||
return kRecordStatus_InvalidChecksum;
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief build intelhex srecord image and flash target
|
||||
*
|
||||
* @param new_record one line of the intelhex record.
|
||||
* @return parse status
|
||||
*/
|
||||
static recordStatus_t intelhex_record_build_image(intelhex_record_t *new_record)
|
||||
{
|
||||
uint8_t is_data_record = 0;
|
||||
uint8_t is_entry_record = 0;
|
||||
uint8_t is_address_record = 0;
|
||||
uint8_t is_eof_record = 0;
|
||||
uint32_t status = 0;
|
||||
|
||||
if (new_record->type == INTELHEX_RECORD_DATA)
|
||||
{
|
||||
is_data_record = 1;
|
||||
}
|
||||
else if ((new_record->type == INTELHEX_RECORD_START_SEGMENT_ADDRESS) ||
|
||||
(new_record->type == INTELHEX_RECORD_START_LINEAR_ADDRESS))
|
||||
{
|
||||
is_entry_record = 1;
|
||||
}
|
||||
else if ((new_record->type == INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS) ||
|
||||
(new_record->type == INTELHEX_RECORD_EXTENDED_LINEAR_ADDRESS))
|
||||
{
|
||||
is_address_record = 1;
|
||||
}
|
||||
else if (new_record->type == INTELHEX_RECORD_END_OF_FILE)
|
||||
{
|
||||
is_eof_record = 1;
|
||||
}
|
||||
|
||||
s_image_base_address = 0;
|
||||
/* Handle 00 data record */
|
||||
if (is_data_record)
|
||||
{
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
/* If this record's data would overflow the collection buffer, or if the */
|
||||
/* record is not contiguous with the rest of the data in the collection */
|
||||
/* buffer, then flush the buffer to the target and restart. */
|
||||
if (((s_image_buffer_index + new_record->dataCount) > IMAGE_BUFFER_SIZE) ||
|
||||
(new_record->address != s_image_next_address))
|
||||
{
|
||||
/* flush the buffer to the target */
|
||||
status = handle_writeMemory_command(s_image_start_address + s_image_base_address, s_image_buffer,
|
||||
s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
|
||||
if (status == kStatus_Fail)
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Capture addresses when starting an empty buffer. */
|
||||
if (s_image_buffer_index == 0)
|
||||
{
|
||||
s_image_start_address = new_record->address;
|
||||
s_image_next_address = s_image_start_address;
|
||||
}
|
||||
|
||||
/* Copy record data into place in the collection buffer and update */
|
||||
/* size and address. */
|
||||
memcpy(&s_image_buffer[s_image_buffer_index], new_record->data, new_record->dataCount);
|
||||
s_image_buffer_index += new_record->dataCount;
|
||||
s_image_next_address += new_record->dataCount;
|
||||
}
|
||||
/* Hnadle 02, 04 record */
|
||||
else if (is_address_record)
|
||||
{
|
||||
/* If there are data in the collection buffer, then flush the buffer to the target. */
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
status = handle_writeMemory_command(s_image_start_address + s_image_base_address, s_image_buffer,
|
||||
s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
|
||||
if (status == kStatus_Fail)
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* extended address stored at data field. */
|
||||
s_image_base_address = (new_record->data[0] << 8) | new_record->data[1];
|
||||
if (new_record->type == INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS)
|
||||
{
|
||||
s_image_base_address <<= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_image_base_address <<= 16;
|
||||
}
|
||||
}
|
||||
/* Handle 03, 05 record */
|
||||
else if (is_entry_record)
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
/* Handle 01 record */
|
||||
else if (is_eof_record)
|
||||
{
|
||||
/* Flash any leftover data to target. */
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
status = handle_writeMemory_command(s_image_start_address, s_image_buffer, s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
|
||||
if (status == kStatus_Fail)
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
|
||||
return kRecordStatus_FlashOver;
|
||||
}
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief erase target flash before program target
|
||||
*
|
||||
* @param image_address address of the image in host flash.
|
||||
* @return parse status
|
||||
*/
|
||||
static recordStatus_t intelhex_record_erase_target(uint32_t image_address)
|
||||
{
|
||||
uint8_t image_char = 0;
|
||||
uint32_t image_index = 0;
|
||||
uint8_t line_buffer[256] = { 0 };
|
||||
uint8_t line_index = 0;
|
||||
recordStatus_t status = kRecordStatus_Fail;
|
||||
|
||||
while (status != kRecordStatus_EraseOver)
|
||||
{
|
||||
image_char = read_flash_char(image_address, image_index);
|
||||
image_index++;
|
||||
|
||||
if (image_char == '\n')
|
||||
{
|
||||
status = intelhex_record_parse_line(line_buffer, line_index);
|
||||
if (status != kRecordStatus_Success)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
line_index = 0;
|
||||
|
||||
/* Erase flash regions */
|
||||
status = intelhex_record_erase_region(&s_new_record);
|
||||
}
|
||||
else if (image_char == '\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
line_buffer[line_index++] = image_char;
|
||||
}
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief eraset flash region based on record
|
||||
*
|
||||
* @param new_record one line of the intelhex record.
|
||||
* @return parse status
|
||||
*/
|
||||
static recordStatus_t intelhex_record_erase_region(intelhex_record_t *new_record)
|
||||
{
|
||||
uint8_t is_data_record = 0;
|
||||
uint8_t is_entry_record = 0;
|
||||
uint8_t is_address_record = 0;
|
||||
uint8_t is_eof_record = 0;
|
||||
|
||||
if (new_record->type == INTELHEX_RECORD_DATA)
|
||||
{
|
||||
is_data_record = 1;
|
||||
}
|
||||
else if ((new_record->type == INTELHEX_RECORD_START_SEGMENT_ADDRESS) ||
|
||||
(new_record->type == INTELHEX_RECORD_START_LINEAR_ADDRESS))
|
||||
{
|
||||
is_entry_record = 1;
|
||||
}
|
||||
else if ((new_record->type == INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS) ||
|
||||
(new_record->type == INTELHEX_RECORD_EXTENDED_LINEAR_ADDRESS))
|
||||
{
|
||||
is_address_record = 1;
|
||||
}
|
||||
else if (new_record->type == INTELHEX_RECORD_END_OF_FILE)
|
||||
{
|
||||
is_eof_record = 1;
|
||||
}
|
||||
|
||||
s_image_base_address = 0;
|
||||
/* Handle 00 data record */
|
||||
if (is_data_record)
|
||||
{
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
/* If this record's data would overflow the collection buffer, or if the */
|
||||
/* record is not contiguous with the rest of the data in the collection */
|
||||
/* buffer, then erase flash region and restart. */
|
||||
if (((s_image_buffer_index + new_record->dataCount) > IMAGE_BUFFER_SIZE) ||
|
||||
(new_record->address != s_image_next_address))
|
||||
{
|
||||
/* Erase target flash region */
|
||||
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Capture addresses when starting an empty buffer. */
|
||||
if (s_image_buffer_index == 0)
|
||||
{
|
||||
s_image_start_address = new_record->address;
|
||||
s_image_next_address = s_image_start_address;
|
||||
}
|
||||
|
||||
/* update size and address. */
|
||||
s_image_buffer_index += new_record->dataCount;
|
||||
s_image_next_address += new_record->dataCount;
|
||||
}
|
||||
/* Hnadle 02, 04 record */
|
||||
else if (is_address_record)
|
||||
{
|
||||
/* If there are data in the collection buffer, then flush the buffer to the executable image. */
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
/* Erase target flash region */
|
||||
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
}
|
||||
|
||||
/* extended address stored at data field. */
|
||||
s_image_base_address = (new_record->data[0] << 8) | new_record->data[1];
|
||||
if (new_record->type == INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS)
|
||||
{
|
||||
s_image_base_address <<= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_image_base_address <<= 16;
|
||||
}
|
||||
}
|
||||
/* Handle 03, 05 record */
|
||||
else if (is_entry_record)
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
/* Handle 01 record */
|
||||
else if (is_eof_record)
|
||||
{
|
||||
/* Flash any leftover data to target. */
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
/* Erase target flash region */
|
||||
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
|
||||
return kRecordStatus_EraseOver;
|
||||
}
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
95
validation/embedded_host/src/image_program/intelhex_image.h
Normal file
95
validation/embedded_host/src/image_program/intelhex_image.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 __intelhex_image_H__
|
||||
#define __intelhex_image_H__
|
||||
|
||||
#include "executable_image.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
enum
|
||||
{
|
||||
/*! The required first character of a Intel Hex */
|
||||
INTELHEX_START_CHAR = ':',
|
||||
|
||||
/*! The minimum length of a Hex. This is the start char (1) + datacount (2) + addr (4) + type (2) + check sum (2).
|
||||
*/
|
||||
INTELHEX_MIN_LENGTH = 11,
|
||||
|
||||
/*! Index of the first character of the address field. */
|
||||
INTELHEX_ADDRESS_START_CHAR_INDEX = 3,
|
||||
|
||||
/*! Index of the first character of the record type field. */
|
||||
INTELHEX_TYPE_START_CHAR_INDEX = 7,
|
||||
|
||||
/*! Index of the first character of the record type field. */
|
||||
INTELHEX_DATA_START_CHAR_INDEX = 9
|
||||
};
|
||||
|
||||
/*! Intel Hex Record Type */
|
||||
enum
|
||||
{
|
||||
/*! Data Record, which contains data and a 16-bit start address for the data. */
|
||||
INTELHEX_RECORD_DATA = 0x00,
|
||||
|
||||
/*! End of File Record, which specifies the end of the hex file, and */
|
||||
/*! must occur exactly once per file in the last line of the file. */
|
||||
INTELHEX_RECORD_END_OF_FILE = 0x01,
|
||||
|
||||
/*! Extended Segment Address Record, which is used to specify bits 4- 19 of the Segment Base Address. */
|
||||
INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS = 0x02,
|
||||
|
||||
/*! Start Segment Address Record, which is used to specify the execution start address for the object file. */
|
||||
INTELHEX_RECORD_START_SEGMENT_ADDRESS = 0x03,
|
||||
|
||||
/*! Extended Linear Address Record, which is used to specify bits 16- 31 of the Linear Base Address. */
|
||||
INTELHEX_RECORD_EXTENDED_LINEAR_ADDRESS = 0x04,
|
||||
|
||||
/*! Start Linear Address Record, which is used to specify the execution start address for the object file. */
|
||||
INTELHEX_RECORD_START_LINEAR_ADDRESS = 0x05
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @brief parse srecord image */
|
||||
recordStatus_t intelhex_image_program(uint32_t image_address);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __intelhex_image_H__ */
|
||||
406
validation/embedded_host/src/image_program/srecord_image.c
Normal file
406
validation/embedded_host/src/image_program/srecord_image.c
Normal file
@@ -0,0 +1,406 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 "fsl_common.h"
|
||||
#include "srecord_image.h"
|
||||
#include "blsh/bllibc.h"
|
||||
#include "blsh/host_command.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
typedef struct _srecord_t
|
||||
{
|
||||
uint8_t type; /*!< Record number type, such as 9 for "S9", 3 for "S3" and so on.*/
|
||||
uint8_t count; /*!< Number of character pairs (bytes) from address through checksum.*/
|
||||
uint32_t address; /*!< The address specified as part of the S-record.*/
|
||||
uint8_t dataCount; /*!< Number of bytes of data.*/
|
||||
uint8_t data[256]; /*!< Pointer to data, or NULL if no data for this record type.*/
|
||||
uint8_t checksum; /*!< The checksum byte present in the S-record.*/
|
||||
} srecord_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
static srecord_t s_new_record = { 0 };
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
static recordStatus_t srecord_parse_line(uint8_t *line, uint8_t line_length);
|
||||
static recordStatus_t srecord_build_image(srecord_t *new_record);
|
||||
static recordStatus_t srecord_erase_target(uint32_t image_address);
|
||||
static recordStatus_t srecord_erase_region(srecord_t *new_record);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
recordStatus_t srecord_image_program(uint32_t image_address)
|
||||
{
|
||||
uint8_t image_char = 0;
|
||||
uint32_t image_index = 0;
|
||||
uint8_t line_buffer[256] = { 0 };
|
||||
uint8_t line_index = 0;
|
||||
recordStatus_t status = kRecordStatus_Fail;
|
||||
|
||||
/* Traverse the first time to erase target flash regions*/
|
||||
srecord_erase_target(image_address);
|
||||
|
||||
/* Clear globle variable*/
|
||||
s_image_buffer_index = 0;
|
||||
s_image_start_address = 0;
|
||||
s_image_next_address = 0;
|
||||
s_image_base_address = 0;
|
||||
|
||||
/* Traverse the second time to program target*/
|
||||
while (status != kRecordStatus_FlashOver)
|
||||
{
|
||||
image_char = read_flash_char(image_address, image_index);
|
||||
image_index++;
|
||||
|
||||
if (image_char == '\n')
|
||||
{
|
||||
status = srecord_parse_line(line_buffer, line_index);
|
||||
if (status != kRecordStatus_Success)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
line_index = 0;
|
||||
|
||||
/* Build image and flash target*/
|
||||
status = srecord_build_image(&s_new_record);
|
||||
|
||||
if (status == kRecordStatus_Fail)
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
}
|
||||
else if (image_char == '\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
line_buffer[line_index++] = image_char;
|
||||
}
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief parse one line of srecord record image
|
||||
*
|
||||
* @param line one line of the srecord record.
|
||||
* @param line_length the length of the line.
|
||||
* @return parse status
|
||||
*/
|
||||
static recordStatus_t srecord_parse_line(uint8_t *line, uint8_t line_length)
|
||||
{
|
||||
uint32_t checksum = 0;
|
||||
uint32_t i = 0;
|
||||
srecord_t *new_record = &s_new_record;
|
||||
|
||||
if (line_length < SRECORD_MIN_LENGTH)
|
||||
{
|
||||
return kRecordStatus_InvalidLength;
|
||||
}
|
||||
|
||||
if (line[0] != SRECORD_START_CHAR)
|
||||
{
|
||||
return kRecordStatus_InvalidStart;
|
||||
}
|
||||
|
||||
/* Parse type field*/
|
||||
if ((line[1] > '9') || (line[1] < '0'))
|
||||
{
|
||||
return kRecordStatus_InvalidType;
|
||||
}
|
||||
new_record->type = line[1] - '0';
|
||||
|
||||
/* Parse count field*/
|
||||
new_record->count = read_hex_byte(line, 2);
|
||||
checksum += new_record->count;
|
||||
|
||||
/* verify the record length now that we know the count*/
|
||||
if (line_length != 4 + new_record->count * 2)
|
||||
{
|
||||
return kRecordStatus_InvalidLength;
|
||||
}
|
||||
|
||||
/* Get address length*/
|
||||
uint8_t address_length = 0;
|
||||
uint8_t has_data = 0;
|
||||
switch (new_record->type)
|
||||
{
|
||||
case 0:
|
||||
address_length = 2;
|
||||
has_data = 1;
|
||||
break;
|
||||
case 1:
|
||||
address_length = 2;
|
||||
has_data = 1;
|
||||
break;
|
||||
case 2:
|
||||
address_length = 3;
|
||||
has_data = 1;
|
||||
break;
|
||||
case 3:
|
||||
address_length = 4;
|
||||
has_data = 1;
|
||||
break;
|
||||
case 5:
|
||||
address_length = 2;
|
||||
break;
|
||||
case 7:
|
||||
address_length = 4;
|
||||
break;
|
||||
case 8:
|
||||
address_length = 3;
|
||||
break;
|
||||
case 9:
|
||||
address_length = 2;
|
||||
break;
|
||||
default:
|
||||
return kRecordStatus_InvalidType;
|
||||
}
|
||||
|
||||
/* Read address*/
|
||||
uint32_t address = 0;
|
||||
for (i = 0; i < address_length; i++)
|
||||
{
|
||||
uint8_t address_byte = read_hex_byte(line, SRECORD_ADDRESS_START_CHAR_INDEX + i * 2);
|
||||
address = (address << 8) | address_byte;
|
||||
checksum += address_byte;
|
||||
}
|
||||
new_record->address = address;
|
||||
|
||||
/* Read data*/
|
||||
if (has_data)
|
||||
{
|
||||
int32_t data_start_char_index = 4 + address_length * 2;
|
||||
int32_t data_length = new_record->count - address_length - 1;
|
||||
|
||||
for (i = 0; i < data_length; i++)
|
||||
{
|
||||
uint8_t data_byte = read_hex_byte(line, data_start_char_index + i * 2);
|
||||
new_record->data[i] = data_byte;
|
||||
checksum += data_byte;
|
||||
}
|
||||
new_record->dataCount = data_length;
|
||||
}
|
||||
|
||||
/* Read and compare checksum byte*/
|
||||
checksum = (~checksum) & 0xff; /* low byte of one's complement of sum of other bytes */
|
||||
new_record->checksum = read_hex_byte(line, line_length - 2);
|
||||
if (checksum != new_record->checksum)
|
||||
{
|
||||
return kRecordStatus_InvalidChecksum;
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief build srecord image and flash target
|
||||
*
|
||||
* @param new_record one line of the intelhex record.
|
||||
* @return parse status
|
||||
*/
|
||||
static recordStatus_t srecord_build_image(srecord_t *new_record)
|
||||
{
|
||||
uint8_t is_data_record = 0;
|
||||
uint8_t has_data = 0;
|
||||
uint32_t status = 0;
|
||||
|
||||
/* Handle S3, 2, 1 records */
|
||||
if ((new_record->type == 3) || (new_record->type == 2) || (new_record->type == 1))
|
||||
{
|
||||
is_data_record = 1;
|
||||
}
|
||||
has_data = (new_record->data) && (new_record->dataCount);
|
||||
if (is_data_record && has_data)
|
||||
{
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
/* If this record's data would overflow the collection buffer, or if the */
|
||||
/* record is not contiguous with the rest of the data in the collection */
|
||||
/* buffer, then flush the buffer to the executable image and restart. */
|
||||
if (((s_image_buffer_index + new_record->dataCount) > IMAGE_BUFFER_SIZE) ||
|
||||
(new_record->address != s_image_next_address))
|
||||
{
|
||||
/* TO-DO flush */
|
||||
status = handle_writeMemory_command(s_image_start_address, s_image_buffer, s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
|
||||
if (status == kStatus_Fail)
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Capture addresses when starting an empty buffer. */
|
||||
if (s_image_buffer_index == 0)
|
||||
{
|
||||
s_image_start_address = new_record->address;
|
||||
s_image_next_address = s_image_start_address;
|
||||
}
|
||||
|
||||
/* Copy record data into place in the collection buffer and update */
|
||||
/* size and address. */
|
||||
memcpy(&s_image_buffer[s_image_buffer_index], new_record->data, new_record->dataCount);
|
||||
s_image_buffer_index += new_record->dataCount;
|
||||
s_image_next_address += new_record->dataCount;
|
||||
}
|
||||
else if ((new_record->type == 7) || (new_record->type == 8) || (new_record->type == 9))
|
||||
{
|
||||
/* Flash any leftover data to target. */
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
status = handle_writeMemory_command(s_image_start_address, s_image_buffer, s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
|
||||
if (status == kStatus_Fail)
|
||||
{
|
||||
return kRecordStatus_Fail;
|
||||
}
|
||||
|
||||
return kRecordStatus_FlashOver;
|
||||
}
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief erase target flash before program target
|
||||
*
|
||||
* @param image_address address of the image in host flash.
|
||||
* @return parse status
|
||||
*/
|
||||
static recordStatus_t srecord_erase_target(uint32_t image_address)
|
||||
{
|
||||
uint8_t image_char = 0;
|
||||
uint32_t image_index = 0;
|
||||
uint8_t line_buffer[256] = { 0 };
|
||||
uint8_t line_index = 0;
|
||||
recordStatus_t status = kRecordStatus_Fail;
|
||||
|
||||
while (status != kRecordStatus_EraseOver)
|
||||
{
|
||||
image_char = read_flash_char(image_address, image_index);
|
||||
image_index++;
|
||||
|
||||
if (image_char == '\n')
|
||||
{
|
||||
status = srecord_parse_line(line_buffer, line_index);
|
||||
if (status != kRecordStatus_Success)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
line_index = 0;
|
||||
|
||||
/* Erase target */
|
||||
status = srecord_erase_region(&s_new_record);
|
||||
}
|
||||
else if (image_char == '\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
line_buffer[line_index++] = image_char;
|
||||
}
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief eraset flash region based on record
|
||||
*
|
||||
* @param new_record one line of the intelhex record.
|
||||
* @return parse status
|
||||
*/
|
||||
static recordStatus_t srecord_erase_region(srecord_t *new_record)
|
||||
{
|
||||
uint8_t is_data_record = 0;
|
||||
uint8_t has_data = 0;
|
||||
|
||||
/* Handle S3, 2, 1 records */
|
||||
if ((new_record->type == 3) || (new_record->type == 2) || (new_record->type == 1))
|
||||
{
|
||||
is_data_record = 1;
|
||||
}
|
||||
has_data = (new_record->data) && (new_record->dataCount);
|
||||
if (is_data_record && has_data)
|
||||
{
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
/* If this record's data would overflow the collection buffer, or if the */
|
||||
/* record is not contiguous with the rest of the data in the collection */
|
||||
/* buffer, then erase the flash region and restart. */
|
||||
if (((s_image_buffer_index + new_record->dataCount) > IMAGE_BUFFER_SIZE) ||
|
||||
(new_record->address != s_image_next_address))
|
||||
{
|
||||
/* Erase target flash region */
|
||||
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Capture addresses when starting an empty buffer. */
|
||||
if (s_image_buffer_index == 0)
|
||||
{
|
||||
s_image_start_address = new_record->address;
|
||||
s_image_next_address = s_image_start_address;
|
||||
}
|
||||
|
||||
/* Update size and address. */
|
||||
s_image_buffer_index += new_record->dataCount;
|
||||
s_image_next_address += new_record->dataCount;
|
||||
}
|
||||
else if ((new_record->type == 7) || (new_record->type == 8) || (new_record->type == 9))
|
||||
{
|
||||
/* Erase target flash region */
|
||||
if (s_image_buffer_index)
|
||||
{
|
||||
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
|
||||
s_image_buffer_index = 0;
|
||||
|
||||
return kRecordStatus_EraseOver;
|
||||
}
|
||||
}
|
||||
|
||||
return kRecordStatus_Success;
|
||||
}
|
||||
65
validation/embedded_host/src/image_program/srecord_image.h
Normal file
65
validation/embedded_host/src/image_program/srecord_image.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 __srecord_image_H__
|
||||
#define __srecord_image_H__
|
||||
|
||||
#include "executable_image.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
enum
|
||||
{
|
||||
/*! The required first character of an S-record. */
|
||||
SRECORD_START_CHAR = 'S',
|
||||
|
||||
/*! The minimum length of a S-record. This is the type (2) + count (2) + addr (4) + cksum (2). */
|
||||
SRECORD_MIN_LENGTH = 10,
|
||||
|
||||
/*! Index of the first character of the address field. */
|
||||
SRECORD_ADDRESS_START_CHAR_INDEX = 4
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @brief parse srecord image */
|
||||
recordStatus_t srecord_image_program(uint32_t image_address);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __srecord_image_H__ */
|
||||
204
validation/embedded_host/src/main.c
Normal file
204
validation/embedded_host/src/main.c
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2014, 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 "host_hardware.h"
|
||||
#include "blsh/host_blsh_cmd.h"
|
||||
#include "blsh/host_command.h"
|
||||
#include "microseconds/microseconds.h"
|
||||
#include "board.h"
|
||||
#include "gpio/fsl_gpio.h"
|
||||
#include "executable_image.h"
|
||||
|
||||
enum
|
||||
{
|
||||
kSwitchStatus_Idle = 0,
|
||||
kSwitchStatus_Lock = 1,
|
||||
kSwitchStatus_Confirm = 2
|
||||
};
|
||||
|
||||
static uint32_t s_switch2_press = 0;
|
||||
static uint32_t s_switch3_press = kSPI_mode;
|
||||
|
||||
void embedded_host_blsh_init(void);
|
||||
void flash_image_status_callback(recordStatus_t status);
|
||||
|
||||
/*!
|
||||
* @brief embedded host main function.
|
||||
*/
|
||||
#if defined(__CC_ARM) || defined(__GNUC__)
|
||||
int main(void)
|
||||
#else
|
||||
void main(void)
|
||||
#endif
|
||||
{
|
||||
hardware_init();
|
||||
|
||||
host_blsh_cmd_init();
|
||||
embedded_host_blsh_init();
|
||||
|
||||
while (!blsh_exit())
|
||||
{
|
||||
/* Wait blsh command */
|
||||
blsh_run();
|
||||
|
||||
/* Fisrt press to lock the selection */
|
||||
if (s_switch2_press == kSwitchStatus_Lock)
|
||||
{
|
||||
LED_YELLOW_ON;
|
||||
}
|
||||
/* Second press to ensure the selection */
|
||||
else if (s_switch2_press == kSwitchStatus_Confirm)
|
||||
{
|
||||
microseconds_init();
|
||||
/* Enter spi transfer mode */
|
||||
if (s_switch3_press == kSPI_mode)
|
||||
{
|
||||
configure_transfer_bus(kSPI_mode, 100);
|
||||
}
|
||||
/* Enter i2c transfer mode */
|
||||
else if (s_switch3_press == kI2C_mode)
|
||||
{
|
||||
configure_transfer_bus(kI2C_mode, 100);
|
||||
}
|
||||
/* Enter uart transfer mode */
|
||||
else if (s_switch3_press == kUART_mode)
|
||||
{
|
||||
configure_transfer_bus(kUART_mode, 57600);
|
||||
}
|
||||
else if (s_switch3_press == kCAN_mode)
|
||||
{
|
||||
configure_transfer_bus(kCAN_mode, 125);
|
||||
}
|
||||
|
||||
flash_image(flash_image_status_callback);
|
||||
microseconds_shutdown();
|
||||
|
||||
LED_YELLOW_OFF;
|
||||
s_switch2_press = kSwitchStatus_Idle;
|
||||
}
|
||||
}
|
||||
|
||||
#if (defined(__CC_ARM) || defined(__GNUC__))
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void flash_image_status_callback(recordStatus_t status)
|
||||
{
|
||||
if (status != kRecordStatus_Success)
|
||||
{
|
||||
LED_RED_ON;
|
||||
blsh_printf("\r\n Flash image fail! \r\n > ");
|
||||
}
|
||||
else
|
||||
{
|
||||
LED_YELLOW_OFF;
|
||||
LED_GREEN_OFF;
|
||||
LED_BLUE_OFF;
|
||||
LED_RED_OFF;
|
||||
s_switch3_press = kSPI_mode;
|
||||
|
||||
blsh_printf("\r\n Flash image success. \r\n > ");
|
||||
}
|
||||
}
|
||||
|
||||
void embedded_host_blsh_init(void)
|
||||
{
|
||||
command_add(&flash_image_cmd);
|
||||
command_add(&write_memory_cmd);
|
||||
command_add(&read_memory_cmd);
|
||||
command_add(&fill_memory_cmd);
|
||||
command_add(&flash_security_disable_cmd);
|
||||
command_add(&flash_erase_all_unsecure_cmd);
|
||||
command_add(&flash_erase_all_cmd);
|
||||
command_add(&flash_erase_region_cmd);
|
||||
command_add(&execute_cmd);
|
||||
command_add(&call_cmd);
|
||||
command_add(&flash_program_once_cmd);
|
||||
command_add(&flash_read_once_cmd);
|
||||
command_add(&flash_read_resource_cmd);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Switch interrupt irq hander.
|
||||
*/
|
||||
void BOARD_SW_IRQ_HANDLER(void)
|
||||
{
|
||||
/* Clear external interrupt flag. */
|
||||
uint32_t int_flags = GPIO_GetPinsInterruptFlags(BOARD_SW3_GPIO);
|
||||
GPIO_ClearPinsInterruptFlags(BOARD_SW3_GPIO, 1U << BOARD_SW3_GPIO_PIN);
|
||||
GPIO_ClearPinsInterruptFlags(BOARD_SW2_GPIO, 1U << BOARD_SW2_GPIO_PIN);
|
||||
|
||||
if (int_flags & BOARD_SW2_MASK)
|
||||
{
|
||||
s_switch2_press++;
|
||||
|
||||
if (s_switch2_press > kSwitchStatus_Confirm)
|
||||
{
|
||||
s_switch2_press = kSwitchStatus_Idle;
|
||||
}
|
||||
}
|
||||
else if (int_flags & BOARD_SW3_MASK)
|
||||
{
|
||||
if (!s_switch2_press)
|
||||
{
|
||||
if (++s_switch3_press > kCAN_mode)
|
||||
{
|
||||
s_switch3_press = kSPI_mode;
|
||||
}
|
||||
|
||||
if (s_switch3_press == kSPI_mode)
|
||||
{
|
||||
LED_GREEN_OFF;
|
||||
LED_BLUE_OFF;
|
||||
}
|
||||
if (s_switch3_press == kI2C_mode)
|
||||
{
|
||||
LED_GREEN_ON;
|
||||
LED_BLUE_OFF;
|
||||
}
|
||||
else if (s_switch3_press == kUART_mode)
|
||||
{
|
||||
LED_GREEN_OFF;
|
||||
LED_BLUE_ON;
|
||||
}
|
||||
else if (s_switch3_press == kCAN_mode)
|
||||
{
|
||||
LED_GREEN_ON;
|
||||
LED_BLUE_ON;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_switch2_press = kSwitchStatus_Idle;
|
||||
LED_YELLOW_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user