GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)
This commit is contained in:
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __LOTUS_ATF_H__
|
||||
#define __LOTUS_ATF_H__
|
||||
|
||||
/**************************************************************/
|
||||
#define ARM_BOOT_SMC_CALL 0x8400ff02
|
||||
|
||||
#define SECURE 0x0
|
||||
#define NON_SECURE 0x1
|
||||
|
||||
#define EP_EE_MASK 0x2
|
||||
#define EP_EE_LITTLE 0x0
|
||||
#define EP_EE_BIG 0x2
|
||||
#define ep_get_ee(x) ((x) & EP_EE_MASK)
|
||||
#define ep_set_ee(x, ee) ((x) = ((x) & ~EP_EE_MASK) | (ee))
|
||||
|
||||
/* CPSR/SPSR definitions */
|
||||
#define DAIF_FIQ_BIT (1 << 0)
|
||||
#define DAIF_IRQ_BIT (1 << 1)
|
||||
#define DAIF_ABT_BIT (1 << 2)
|
||||
#define DAIF_DBG_BIT (1 << 3)
|
||||
#define SPSR_DAIF_SHIFT 6
|
||||
#define SPSR_DAIF_MASK 0xf
|
||||
|
||||
#define SPSR_AIF_SHIFT 6
|
||||
#define SPSR_AIF_MASK 0x7
|
||||
|
||||
#define SPSR_E_SHIFT 9
|
||||
#define SPSR_E_MASK 0x1
|
||||
#define SPSR_E_LITTLE 0x0
|
||||
#define SPSR_E_BIG 0x1
|
||||
|
||||
#define SPSR_T_SHIFT 5
|
||||
#define SPSR_T_MASK 0x1
|
||||
#define SPSR_T_ARM 0x0
|
||||
#define SPSR_T_THUMB 0x1
|
||||
|
||||
#define MODE_SP_SHIFT 0x0
|
||||
#define MODE_SP_MASK 0x1
|
||||
#define MODE_SP_EL0 0x0
|
||||
#define MODE_SP_ELX 0x1
|
||||
|
||||
#define MODE_RW_SHIFT 0x4
|
||||
#define MODE_RW_MASK 0x1
|
||||
#define MODE_RW_64 0x0
|
||||
#define MODE_RW_32 0x1
|
||||
|
||||
#define MODE_EL_SHIFT 0x2
|
||||
#define MODE_EL_MASK 0x3
|
||||
#define MODE_EL3 0x3
|
||||
#define MODE_EL2 0x2
|
||||
#define MODE_EL1 0x1
|
||||
#define MODE_EL0 0x0
|
||||
|
||||
#define MODE32_SHIFT 0
|
||||
#define MODE32_MASK 0xf
|
||||
#define MODE32_USR 0x0
|
||||
#define MODE32_FIQ 0x1
|
||||
#define MODE32_IRQ 0x2
|
||||
#define MODE32_SVC 0x3
|
||||
#define MODE32_MON 0x6
|
||||
#define MODE32_ABT 0x7
|
||||
#define MODE32_HYP 0xa
|
||||
#define MODE32_UND 0xb
|
||||
#define MODE32_SYS 0xf
|
||||
|
||||
/* Param header types */
|
||||
#define PARAM_EP 0x01UL
|
||||
#define PARAM_IMAGE_BINARY 0x02UL
|
||||
#define PARAM_BL31 0x03UL
|
||||
#define PARAM_BL_LOAD_INFO 0x04UL
|
||||
#define PARAM_BL_PARAMS 0x05UL
|
||||
#define PARAM_PSCI_LIB_ARGS 0x06UL
|
||||
#define PARAM_SP_IMAGE_BOOT_INFO 0x07UL
|
||||
|
||||
/* Param header version */
|
||||
#define VERSION_1 0x01UL
|
||||
#define VERSION_2 0x02UL
|
||||
|
||||
/* Firmware Image Package */
|
||||
#define FIP_IMAGE_ID 0UL
|
||||
|
||||
/* Trusted Boot Firmware BL2 */
|
||||
#define BL2_IMAGE_ID 1UL
|
||||
|
||||
/* SCP Firmware SCP_BL2 */
|
||||
#define SCP_BL2_IMAGE_ID 2UL
|
||||
|
||||
/* EL3 Runtime Firmware BL31 */
|
||||
#define BL31_IMAGE_ID 3UL
|
||||
|
||||
/* Secure Payload BL32 (Trusted OS) */
|
||||
#define BL32_IMAGE_ID 4UL
|
||||
|
||||
/* Non-Trusted Firmware BL33 */
|
||||
#define BL33_IMAGE_ID 5UL
|
||||
|
||||
|
||||
#define DISABLE_ALL_EXCEPTIONS \
|
||||
(DAIF_FIQ_BIT | DAIF_IRQ_BIT | DAIF_ABT_BIT | DAIF_DBG_BIT)
|
||||
|
||||
#define PARAM_EP_SECURITY_MASK 0x1
|
||||
#define get_security_state(x) ((x) & PARAM_EP_SECURITY_MASK)
|
||||
#define set_security_state(x, security) \
|
||||
((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security))
|
||||
|
||||
#define spsr_64(el, sp, daif) \
|
||||
(MODE_RW_64 << MODE_RW_SHIFT | ((el) & MODE_EL_MASK) << MODE_EL_SHIFT | \
|
||||
((sp) & MODE_SP_MASK) << MODE_SP_SHIFT | ((daif) & SPSR_DAIF_MASK) << SPSR_DAIF_SHIFT)
|
||||
|
||||
#define spsr_mode32(mode, isa, endian, aif) (MODE_RW_32 << MODE_RW_SHIFT | \
|
||||
((mode) & MODE32_MASK) << MODE32_SHIFT | ((isa) & SPSR_T_MASK) << SPSR_T_SHIFT | \
|
||||
((endian) & SPSR_E_MASK) << SPSR_E_SHIFT | ((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT)
|
||||
|
||||
|
||||
/* Length of a node address (an IEEE 802 address). */
|
||||
#define _UUID_NODE_LEN 6
|
||||
|
||||
#define FIP_MAX_FILES 3
|
||||
|
||||
/* TODO: Update this number as required */
|
||||
#define TOC_HEADER_SERIAL_NUMBER 0x12345678
|
||||
|
||||
#define FLAG_FILENAME (1 << 0)
|
||||
|
||||
/* This is used as a signature to validate the blob header */
|
||||
#define TOC_HEADER_NAME 0xAA640001
|
||||
|
||||
/* ToC Entry UUIDs */
|
||||
#define UUID_TRUSTED_BOOT_FIRMWARE_BL2 \
|
||||
{0x0becf95f, 0x224d, 0x4d3e, 0xa5, 0x44, {0xc3, 0x9d, 0x81, 0xc7, 0x3f, 0x0a} }
|
||||
#define UUID_SCP_FIRMWARE_BL30 \
|
||||
{0x3dfd6697, 0xbe89, 0x49e8, 0xae, 0x5d, {0x78, 0xa1, 0x40, 0x60, 0x82, 0x13} }
|
||||
#define UUID_EL3_RUNTIME_FIRMWARE_BL31 \
|
||||
{0x6d08d447, 0xfe4c, 0x4698, 0x9b, 0x95, {0x29, 0x50, 0xcb, 0xbd, 0x5a, 0x00} }
|
||||
#define UUID_SECURE_PAYLOAD_BL32 \
|
||||
{0x89e1d005, 0xdc53, 0x4713, 0x8d, 0x2b, {0x50, 0x0a, 0x4b, 0x7a, 0x3e, 0x38} }
|
||||
#define UUID_NON_TRUSTED_FIRMWARE_BL33 \
|
||||
{0xa7eed0d6, 0xeafc, 0x4bd5, 0x97, 0x82, {0x99, 0x34, 0xf2, 0x34, 0xb6, 0xe4} }
|
||||
|
||||
/**************************************************************/
|
||||
/* XXX namespace pollution? */
|
||||
typedef struct uuuid uuid_t;
|
||||
|
||||
/**************************************************************/
|
||||
/*
|
||||
* See also:
|
||||
* http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
|
||||
* http://www.opengroup.org/onlinepubs/009629399/apdxa.htm
|
||||
*
|
||||
* A DCE 1.1 compatible source representation of UUIDs.
|
||||
*/
|
||||
struct uuuid {
|
||||
uint32_t time_low;
|
||||
uint16_t time_mid;
|
||||
uint16_t time_hi_and_version;
|
||||
uint8_t clock_seq_hi_and_reserved;
|
||||
uint8_t clock_seq_low;
|
||||
uint8_t node[_UUID_NODE_LEN];
|
||||
};
|
||||
|
||||
typedef struct entry_lookup_list {
|
||||
const char *name;
|
||||
uuid_t name_uuid;
|
||||
const char *command_line_name;
|
||||
struct file_info *info;
|
||||
unsigned int flags;
|
||||
} entry_lookup_list_t;
|
||||
|
||||
typedef struct file_info {
|
||||
uuid_t name_uuid;
|
||||
const char *filename;
|
||||
unsigned int size;
|
||||
void *image_buffer;
|
||||
entry_lookup_list_t *entry;
|
||||
} file_info_t;
|
||||
|
||||
typedef struct fip_toc_header {
|
||||
uint32_t name;
|
||||
uint32_t serial_number;
|
||||
uint64_t flags;
|
||||
} fip_toc_header_t;
|
||||
|
||||
typedef struct fip_toc_entry {
|
||||
uuid_t uuid;
|
||||
uint64_t offset_address;
|
||||
uint64_t size;
|
||||
uint64_t flags;
|
||||
} fip_toc_entry_t;
|
||||
|
||||
typedef struct aapcs64_params {
|
||||
uint64_t arg0;
|
||||
uint64_t arg1;
|
||||
uint64_t arg2;
|
||||
uint64_t arg3;
|
||||
uint64_t arg4;
|
||||
uint64_t arg5;
|
||||
uint64_t arg6;
|
||||
uint64_t arg7;
|
||||
} aapcs64_params_t;
|
||||
|
||||
typedef struct aapcs32_params {
|
||||
uint64_t arg0;
|
||||
uint64_t arg1;
|
||||
uint64_t arg2;
|
||||
uint64_t arg3;
|
||||
} aapcs32_params_t;
|
||||
|
||||
/***************************************************************************
|
||||
* This structure provides version information and the size of the
|
||||
* structure, attributes for the structure it represents
|
||||
***************************************************************************/
|
||||
typedef struct param_header {
|
||||
uint8_t type; /* type of the structure */
|
||||
uint8_t version; /* version of this structure */
|
||||
uint16_t size; /* size of this structure in bytes */
|
||||
uint32_t attr; /* attributes: unused bits SBZ */
|
||||
} param_header_t;
|
||||
|
||||
/*****************************************************************************
|
||||
* This structure represents the superset of information needed while
|
||||
* switching exception levels. The only two mechanisms to do so are
|
||||
* ERET & SMC. Security state is indicated using bit zero of header
|
||||
* attribute
|
||||
* NOTE: BL1 expects entrypoint followed by spsr at an offset from the start
|
||||
* of this structure defined by the macro `ENTRY_POINT_INFO_PC_OFFSET` while
|
||||
* processing SMC to jump to BL31.
|
||||
*****************************************************************************/
|
||||
typedef struct entry_point_info {
|
||||
param_header_t h;
|
||||
uint64_t pc;
|
||||
uint32_t spsr;
|
||||
aapcs64_params_t args;
|
||||
} entry_point_info_t;
|
||||
|
||||
/*****************************************************************************
|
||||
* Image info binary provides information from the image loader that
|
||||
* can be used by the firmware to manage available trusted RAM.
|
||||
* More advanced firmware image formats can provide additional
|
||||
* information that enables optimization or greater flexibility in the
|
||||
* common firmware code
|
||||
*****************************************************************************/
|
||||
typedef struct bl_image_info {
|
||||
param_header_t h;
|
||||
uint64_t image_base; /* physical address of base of image */
|
||||
uint32_t image_size; /* bytes read from image file */
|
||||
uint32_t image_max_size;
|
||||
} bl_image_info_t;
|
||||
|
||||
/*****************************************************************************
|
||||
* The image descriptor struct definition.
|
||||
*****************************************************************************/
|
||||
/* BL image node in the BL image execution sequence */
|
||||
typedef struct bl_params_node {
|
||||
unsigned int image_id;
|
||||
bl_image_info_t *image_info __attribute((aligned (8)));
|
||||
entry_point_info_t *ep_info __attribute((aligned (8)));
|
||||
struct bl_params_node *next_params_info __attribute((aligned (8)));
|
||||
} bl_params_node_t;
|
||||
|
||||
/*
|
||||
* BL image head node in the BL image execution sequence
|
||||
* It is also used to pass information to next BL image.
|
||||
*/
|
||||
typedef struct bl_params {
|
||||
param_header_t h;
|
||||
bl_params_node_t *head __attribute((aligned (8)));
|
||||
} bl_params_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* This structure represents the superset of information that can be passed to
|
||||
* BL31 e.g. while passing control to it from BL2. The BL32 parameters will be
|
||||
* populated only if BL2 detects its presence. A pointer to a structure of this
|
||||
* type should be passed in X0 to BL31's cold boot entrypoint.
|
||||
*
|
||||
* Use of this structure and the X0 parameter is not mandatory: the BL31
|
||||
* platform code can use other mechanisms to provide the necessary information
|
||||
* about BL32 and BL33 to the common and SPD code.
|
||||
*
|
||||
* BL31 image information is mandatory if this structure is used. If either of
|
||||
* the optional BL32 and BL33 image information is not provided, this is
|
||||
* indicated by the respective image_info pointers being zero.
|
||||
******************************************************************************/
|
||||
typedef struct bl31_params {
|
||||
param_header_t h;
|
||||
uint64_t bl31_image_info;
|
||||
uint64_t bl32_ep_info;
|
||||
uint64_t bl32_image_info;
|
||||
uint64_t bl33_ep_info;
|
||||
uint64_t bl33_image_info;
|
||||
} bl31_params_t;
|
||||
|
||||
typedef struct smc_cmd_args {
|
||||
uint32_t arg1;
|
||||
uint32_t arg2;
|
||||
uint32_t arg3;
|
||||
uint32_t arg4;
|
||||
uint32_t arg5;
|
||||
}smc_cmd_args_t;
|
||||
|
||||
#define BL33_IMG_ARM32 32
|
||||
#define BL33_IMG_ARM64 64
|
||||
|
||||
#include <image.h>
|
||||
|
||||
void run_bl31(bootm_headers_t *images, uint32_t machid);
|
||||
|
||||
#endif /* __LOTUS_ATF_H__ */
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef LOTUS_CHIP_H
|
||||
#define LOTUS_CHIP_H
|
||||
|
||||
unsigned int get_chipid(void);
|
||||
|
||||
#endif /* LOTUS_CHIP_H */
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __CPU_COMMON_H__
|
||||
#define __CPU_COMMON_H__
|
||||
|
||||
#include <command.h>
|
||||
#include <linux/lotus/hw_decompress.h>
|
||||
|
||||
#ifdef CONFIG_EMMC
|
||||
extern int target_dev;
|
||||
extern int target_paratition;
|
||||
#endif
|
||||
|
||||
void reset_cpu(ulong addr);
|
||||
void uart_early_init(void);
|
||||
void uart_early_puts(const char *ss);
|
||||
|
||||
void download_boot(void);
|
||||
void show_boot_timestamp(void);
|
||||
|
||||
#ifdef CONFIG_BSP_NAND_SPL
|
||||
extern uint32_t crc32(uint32_t crc, const char *p, unsigned int len);
|
||||
|
||||
extern unsigned long __bss_start;
|
||||
extern unsigned char _blank_zone_end[];
|
||||
extern unsigned long _blank_crc_start;
|
||||
#endif
|
||||
extern unsigned char input_data[];
|
||||
extern unsigned char input_data_end[];
|
||||
extern unsigned long _armboot_start;
|
||||
extern int sdhci_add_port(int index, u32 regbase, u32 freq);
|
||||
extern int lotus_mmc_init(int index);
|
||||
|
||||
#if (CONFIG_AUTO_UPDATE == 1)
|
||||
extern int do_auto_update(void);
|
||||
extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
|
||||
#endif /* CONFIG_AUTO_UPDATE */
|
||||
|
||||
#ifdef CONFIG_GENERIC_MMC
|
||||
extern int mci_probe(int dev_num);
|
||||
#endif /* CONFIG_GENERIC_MMC */
|
||||
|
||||
#ifdef CONFIG_SUPPORT_EMMC_BOOT
|
||||
extern int mci_add_port(int index, u32 reg_base, u32 freq);
|
||||
#endif /* CONFIG_SUPPORT_EMMC_BOOT */
|
||||
|
||||
#ifdef CONFIG_AUTO_SD_UPDATE
|
||||
extern int mci_add_port(int index, u32 reg_base, u32 freq);
|
||||
#endif /* CONFIG_AUTO_SD_UPDATE */
|
||||
|
||||
extern int mmc_phy_init(void);
|
||||
|
||||
#ifdef CONFIG_CMD_NAND
|
||||
extern int nand_saveenv(void);
|
||||
extern void nand_env_relocate_spec(void);
|
||||
#endif /* CONFIG_CMD_NAND */
|
||||
|
||||
#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
|
||||
extern int sf_saveenv(void);
|
||||
extern void sf_env_relocate_spec(void);
|
||||
#endif /* CONFIG_ENV_IS_IN_SPI_FLASH */
|
||||
|
||||
#ifdef CONFIG_ENV_IS_IN_MMC
|
||||
extern int emmc_saveenv(void);
|
||||
extern void emmc_env_relocate_spec(void);
|
||||
#endif /* CONFIG_ENV_IS_IN_MMC */
|
||||
|
||||
#ifdef CONFIG_ENV_IS_IN_UFS
|
||||
extern int ufs_saveenv(void);
|
||||
extern void ufs_env_relocate_spec(void);
|
||||
#endif /* CONFIG_ENV_IS_IN_UFS */
|
||||
|
||||
#ifdef CONFIG_HWDEC
|
||||
extern unsigned int hw_dec_type;
|
||||
extern void hw_dec_init(void);
|
||||
extern void hw_dec_uinit(void);
|
||||
|
||||
#endif /* CONFIG_HWDEC */
|
||||
|
||||
#endif /* __CPU_COMMON_H__ */
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
#ifndef CYCLE_H
|
||||
#define CYCLE_H
|
||||
|
||||
#include <common.h>
|
||||
|
||||
int getcycledata(unsigned long src, unsigned long src_bak, unsigned int src_len,
|
||||
unsigned long dst);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __FLASH_READ_H
|
||||
#define __FLASH_READ_H
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/*
|
||||
* read flash into out_addr from offset.
|
||||
* note:
|
||||
* 1. offset should aligned with FLASH_ALIGNED_SIZE
|
||||
* 2. if size is not aligned with FLASH_ALIGNED_SIZE,
|
||||
* system will read (((size / FLASH_ALIGNED_SIZE) + 1) * FLASH_ALIGNED_SIZE) content to out_addr
|
||||
*/
|
||||
int flash_read(unsigned long offset, unsigned int size, unsigned char *out_addr);
|
||||
|
||||
/*
|
||||
* read flash into out_addr from offset.
|
||||
* note:
|
||||
* 1. offset and size should aligned with FLASH_ALIGNED_SIZE
|
||||
*/
|
||||
int flash_read_aligned(unsigned long offset, unsigned int size, unsigned char *out_addr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
#ifndef __FMC_H__
|
||||
#define __FMC_H__
|
||||
|
||||
#include <spi_flash.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
|
||||
struct spi_flash *fmc100_spi_nor_probe(struct mtd_info_ex **);
|
||||
struct mtd_info_ex *fmc100_get_spi_nor_info(struct spi_flash *);
|
||||
|
||||
#endif /* End of __FMC_H__ */
|
||||
|
||||
@@ -0,0 +1,494 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
#ifndef __FMC_COMMON_H__
|
||||
#define __FMC_COMMON_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#define _32B 32
|
||||
#define _64B 64
|
||||
#define _128B 128
|
||||
#define _218B 218
|
||||
#define _224B 224
|
||||
#define _232B 232
|
||||
#define _256B 256
|
||||
#define _448B 448
|
||||
#define _512B 512
|
||||
#define _640B 640
|
||||
#define _744B 744
|
||||
#define _1K 1024
|
||||
#define _1280B 1280
|
||||
#define _2K 2048
|
||||
#define _4K 4096
|
||||
#define _8K 8192
|
||||
#define _16K 16384
|
||||
#define _32K 32768
|
||||
#define _64K 0x10000UL
|
||||
#define _128K 0x20000UL
|
||||
#define _256K 0x40000UL
|
||||
#define _512K 0x80000UL
|
||||
#define _1M 0x100000UL
|
||||
#define _2M 0x200000UL
|
||||
#define _4M 0x400000UL
|
||||
#define _8M 0x800000UL
|
||||
#define _16M 0x1000000UL
|
||||
#define _32M 0x2000000UL
|
||||
#define _64M 0x4000000UL
|
||||
#define _128M 0x8000000UL
|
||||
#define _256M 0x10000000UL
|
||||
#define _512M 0x20000000UL
|
||||
#define _1G 0x40000000ULL
|
||||
#define _2G 0x80000000ULL
|
||||
#define _4G 0x100000000ULL
|
||||
#define _8G 0x200000000ULL
|
||||
#define _16G 0x400000000ULL
|
||||
#define _64G 0x1000000000ULL
|
||||
|
||||
#define ECC_TYPE_0BIT 0x0
|
||||
#define ECC_TYPE_8BIT 0x1
|
||||
#define ECC_TYPE_16BIT 0x2
|
||||
#define ECC_TYPE_24BIT 0x3
|
||||
#define ECC_TYPE_28BIT 0x4
|
||||
#define ECC_TYPE_40BIT 0x5
|
||||
#define ECC_TYPE_64BIT 0x6
|
||||
|
||||
#define PAGE_SIZE_2KB 0x0
|
||||
#define PAGE_SIZE_4KB 0x1
|
||||
#define PAGE_SIZE_8KB 0x2
|
||||
#define PAGE_SIZE_16KB 0x3
|
||||
|
||||
/* id len */
|
||||
#define _2B 2
|
||||
#define _3B 3
|
||||
#define _4B 4
|
||||
#define _5B 5
|
||||
#define _6B 6
|
||||
#define _7B 7
|
||||
#define _8B 8
|
||||
#define _9B 9
|
||||
#define _10B 10
|
||||
#define _11B 11
|
||||
#define _12B 12
|
||||
|
||||
#ifdef CONFIG_FMC
|
||||
|
||||
/* FMC REG */
|
||||
#define FMC_CFG 0x08
|
||||
#define fmc_cfg_spi_nand_sel(_type) (((_size) & 0x3) << 1)
|
||||
#define fmc_cfg_spi_nor_addr_mode(_mode) ((_mode) << 10)
|
||||
#define fmc_cfg_block_size(_size) (((_size) & 0x3) << 8)
|
||||
#define fmc_cfg_ecc_type(_type) (((_type) & 0x7) << 5)
|
||||
#define fmc_cfg_page_size(_size) (((_size) & 0x3) << 11)
|
||||
#define fmc_cfg_flash_sel(_type) (((_type) & 0x3) << 3)
|
||||
#define fmc_cfg_op_mode(_mode) ((_mode) & 0x1)
|
||||
|
||||
#define SPI_NAND_MFR_OTHER 0x0
|
||||
#define SPI_NAND_MFR_WINBOND 0x1
|
||||
#define SPI_NAND_MFR_ESMT 0x2
|
||||
#define SPI_NAND_MFR_MICRON 0x3
|
||||
|
||||
#define SPI_NAND_SEL_SHIFT 11
|
||||
#define SPI_NAND_SEL_MASK (0x3 << SPI_NAND_SEL_SHIFT)
|
||||
|
||||
#define SPI_NOR_ADDR_MODE_3_BYTES 0x0
|
||||
#define SPI_NOR_ADDR_MODE_4_BYTES 0x1
|
||||
|
||||
#define SPI_NOR_ADDR_MODE_SHIFT 10
|
||||
#define SPI_NOR_ADDR_MODE_MASK (0x1 << SPI_NOR_ADDR_MODE_SHIFT)
|
||||
|
||||
#define BLOCK_SIZE_64_PAGE 0x0
|
||||
#define BLOCK_SIZE_128_PAGE 0x1
|
||||
#define BLOCK_SIZE_256_PAGE 0x2
|
||||
#define BLOCK_SIZE_512_PAGE 0x3
|
||||
|
||||
#define _64_PAGES 64
|
||||
#define _128_PAGES 128
|
||||
#define _256_PAGES 256
|
||||
#define _512_PAGES 512
|
||||
|
||||
#define EB_NORMAL 28
|
||||
#define EB_2K_16_BIT 4
|
||||
#define EB_4K_16_BIT 12
|
||||
|
||||
#define BLOCK_SIZE_MASK (0x3 << 8)
|
||||
|
||||
#define ECC_TYPE_SHIFT 5
|
||||
#define ECC_TYPE_MASK (0x7 << ECC_TYPE_SHIFT)
|
||||
|
||||
#define PAGE_SIZE_SHIFT 11
|
||||
#define PAGE_SIZE_MASK (0x3 << PAGE_SIZE_SHIFT)
|
||||
|
||||
#define FLASH_TYPE_SPI_NOR 0x0
|
||||
#define FLASH_TYPE_SPI_NAND 0x1
|
||||
#define FLASH_TYPE_NAND 0x2
|
||||
#define FLASH_TYPE_DEFAULT 0x3
|
||||
|
||||
#define FLASH_SEL_SHIFT 3
|
||||
#define FLASH_SEL_MASK (0x3 << FLASH_SEL_SHIFT)
|
||||
|
||||
#define OP_MODE_BOOT 0x0
|
||||
#define OP_MODE_NORMAL 0x1
|
||||
|
||||
#define OP_MODE_MASK 0x1
|
||||
|
||||
#define FMC_GLOBAL_CFG 0x0c
|
||||
#define FMC_GLOBAL_CFG_WP_ENABLE (1 << 11)
|
||||
#define FMC_GLOBAL_CFG_RANDOMIZER_EN (1 << 24)
|
||||
|
||||
#define FMC_SPI_TIMING_CFG 0x00
|
||||
#define timing_cfg_tcsh(_n) (((_n) & 0xf) << 8)
|
||||
#define timing_cfg_tcss(_n) (((_n) & 0xf) << 0)
|
||||
#define timing_cfg_tshsl(_n) (((_n) & 0xf) << 4)
|
||||
|
||||
#define CS_HOLD_TIME 0x6
|
||||
#define CS_SETUP_TIME 0x6
|
||||
#define CS_DESELECT_TIME 0xf
|
||||
|
||||
#define FMC_PND_PWIDTH_CFG 0x04
|
||||
#define pwidth_cfg_rw_hcnt(_n) (((_n) & 0xf) << 8)
|
||||
#define pwidth_cfg_r_lcnt(_n) (((_n) & 0xf) << 4)
|
||||
#define pwidth_cfg_w_lcnt(_n) ((_n) & 0xf)
|
||||
|
||||
#ifdef CONFIG_NAND_EDO_MODE
|
||||
#define RW_H_WIDTH 0x3
|
||||
#define R_L_WIDTH 0x2
|
||||
#define W_L_WIDTH 0x2
|
||||
#define NAND_EDO_MODE_SHIFT 9
|
||||
#define NAND_EDO_MODE_MASK (1<<NAND_EDO_MODE_SHIFT)
|
||||
#define set_nand_edo_mode_en(reg) ((reg) | NAND_EDO_MODE_MASK)
|
||||
#else
|
||||
#define RW_H_WIDTH 0xa
|
||||
#define R_L_WIDTH 0xa
|
||||
#define W_L_WIDTH 0xa
|
||||
#endif
|
||||
|
||||
#define FMC_INT 0x10
|
||||
#define FMC_INT_AHB_OP (1 << 7)
|
||||
#define FMC_INT_WR_LOCK (1 << 6)
|
||||
#define FMC_INT_DMA_ERR (1 << 5)
|
||||
#define FMC_INT_ERR_ALARM (1 << 4)
|
||||
#define FMC_INT_ERR_INVALID (1 << 3)
|
||||
#define FMC_INT_ERR_VALID (1 << 2)
|
||||
#define FMC_INT_OP_FAIL (1 << 1)
|
||||
#define FMC_INT_OP_DONE (1 << 0)
|
||||
|
||||
#define FMC_INT_EN 0x14
|
||||
#define FMC_INT_EN_AHB_OP (1 << 7)
|
||||
#define FMC_INT_EN_WR_LOCK (1 << 6)
|
||||
#define FMC_INT_EN_DMA_ERR (1 << 5)
|
||||
#define FMC_INT_EN_ERR_ALARM (1 << 4)
|
||||
#define FMC_INT_EN_ERR_INVALID (1 << 3)
|
||||
#define FMC_INT_EN_ERR_VALID (1 << 2)
|
||||
#define FMC_INT_EN_OP_FAIL (1 << 1)
|
||||
#define FMC_INT_EN_OP_DONE (1 << 0)
|
||||
|
||||
#define FMC_INT_CLR 0x28
|
||||
#define FMC_INT_CLR_AHB_OP (1 << 7)
|
||||
#define FMC_INT_CLR_WR_LOCK (1 << 6)
|
||||
#define FMC_INT_CLR_DMA_ERR (1 << 5)
|
||||
#define FMC_INT_CLR_ERR_ALARM (1 << 4)
|
||||
#define FMC_INT_CLR_ERR_INVALID (1 << 3)
|
||||
#define FMC_INT_CLR_ERR_VALID (1 << 2)
|
||||
#define FMC_INT_CLR_OP_FAIL (1 << 1)
|
||||
#define FMC_INT_CLR_OP_DONE (1 << 0)
|
||||
|
||||
#define FMC_INT_CLR_ALL 0xff
|
||||
|
||||
#define FMC_CMD 0x2c
|
||||
#define fmc_cmd_cmd2(_cmd) (((_cmd) & 0xff) << 8)
|
||||
#define fmc_cmd_cmd1(_cmd) ((_cmd) & 0xff)
|
||||
|
||||
#define FMC_ADDRH 0x20
|
||||
#define fmc_addrh_set(_addr) ((_addr) & 0xff)
|
||||
|
||||
#define FMC_ADDRL 0x24
|
||||
#define fmc_addrl_block_h_mask(_page) (((_page) & 0xffff) << 16)
|
||||
#define fmc_addrl_block_l_mask(_page) ((_page) & 0xffc0)
|
||||
|
||||
#define READ_ID_ADDR 0x00
|
||||
#define PROTECT_ADDR 0xa0
|
||||
#define FEATURE_ADDR 0xb0
|
||||
#define STATUS_ADDR 0xc0
|
||||
|
||||
#define FMC_OP_CFG 0x38
|
||||
#define op_cfg_fm_cs(_cs) ((_cs) << 10)
|
||||
#define op_cfg_force_cs_en(_en) ((_en) << 11)
|
||||
#define op_cfg_mem_if_type(_type) (((_type) & 0x7) << 4)
|
||||
#define op_cfg_addr_num(_addr) (((_addr) & 0x7) << 7)
|
||||
#define op_cfg_dummy_num(_dummy) ((_dummy) & 0xf)
|
||||
#define OP_CFG_OEN_EN (0x1 << 13)
|
||||
|
||||
#define IF_TYPE_STD 0x0
|
||||
#define IF_TYPE_DUAL 0x1
|
||||
#define IF_TYPE_DIO 0x2
|
||||
#define IF_TYPE_QUAD 0x3
|
||||
#define IF_TYPE_QIO 0x4
|
||||
#define IF_TYPE_DTR 0x4
|
||||
|
||||
#define IF_TYPE_SHIFT 4
|
||||
#define IF_TYPE_MASK (0x7 << IF_TYPE_SHIFT)
|
||||
|
||||
#define READ_ID_ADDR_NUM 1
|
||||
#define FEATURES_OP_ADDR_NUM 1
|
||||
#define STD_OP_ADDR_NUM 3
|
||||
|
||||
#define FMC_SPI_OP_ADDR 0x3c
|
||||
|
||||
#define FMC_DATA_NUM 0x30
|
||||
#define fmc_data_num_cnt(_n) ((_n) & 0x3fff)
|
||||
|
||||
#define SPI_NOR_SR_LEN 1 /* Status Register length */
|
||||
#define SPI_NOR_CR_LEN 1 /* Config Register length */
|
||||
#define FEATURES_DATA_LEN 1
|
||||
#define READ_OOB_BB_LEN 1
|
||||
#define MAX_SPI_NOR_ID_LEN 8
|
||||
#define MAX_NAND_ID_LEN 8
|
||||
#define MAX_SPI_NAND_ID_LEN 3
|
||||
|
||||
#define PROTECT_BRWD_MASK (1 << 7)
|
||||
#define PROTECT_BP3_MASK (1 << 6)
|
||||
#define PROTECT_BP2_MASK (1 << 5)
|
||||
#define PROTECT_BP1_MASK (1 << 4)
|
||||
#define PROTECT_BP0_MASK (1 << 3)
|
||||
|
||||
#define any_bp_enable(_val) ((PROTECT_BP3_MASK & _val) || \
|
||||
(PROTECT_BP2_MASK & _val) || (PROTECT_BP1_MASK & _val) || \
|
||||
(PROTECT_BP0_MASK & _val))
|
||||
|
||||
#define ALL_BP_MASK (PROTECT_BP3_MASK \
|
||||
| PROTECT_BP2_MASK \
|
||||
| PROTECT_BP1_MASK \
|
||||
| PROTECT_BP0_MASK)
|
||||
|
||||
#define FEATURE_ECC_ENABLE (1 << 4)
|
||||
#define FEATURE_QE_ENABLE (1 << 0)
|
||||
|
||||
/* read nand id or nand status, return from nand data length */
|
||||
#define MAX_NANDINFO_LEN 0x10
|
||||
|
||||
#define FMC_OP 0x34
|
||||
#define fmc_op_dummy_en(_en) ((_en) << 8)
|
||||
#define fmc_op_cmd1_en(_en) ((_en) << 2)
|
||||
#define fmc_op_addr_en(_en) ((_en) << 1)
|
||||
#define fmc_op_write_data_en(_en) ((_en) << 5)
|
||||
#define fmc_op_cmd2_en(_en) ((_en) << 4)
|
||||
#define fmc_op_wait_ready_en(_en) ((_en) << 3)
|
||||
#define fmc_op_read_data_en(_en) ((_en) << 7)
|
||||
#define fmc_op_read_status_en(_en) ((_en) << 6)
|
||||
#define FMC_OP_REG_OP_START 1
|
||||
|
||||
#define FMC_DMA_LEN 0x48
|
||||
#define fmc_dma_len_set(_len) ((_len) & 0x0fffffff)
|
||||
#define byte_to_mb(_x) ((_x) >> 20)
|
||||
|
||||
#define FMC_DMA_AHB_CTRL 0x40
|
||||
#define FMC_DMA_AHB_CTRL_DMA_PP_EN (1 << 3)
|
||||
#define FMC_DMA_AHB_CTRL_BURST16_EN (1 << 2)
|
||||
#define FMC_DMA_AHB_CTRL_BURST8_EN (1 << 1)
|
||||
#define FMC_DMA_AHB_CTRL_BURST4_EN 1
|
||||
|
||||
#define ALL_BURST_ENABLE (FMC_DMA_AHB_CTRL_BURST16_EN \
|
||||
| FMC_DMA_AHB_CTRL_BURST8_EN \
|
||||
| FMC_DMA_AHB_CTRL_BURST4_EN)
|
||||
|
||||
#define FMC_DMA_ADDR_OFFSET 4096
|
||||
|
||||
#define FMC_DMA_SADDR_D0 0x44
|
||||
|
||||
#define FMC_DMA_SADDR_D1 0x58
|
||||
|
||||
#define FMC_DMA_SADDR_D2 0x5c
|
||||
|
||||
#define FMC_DMA_SADDR_D3 0x50
|
||||
|
||||
#define FMC_DMA_SADDR_OOB 0x54
|
||||
|
||||
#define FMC_DMA_SADDRH_D0 0x208
|
||||
#define FMC_DMA_SADDRH_SHIFT 0x3LL
|
||||
#define FMC_DMA_SADDRH_MASK (FMC_DMA_SADDRH_SHIFT << 32)
|
||||
|
||||
#define FMC_DMA_SADDRH_OOB 0x218
|
||||
|
||||
#define FMC_DMA_BLK_SADDR 0x68
|
||||
#define fmc_dma_blk_saddr_set(_addr) ((_addr) & 0xffffff)
|
||||
|
||||
#define FMC_DMA_BLK_LEN 0x6c
|
||||
#define fmc_dma_blk_len_set(_len) ((_len) & 0xffff)
|
||||
|
||||
#define FMC_OP_CTRL 0x60
|
||||
#define op_ctrl_rd_opcode(_code) (((_code) & 0xff) << 8)
|
||||
#define op_ctrl_wr_opcode(_code) (((_code) & 0xff) << 16)
|
||||
#define op_ctrl_rd_op_sel(_op) (((_op) & 0x3) << 4)
|
||||
#define op_ctrl_dma_op(_type) ((_type) << 2)
|
||||
#define op_ctrl_rw_op(_op) ((_op) << 1)
|
||||
#define OP_CTRL_DMA_OP_READY 1
|
||||
|
||||
#define RD_OP_READ_ALL_PAGE 0x0
|
||||
#define RD_OP_READ_OOB 0x1
|
||||
#define RD_OP_BLOCK_READ 0x2
|
||||
|
||||
#define RD_OP_SHIFT 4
|
||||
#define RD_OP_MASK (0x3 << RD_OP_SHIFT)
|
||||
|
||||
#define OP_TYPE_DMA 0x0
|
||||
#define OP_TYPE_REG 0x1
|
||||
|
||||
#define RW_OP_READ 0x0
|
||||
#define RW_OP_WRITE 0x1
|
||||
|
||||
#define FMC_OP_PARA 0x78
|
||||
#define FMC_OP_PARA_RD_OOB_ONLY (1 << 1)
|
||||
|
||||
#define FMC_BOOT_SET 0x7c
|
||||
#define FMC_BOOT_SET_DEVICE_ECC_EN (1 << 4)
|
||||
#define FMC_BOOT_SET_BOOT_QUAD_EN (1 << 0)
|
||||
|
||||
#define FMC_STATUS 0xa4
|
||||
|
||||
#define GET_OP 0
|
||||
#define SET_OP 1
|
||||
|
||||
#define STATUS_ECC_MASK (0x3 << 4)
|
||||
#define STATUS_P_FAIL_MASK (1 << 3)
|
||||
#define STATUS_E_FAIL_MASK (1 << 2)
|
||||
#define STATUS_WEL_MASK (1 << 1)
|
||||
#define STATUS_OIP_MASK (1 << 0)
|
||||
|
||||
#define FMC_VERSION 0xb4
|
||||
|
||||
/* FMC IP version */
|
||||
#define FMC_VER_100 0x200
|
||||
|
||||
#endif /* End of CONFIG_FMC */
|
||||
|
||||
#define DISABLE 0
|
||||
#define ENABLE 1
|
||||
|
||||
/* DMA address align with 32 bytes. */
|
||||
#define FMC_DMA_ALIGN 32
|
||||
|
||||
#define FMC_CHIP_DELAY 25
|
||||
|
||||
#define TMP_BUF_LEN 128
|
||||
|
||||
#define fmc_read(_host, _reg) \
|
||||
readl((uintptr_t)((char *)_host->regbase + (_reg)))
|
||||
|
||||
#define fmc_write(_host, _reg, _value) \
|
||||
writel((u_int)(_value), (uintptr_t)((char *)_host->regbase + (_reg)))
|
||||
|
||||
#define get_page_index(host) \
|
||||
((host->addr_value[0] >> 16) | (host->addr_value[1] << 16))
|
||||
|
||||
#define db_msg(_fmt, arg...) \
|
||||
printf("%s(%d): " _fmt, __func__, __LINE__, ##arg);
|
||||
|
||||
#define db_bug(fmt, args...) \
|
||||
do { \
|
||||
printf("%s(%d): BUG: " fmt, __FILE__, __LINE__, ##args); \
|
||||
while (1); \
|
||||
} while (0)
|
||||
|
||||
#define FMC_INFO 1
|
||||
|
||||
#define BT_DBG 0 /* Boot init debug print */
|
||||
#define ER_DBG 0 /* Erase debug print */
|
||||
#define WR_DBG 0 /* Write debug print */
|
||||
#define RD_DBG 0 /* Read debug print */
|
||||
#define QE_DBG 0 /* Quad Enable debug print */
|
||||
#define OP_DBG 0 /* OP command debug print */
|
||||
#define DMA_DB 0 /* DMA read or write debug print */
|
||||
#define AC_DBG 0 /* 3-4byte Address Cycle */
|
||||
#define SR_DBG 0 /* Status Register debug print */
|
||||
#define CR_DBG 0 /* Config Register debug print */
|
||||
#define FT_DBG 0 /* Features debug print */
|
||||
#define WE_DBG 0 /* Write Enable debug print */
|
||||
#define BP_DBG 0 /* Block Protection debug print */
|
||||
#define EC_DBG 0 /* enable/disable ecc0 and randomizer */
|
||||
#define DTR_DB 0 /* 4DTR debug print */
|
||||
#define RST_DB 0 /* enable/disable reset pin */
|
||||
#define REG_DB 0 /* operation debug print */
|
||||
|
||||
#define fmc_pr(_type, _fmt, arg...) \
|
||||
do { \
|
||||
if (_type) \
|
||||
db_msg(_fmt, ##arg) \
|
||||
} while (0)
|
||||
|
||||
#define FMC_WAIT_TIMEOUT 400000 /* 4s equals 400000*10us */
|
||||
|
||||
#define fmc_cmd_wait_cpu_finish(_host) \
|
||||
do { \
|
||||
unsigned regval, timeout = FMC_WAIT_TIMEOUT; \
|
||||
do { \
|
||||
udelay(10); \
|
||||
regval = fmc_read((_host), FMC_OP); \
|
||||
--timeout; \
|
||||
} while ((regval & FMC_OP_REG_OP_START) && timeout); \
|
||||
if (!timeout) \
|
||||
db_msg("Error: Wait cmd cpu finish timeout!\n"); \
|
||||
} while (0)
|
||||
|
||||
#define fmc_dma_wait_int_finish(_host) \
|
||||
do { \
|
||||
unsigned regval, timeout = FMC_WAIT_TIMEOUT; \
|
||||
do { \
|
||||
udelay(10); \
|
||||
regval = fmc_read((_host), FMC_INT); \
|
||||
--timeout; \
|
||||
} while ((!(regval & FMC_INT_OP_DONE) && timeout)); \
|
||||
if (!timeout) { \
|
||||
debug_register_dump(); \
|
||||
db_msg("Error: Wait dma int finish timeout!\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define fmc_dma_wait_cpu_finish(_host) \
|
||||
do { \
|
||||
unsigned regval, timeout = FMC_WAIT_TIMEOUT; \
|
||||
do { \
|
||||
udelay(10); \
|
||||
regval = fmc_read((_host), FMC_OP_CTRL); \
|
||||
--timeout; \
|
||||
} while ((regval & OP_CTRL_DMA_OP_READY) && timeout); \
|
||||
if (!timeout) { \
|
||||
debug_register_dump(); \
|
||||
db_msg("Error: Wait dma cpu finish timeout!\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define clk_2x(_clk) (((_clk) + 1) >> 1)
|
||||
#define clk_4x(_clk) (((_clk) + 1) >> 2)
|
||||
|
||||
enum OP {
|
||||
READ = 1,
|
||||
WRITE,
|
||||
ERASE,
|
||||
};
|
||||
|
||||
struct fmc_cmd_op {
|
||||
unsigned char cs;
|
||||
unsigned char cmd;
|
||||
unsigned char l_cmd;
|
||||
unsigned char addr_h;
|
||||
unsigned int addr_l;
|
||||
unsigned int data_no;
|
||||
unsigned short option;
|
||||
unsigned short op_cfg;
|
||||
};
|
||||
|
||||
char *ulltostr(unsigned long long size);
|
||||
|
||||
void debug_register_dump(void);
|
||||
|
||||
int fmc_ip_ver_check(void);
|
||||
|
||||
void fmc_dev_type_switch(unsigned char type);
|
||||
|
||||
void *get_fmc_ip(void);
|
||||
|
||||
unsigned char *get_cs_number(unsigned char cs);
|
||||
|
||||
unsigned int get_fmc_boot_mode (void);
|
||||
|
||||
#endif /* End of __FMC_COMMON_H__ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
#ifndef HW_DECOMPRESS_H
|
||||
#define HW_DECOMPRESS_H
|
||||
|
||||
#define GZIP_MAX_LEN 0xffffff /* (16MB - 1Byte) */
|
||||
|
||||
typedef enum {
|
||||
HW_DECOMPRESS_OP_START = 0, /* decompress operation start */
|
||||
HW_DECOMPRESS_OP_CONTINUE, /* decompress operation continue */
|
||||
HW_DECOMPRESS_OP_END, /* decompress operation end */
|
||||
HW_DECOMPRESS_OP_ONCE, /* decompress operation just once */
|
||||
} hw_decompress_op_type;
|
||||
|
||||
extern unsigned int hw_dec_type;
|
||||
void hw_dec_init(void);
|
||||
void hw_dec_uinit(void);
|
||||
|
||||
int hw_dec_decompress(const unsigned char *dst, int *dstlen,
|
||||
const unsigned char *src, int srclen, const void *unused);
|
||||
|
||||
/*
|
||||
* Support decompressing gzip file by sections
|
||||
* op_type: operation type
|
||||
* dst: addr of uncompressed file
|
||||
* dstlen: len of uncompressed file
|
||||
* src: addr of compressed file
|
||||
* srclen: len of compressed file
|
||||
*
|
||||
* note: only support v1 version now for sections feature
|
||||
*/
|
||||
int hw_dec_decompress_ex(hw_decompress_op_type op_type, const unsigned char *dst,
|
||||
unsigned int *dstlen, const unsigned char *src, unsigned int srclen);
|
||||
|
||||
int hw_gunzip(void *dst, unsigned int dst_len, void *src, unsigned int *src_len);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
#ifndef __LOTUS_IMAGE_H_
|
||||
#define __LOTUS_IMAGE_H_ 1
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* HW GZIP Image head */
|
||||
static inline bool check_hwzimage_header(unsigned char *header)
|
||||
{
|
||||
unsigned int magic_num0 = *((unsigned int *)(header + HEAD_MAGIC_NUM0_OFFSET));
|
||||
unsigned int magic_num1 = *((unsigned int *)(header + HEAD_MAGIC_NUM1_OFFSET));
|
||||
if ((magic_num0 != HEAD_MAGIC_NUM0) || (magic_num1 != HEAD_MAGIC_NUM1))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif /* __LOTUS_IMAGE_H_ */
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef LOTUS_I2C_H
|
||||
#define LOTUS_I2C_H
|
||||
|
||||
#include <compiler.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct i2c_client {
|
||||
unsigned char i2c_num;
|
||||
unsigned short dev_addr;
|
||||
unsigned long int reg_addr;
|
||||
unsigned int reg_width;
|
||||
};
|
||||
|
||||
int hal_i2c_init(unsigned char i2c_num);
|
||||
int hal_i2c_recv(const struct i2c_client *client, unsigned int *buf,
|
||||
unsigned int count);
|
||||
int hal_i2c_send(unsigned char i2c_num, unsigned short dev_addr, const char *buf,
|
||||
unsigned int count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HAL_I2C_H */
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
#ifndef _LOTUS_IMAGE_H_
|
||||
#define _LOTUS_IMAGE_H_
|
||||
|
||||
#include <config.h>
|
||||
#include <linux/lotus/hwzimage.h>
|
||||
|
||||
#define _MCU_HEAD_SIZE 64
|
||||
#define _MCU_FW_MAGIC 0x57465652
|
||||
|
||||
struct mcu_fw_head {
|
||||
u32 j_instruction; /* Jump to real excutable entry */
|
||||
u32 fw_magic; /* MCU Firmware magic */
|
||||
u32 fw_ver; /* MCU Firmware version */
|
||||
u32 fw_total_size; /* MCU Firmware total size */
|
||||
u32 fw_stage1_size; /* MCU Stage1 size */
|
||||
u8 resv[_MCU_HEAD_SIZE - 20]; /* Reserved */
|
||||
};
|
||||
|
||||
#endif /* ifndef _LOTUS_IMAGE_H_ */
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __MATCH_TABLE_H__
|
||||
#define __MATCH_TABLE_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
struct match_reg_type {
|
||||
int reg;
|
||||
int type;
|
||||
};
|
||||
|
||||
struct match_type_str {
|
||||
int type;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
struct match_t {
|
||||
int type;
|
||||
int reg;
|
||||
void *data;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
#define match_set_type_reg(_type, _reg) {(_type), (_reg), (void *)0}
|
||||
#define match_set_type_data(_type, _data) {(_type), 0, (void *)(_data)}
|
||||
#define match_set(_type, _reg, _data) {(_type), (_reg), (void *)(_data)}
|
||||
|
||||
int reg2type(const struct match_reg_type *table, int length, int reg, int def);
|
||||
|
||||
int type2reg(const struct match_reg_type *table, int length, int type, int def);
|
||||
|
||||
int str2type(const struct match_type_str *table, int length, const char *str,
|
||||
int size, int def);
|
||||
|
||||
const char *type2str(const struct match_type_str *table, int length, int type,
|
||||
const char *def);
|
||||
|
||||
int match_reg_to_type(const struct match_t *table, int nr_table, int reg, int def);
|
||||
|
||||
int match_type_to_reg(const struct match_t *table, int nr_table, int type, int def);
|
||||
|
||||
int match_data_to_type(const struct match_t *table, int nr_table, const char *data,
|
||||
int size, int def);
|
||||
|
||||
void *match_type_to_data(const struct match_t *table, int nr_table, int type,
|
||||
void *def);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* End of __MATCH_TABLE_H__ */
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __NFC_COMMON_H__
|
||||
#define __NFC_COMMON_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include <asm/io.h>
|
||||
#include <common.h>
|
||||
#include <linux/mtd/rawnand.h>
|
||||
#include <linux/lotus/match_table.h>
|
||||
#include <linux/lotus/fmc_common.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
#define _512B 512
|
||||
#define _2K 2048
|
||||
#define _4K 4096
|
||||
#define _8K 8192
|
||||
#define _16K 16384
|
||||
|
||||
/*****************************************************************************/
|
||||
#define NAND_PAGE_512B 0
|
||||
#define NAND_PAGE_1K 1
|
||||
#define NAND_PAGE_2K 2
|
||||
#define NAND_PAGE_4K 3
|
||||
#define NAND_PAGE_8K 4
|
||||
#define NAND_PAGE_16K 5
|
||||
#define NAND_PAGE_32K 6
|
||||
|
||||
/*****************************************************************************/
|
||||
#define NAND_ECC_NONE 0
|
||||
#define NAND_ECC_0BIT 0
|
||||
#define NAND_ECC_1BIT 1
|
||||
#define NAND_ECC_1BIT_512 1
|
||||
#define NAND_ECC_4BIT 2
|
||||
#define NAND_ECC_4BIT_512 2
|
||||
#define NAND_ECC_4BYTE 2
|
||||
#define NAND_ECC_8BIT 2
|
||||
#define NAND_ECC_8BIT_512 3
|
||||
#define NAND_ECC_8BYTE 3
|
||||
#define NAND_ECC_13BIT 4
|
||||
#define NAND_ECC_16BIT 5
|
||||
#define NAND_ECC_18BIT 6
|
||||
#define NAND_ECC_24BIT 7
|
||||
#define NAND_ECC_27BIT 8
|
||||
#define NAND_ECC_28BIT 9
|
||||
#define NAND_ECC_32BIT 10
|
||||
#define NAND_ECC_40BIT 11
|
||||
#define NAND_ECC_41BIT 12
|
||||
#define NAND_ECC_42BIT 13
|
||||
#define NAND_ECC_48BIT 14
|
||||
#define NAND_ECC_60BIT 15
|
||||
#define NAND_ECC_64BIT 16
|
||||
#define NAND_ECC_72BIT 17
|
||||
#define NAND_ECC_80BIT 18
|
||||
|
||||
#define ERSTR_HARDWARE "Hardware configuration error."
|
||||
#define ERSTR_DRIVER "Driver does not support."
|
||||
|
||||
#define DISABLE 0
|
||||
#define ENABLE 1
|
||||
|
||||
#define is_randomizer(_dev) ((_dev)->flags & NAND_RANDOMIZER)
|
||||
#define is_hw_auto(_dev) ((_dev)->flags & NAND_HW_AUTO)
|
||||
#define is_synchronous(_dev) ((_dev)->flags & NAND_SYNCHRONOUS)
|
||||
#define is_config_done(_dev) ((_dev)->flags & NAND_CONFIG_DONE)
|
||||
#define is_synchronous_boot(_dev) ((_dev)->flags & NAND_SYNCHRONOUS_BOOT)
|
||||
|
||||
#define NAND_PAGE_SHIFT 9 /* 512 */
|
||||
|
||||
#if defined(CONFIG_FMC_SPI_NAND) || defined(CONFIG_FMC_NAND)
|
||||
/*****************************************************************************/
|
||||
enum ecc_type {
|
||||
ET_ECC_NONE = 0x00,
|
||||
ET_ECC_1BIT = 0x01,
|
||||
ET_ECC_4BIT = 0x02,
|
||||
ET_ECC_8BIT = 0x03,
|
||||
ET_ECC_24BIT1K = 0x04,
|
||||
ET_ECC_40BIT1K = 0x05,
|
||||
ET_ECC_64BIT1K = 0x06,
|
||||
};
|
||||
|
||||
enum page_type {
|
||||
PT_PAGESIZE_512 = 0x00,
|
||||
PT_PAGESIZE_2K = 0x01,
|
||||
PT_PAGESIZE_4K = 0x02,
|
||||
PT_PAGESIZE_8K = 0x03,
|
||||
PT_PAGESIZE_16K = 0x04,
|
||||
};
|
||||
|
||||
struct nand_config_info {
|
||||
unsigned int pagetype;
|
||||
unsigned int ecctype;
|
||||
unsigned int oobsize;
|
||||
struct nand_ecclayout *layout;
|
||||
};
|
||||
|
||||
struct nfc_host;
|
||||
|
||||
struct read_retry_t {
|
||||
int type;
|
||||
int count;
|
||||
int (*set_rr_param)(struct nfc_host *host, int param);
|
||||
int (*get_rr_param)(struct nfc_host *host);
|
||||
int (*reset_rr_param)(struct nfc_host *host);
|
||||
int (*enable_enhanced_slc)(struct nfc_host *host, int enable);
|
||||
};
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
struct nand_flash_dev_ex {
|
||||
struct nand_flash_dev flash_dev;
|
||||
|
||||
char *start_type;
|
||||
unsigned char ids[8]; /* 8Byte */
|
||||
int oobsize;
|
||||
int ecctype;
|
||||
|
||||
#define NAND_RANDOMIZER 0x01 /* nand chip need randomizer */
|
||||
#define NAND_HW_AUTO 0x02 /* controller support hardware auto config */
|
||||
#define NAND_SYNCHRONOUS 0x04 /* nand chip support synchronous */
|
||||
#define NAND_ASYNCHRONOUS 0x08 /* nand chip support asynchronous */
|
||||
#define NAND_SYNCHRONOUS_BOOT 0x10 /* nand boot from synchronous mode */
|
||||
#define NAND_CONFIG_DONE 0x20 /* current controller config finish */
|
||||
int flags;
|
||||
int is_randomizer;
|
||||
#define NAND_RR_NONE 0x00
|
||||
#define NAND_RR_HYNIX_BG_BDIE 0x10
|
||||
#define NAND_RR_HYNIX_BG_CDIE 0x11
|
||||
#define NAND_RR_HYNIX_CG_ADIE 0x12
|
||||
#define NAND_RR_MICRON 0x20
|
||||
#define NAND_RR_SAMSUNG 0x30
|
||||
#define NAND_RR_TOSHIBA_24NM 0x40
|
||||
#define NAND_RR_TOSHIBA_19NM 0x41
|
||||
#define NAND_RR_MASK 0xF0
|
||||
int read_retry_type;
|
||||
|
||||
int hostver; /* host controller version. */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
const char *nand_ecc_name(int type);
|
||||
|
||||
const char *nand_page_name(int type);
|
||||
|
||||
int nandpage_size2type(int size);
|
||||
|
||||
int nandpage_type2size(int size);
|
||||
|
||||
/*****************************************************************************/
|
||||
extern int nand_get_ecctype(void);
|
||||
|
||||
extern struct nand_flash_dev *(*get_flash_type)(struct mtd_info *mtd,
|
||||
struct nand_chip *chip, unsigned char *id);
|
||||
|
||||
extern int (*nand_oob_resize)(struct mtd_info *mtd);
|
||||
|
||||
/*****************************************************************************/
|
||||
extern unsigned char match_ecc_type_to_yaffs(unsigned char type);
|
||||
|
||||
extern unsigned char match_page_reg_to_type(unsigned char reg);
|
||||
|
||||
extern unsigned char match_page_type_to_reg(unsigned char type);
|
||||
|
||||
extern const char *match_page_type_to_str(unsigned char type);
|
||||
|
||||
/*****************************************************************************/
|
||||
extern unsigned char match_ecc_reg_to_type(unsigned char reg);
|
||||
|
||||
extern unsigned char match_ecc_type_to_reg(unsigned char type);
|
||||
|
||||
extern const char *match_ecc_type_to_str(unsigned char type);
|
||||
|
||||
/*****************************************************************************/
|
||||
extern unsigned char match_page_size_to_type(unsigned int size);
|
||||
|
||||
extern unsigned int match_page_type_to_size(unsigned char type);
|
||||
|
||||
#endif /* End of __NFC_COMMON_H__ */
|
||||
|
||||
@@ -0,0 +1,614 @@
|
||||
|
||||
#ifndef SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27
|
||||
#define SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27
|
||||
|
||||
#include "linux/lotus/securectype.h"
|
||||
#ifndef SECUREC_HAVE_STDARG_H
|
||||
#define SECUREC_HAVE_STDARG_H 1
|
||||
#endif
|
||||
|
||||
#if SECUREC_HAVE_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_HAVE_ERRNO_H
|
||||
#define SECUREC_HAVE_ERRNO_H 1
|
||||
#endif
|
||||
|
||||
/* EINVAL ERANGE may defined in errno.h */
|
||||
#if SECUREC_HAVE_ERRNO_H
|
||||
#if SECUREC_IN_KERNEL
|
||||
#include <linux/errno.h>
|
||||
#else
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Define error code */
|
||||
#if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \
|
||||
(defined(__STDC_WANT_LIB_EXT1__) && (!__STDC_WANT_LIB_EXT1__))
|
||||
#ifndef SECUREC_DEFINED_ERRNO_TYPE
|
||||
#define SECUREC_DEFINED_ERRNO_TYPE
|
||||
/* Just check whether macrodefinition exists. */
|
||||
#ifndef errno_t
|
||||
typedef int errno_t;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Success */
|
||||
#ifndef EOK
|
||||
#define EOK 0
|
||||
#endif
|
||||
|
||||
#ifndef EINVAL
|
||||
/* The src buffer is not correct and destination buffer cant not be reset */
|
||||
#define EINVAL 22
|
||||
#endif
|
||||
|
||||
#ifndef EINVAL_AND_RESET
|
||||
/* Once the error is detected, the dest buffer must be reseted! Value is 22 xor 128 */
|
||||
#define EINVAL_AND_RESET 150
|
||||
#endif
|
||||
|
||||
#ifndef ERANGE
|
||||
/* The destination buffer is not long enough and destination buffer can not be reset */
|
||||
#define ERANGE 34
|
||||
#endif
|
||||
|
||||
#ifndef ERANGE_AND_RESET
|
||||
/* Once the error is detected, the dest buffer must be reseted! Value is 34 xor 128 */
|
||||
#define ERANGE_AND_RESET 162
|
||||
#endif
|
||||
|
||||
#ifndef EOVERLAP_AND_RESET
|
||||
/* Once the buffer overlap is detected, the dest buffer must be reseted! Value is 54 xor 128 */
|
||||
#define EOVERLAP_AND_RESET 182
|
||||
#endif
|
||||
|
||||
/* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */
|
||||
#ifndef SECUREC_API
|
||||
#if defined(SECUREC_DLL_EXPORT)
|
||||
#define SECUREC_API __declspec(dllexport)
|
||||
#elif defined(SECUREC_DLL_IMPORT)
|
||||
#define SECUREC_API __declspec(dllimport)
|
||||
#else
|
||||
/*
|
||||
* Standardized function declaration. If a security function is declared in the your code,
|
||||
* it may cause a compilation alarm,Please delete the security function you declared.
|
||||
* Adding extern under windows will cause the system to have inline functions to expand,
|
||||
* so do not add the extern in default
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
#define SECUREC_API
|
||||
#else
|
||||
#define SECUREC_API extern
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Description: The GetHwSecureCVersion function get SecureC Version string and version number.
|
||||
* Parameter: verNumber - to store version number (for example value is 0x500 | 0xa)
|
||||
* Return: version string
|
||||
*/
|
||||
SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber);
|
||||
|
||||
#if SECUREC_ENABLE_MEMSET
|
||||
/*
|
||||
* Description: The memset_s function copies the value of c (converted to an unsigned char) into each of
|
||||
* the first count characters of the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: c - the value to be copied
|
||||
* Parameter: count - copies count bytes of value to dest
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count);
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ONLY_DECLARE_MEMSET
|
||||
#define SECUREC_ONLY_DECLARE_MEMSET 0
|
||||
#endif
|
||||
|
||||
#if !SECUREC_ONLY_DECLARE_MEMSET
|
||||
|
||||
#if SECUREC_ENABLE_MEMMOVE
|
||||
/*
|
||||
* Description: The memmove_s function copies n characters from the object pointed to by src
|
||||
* into the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: src - source address
|
||||
* Parameter: count - copies count bytes from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_MEMCPY
|
||||
/*
|
||||
* Description: The memcpy_s function copies n characters from the object pointed to
|
||||
* by src into the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: src - source address
|
||||
* Parameter: count - copies count bytes from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRCPY
|
||||
/*
|
||||
* Description: The strcpy_s function copies the string pointed to by strSrc (including
|
||||
* the terminating null character) into the array pointed to by strDest
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
|
||||
* Parameter: strSrc - source address
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRNCPY
|
||||
/*
|
||||
* Description: The strncpy_s function copies not more than n successive characters (not including
|
||||
* the terminating null character) from the array pointed to by strSrc to the array pointed to by strDest.
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
|
||||
* Parameter: strSrc - source address
|
||||
* Parameter: count - copies count characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRCAT
|
||||
/*
|
||||
* Description: The strcat_s function appends a copy of the string pointed to by strSrc (including
|
||||
* the terminating null character) to the end of the string pointed to by strDest.
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null wide character)
|
||||
* Parameter: strSrc - source address
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRNCAT
|
||||
/*
|
||||
* Description: The strncat_s function appends not more than n successive characters (not including
|
||||
* the terminating null character)
|
||||
* from the array pointed to by strSrc to the end of the string pointed to by strDest.
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
|
||||
* Parameter: strSrc - source address
|
||||
* Parameter: count - copies count characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSPRINTF
|
||||
/*
|
||||
* Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax
|
||||
* and the explicit runtime-constraints violation
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte)
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format,
|
||||
va_list argList) SECUREC_ATTRIBUTE(3, 0);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SPRINTF
|
||||
/*
|
||||
* Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax
|
||||
* and the explicit runtime-constraints violation
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSNPRINTF
|
||||
/*
|
||||
* Description: The vsnprintf_s function is equivalent to the vsnprintf function except for
|
||||
* the parameter destMax/count and the explicit runtime-constraints violation
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
|
||||
*/
|
||||
SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
|
||||
va_list argList) SECUREC_ATTRIBUTE(4, 0);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SNPRINTF
|
||||
/*
|
||||
* Description: The snprintf_s function is equivalent to the snprintf function except for
|
||||
* the parameter destMax/count and the explicit runtime-constraints violation
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
|
||||
*/
|
||||
SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
|
||||
...) SECUREC_ATTRIBUTE(4, 5);
|
||||
#endif
|
||||
|
||||
#if SECUREC_SNPRINTF_TRUNCATED
|
||||
/*
|
||||
* Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except
|
||||
* no count parameter and return value
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
|
||||
*/
|
||||
SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
|
||||
va_list argList) SECUREC_ATTRIBUTE(3, 0);
|
||||
|
||||
/*
|
||||
* Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except
|
||||
* no count parameter and return value
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
|
||||
*/
|
||||
SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax,
|
||||
const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SCANF
|
||||
/*
|
||||
* Description: The scanf_s function is equivalent to fscanf_s with the argument stdin
|
||||
* interposed before the arguments to scanf_s
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int scanf_s(const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSCANF
|
||||
/*
|
||||
* Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vscanf_s(const char *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SSCANF
|
||||
/*
|
||||
* Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a
|
||||
* string (specified by the argument buffer) rather than from a stream
|
||||
* Parameter: buffer - read character from buffer
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int sscanf_s(const char *buffer, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSSCANF
|
||||
/*
|
||||
* Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
|
||||
* replaced by argList
|
||||
* Parameter: buffer - read character from buffer
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_FSCANF
|
||||
/*
|
||||
* Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers
|
||||
* apply to a pair of arguments (unless assignment suppression is indicated by a*)
|
||||
* Parameter: stream - stdio file stream
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int fscanf_s(FILE *stream, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VFSCANF
|
||||
/*
|
||||
* Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
|
||||
* replaced by argList
|
||||
* Parameter: stream - stdio file stream
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRTOK
|
||||
/*
|
||||
* Description: The strtok_s function parses a string into a sequence of strToken,
|
||||
* replace all characters in strToken string that match to strDelimit set with 0.
|
||||
* On the first call to strtok_s the string to be parsed should be specified in strToken.
|
||||
* In each subsequent call that should parse the same string, strToken should be NULL
|
||||
* Parameter: strToken - the string to be delimited
|
||||
* Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
|
||||
* Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
|
||||
* Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned.
|
||||
* In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
|
||||
* return NULL if the *context string length is equal 0, otherwise return *context.
|
||||
*/
|
||||
SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_GETS && !SECUREC_IN_KERNEL
|
||||
/*
|
||||
* Description: The gets_s function reads at most one less than the number of characters specified
|
||||
* by destMax from the stream pointed to by stdin, into the array pointed to by buffer
|
||||
* Parameter: buffer - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
|
||||
* Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL.
|
||||
*/
|
||||
SECUREC_API char *gets_s(char *buffer, size_t destMax);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_WCHAR_FUNC
|
||||
#if SECUREC_ENABLE_MEMCPY
|
||||
/*
|
||||
* Description: The wmemcpy_s function copies n successive wide characters from the object pointed to
|
||||
* by src into the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: src - source address
|
||||
* Parameter: count - copies count wide characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_MEMMOVE
|
||||
/*
|
||||
* Description: The wmemmove_s function copies n successive wide characters from the object
|
||||
* pointed to by src into the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: src - source address
|
||||
* Parameter: count - copies count wide characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRCPY
|
||||
/*
|
||||
* Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating
|
||||
* null wide character) into the array pointed to by strDest
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: strSrc - source address
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRNCPY
|
||||
/*
|
||||
* Description: The wcsncpy_s function copies not more than n successive wide characters (not including the
|
||||
* terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
|
||||
* Parameter: strSrc - source address
|
||||
* Parameter: count - copies count wide characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRCAT
|
||||
/*
|
||||
* Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the
|
||||
* terminating null wide character) to the end of the wide string pointed to by strDest
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
|
||||
* Parameter: strSrc - source address
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRNCAT
|
||||
/*
|
||||
* Description: The wcsncat_s function appends not more than n successive wide characters (not including the
|
||||
* terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to
|
||||
* by strDest.
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
|
||||
* Parameter: strSrc - source address
|
||||
* Parameter: count - copies count wide characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRTOK
|
||||
/*
|
||||
* Description: The wcstok_s function is the wide-character equivalent of the strtok_s function
|
||||
* Parameter: strToken - the string to be delimited
|
||||
* Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
|
||||
* Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
|
||||
* Return: a pointer to the first character of a token, or a null pointer if there is no token
|
||||
* or there is a runtime-constraint violation.
|
||||
*/
|
||||
SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSPRINTF
|
||||
/*
|
||||
* Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null )
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of characters printed(not including the terminating null wide characte),
|
||||
* If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SPRINTF
|
||||
|
||||
/*
|
||||
* Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null )
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of characters printed(not including the terminating null wide characte),
|
||||
* If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_FSCANF
|
||||
/*
|
||||
* Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function
|
||||
* Parameter: stream - stdio file stream
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VFSCANF
|
||||
/*
|
||||
* Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
|
||||
* Parameter: stream - stdio file stream
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SCANF
|
||||
/*
|
||||
* Description: The wscanf_s function is the wide-character equivalent of the scanf_s function
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int wscanf_s(const wchar_t *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSCANF
|
||||
/*
|
||||
* Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SSCANF
|
||||
/*
|
||||
* Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function
|
||||
* Parameter: buffer - read character from buffer
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSSCANF
|
||||
/*
|
||||
* Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
|
||||
* Parameter: buffer - read character from buffer
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList);
|
||||
#endif
|
||||
#endif /* SECUREC_ENABLE_WCHAR_FUNC */
|
||||
#endif
|
||||
|
||||
/* Those functions are used by macro ,must declare hare , also for without function declaration warning */
|
||||
extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count);
|
||||
extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc);
|
||||
|
||||
#if SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
/* Those functions are used by macro */
|
||||
extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count);
|
||||
extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count);
|
||||
extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count);
|
||||
extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count);
|
||||
|
||||
/* The strcpy_sp is a macro, not a function in performance optimization mode. */
|
||||
#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
|
||||
__builtin_constant_p((src))) ? \
|
||||
SECUREC_STRCPY_SM((dest), (destMax), (src)) : \
|
||||
strcpy_s((dest), (destMax), (src)))
|
||||
|
||||
/* The strncpy_sp is a macro, not a function in performance optimization mode. */
|
||||
#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
|
||||
__builtin_constant_p((destMax)) && \
|
||||
__builtin_constant_p((src))) ? \
|
||||
SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \
|
||||
strncpy_s((dest), (destMax), (src), (count)))
|
||||
|
||||
/* The strcat_sp is a macro, not a function in performance optimization mode. */
|
||||
#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
|
||||
__builtin_constant_p((src))) ? \
|
||||
SECUREC_STRCAT_SM((dest), (destMax), (src)) : \
|
||||
strcat_s((dest), (destMax), (src)))
|
||||
|
||||
/* The strncat_sp is a macro, not a function in performance optimization mode. */
|
||||
#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
|
||||
__builtin_constant_p((destMax)) && \
|
||||
__builtin_constant_p((src))) ? \
|
||||
SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \
|
||||
strncat_s((dest), (destMax), (src), (count)))
|
||||
|
||||
/* The memcpy_sp is a macro, not a function in performance optimization mode. */
|
||||
#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \
|
||||
(SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \
|
||||
(__builtin_constant_p((destMax)) ? \
|
||||
(((size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
|
||||
memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \
|
||||
memcpy_sOptAsm((dest), (destMax), (src), (count))))
|
||||
|
||||
/* The memset_sp is a macro, not a function in performance optimization mode. */
|
||||
#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \
|
||||
(SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \
|
||||
(__builtin_constant_p((destMax)) ? \
|
||||
(((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
|
||||
memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \
|
||||
memset_sOptAsm((dest), (destMax), (c), (count))))
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,564 @@
|
||||
|
||||
#ifndef SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7
|
||||
#define SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7
|
||||
|
||||
#ifndef SECUREC_USING_STD_SECURE_LIB
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
#if defined(__STDC_WANT_SECURE_LIB__) && (!__STDC_WANT_SECURE_LIB__)
|
||||
/* Security functions have been provided since vs2005, default use of system library functions */
|
||||
#define SECUREC_USING_STD_SECURE_LIB 0
|
||||
#else
|
||||
#define SECUREC_USING_STD_SECURE_LIB 1
|
||||
#endif
|
||||
#else
|
||||
#define SECUREC_USING_STD_SECURE_LIB 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (!SECUREC_USING_STD_SECURE_LIB)
|
||||
#ifndef SECUREC_DISABLE_CRT_FUNC
|
||||
#define SECUREC_DISABLE_CRT_FUNC 1
|
||||
#endif
|
||||
#ifndef SECUREC_DISABLE_CRT_IMP
|
||||
#define SECUREC_DISABLE_CRT_IMP 1
|
||||
#endif
|
||||
#else /* MSC VER */
|
||||
#ifndef SECUREC_DISABLE_CRT_FUNC
|
||||
#define SECUREC_DISABLE_CRT_FUNC 0
|
||||
#endif
|
||||
#ifndef SECUREC_DISABLE_CRT_IMP
|
||||
#define SECUREC_DISABLE_CRT_IMP 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SECUREC_DISABLE_CRT_FUNC
|
||||
#ifdef __STDC_WANT_SECURE_LIB__
|
||||
#undef __STDC_WANT_SECURE_LIB__
|
||||
#endif
|
||||
#define __STDC_WANT_SECURE_LIB__ 0
|
||||
#endif
|
||||
|
||||
#if SECUREC_DISABLE_CRT_IMP
|
||||
#ifdef _CRTIMP_ALTERNATIVE
|
||||
#undef _CRTIMP_ALTERNATIVE
|
||||
#endif
|
||||
#define _CRTIMP_ALTERNATIVE /* Comment Microsoft *_s function */
|
||||
#endif
|
||||
|
||||
/* Compile in kernel under macro control */
|
||||
#ifndef SECUREC_IN_KERNEL
|
||||
#ifdef __KERNEL__
|
||||
#define SECUREC_IN_KERNEL 0
|
||||
#else
|
||||
#define SECUREC_IN_KERNEL 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* make kernel symbols of functions available to loadable modules */
|
||||
#ifndef SECUREC_EXPORT_KERNEL_SYMBOL
|
||||
#if SECUREC_IN_KERNEL
|
||||
#define SECUREC_EXPORT_KERNEL_SYMBOL 1
|
||||
#else
|
||||
#define SECUREC_EXPORT_KERNEL_SYMBOL 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SECUREC_IN_KERNEL
|
||||
#ifndef SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_SCANF_FILE 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_WCHAR_FUNC
|
||||
#define SECUREC_ENABLE_WCHAR_FUNC 0
|
||||
#endif
|
||||
#else /* SECUREC_IN_KERNEL */
|
||||
#ifndef SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_SCANF_FILE 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_WCHAR_FUNC
|
||||
#define SECUREC_ENABLE_WCHAR_FUNC 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Default secure function declaration, default declarations for non-standard functions */
|
||||
#ifndef SECUREC_SNPRINTF_TRUNCATED
|
||||
#define SECUREC_SNPRINTF_TRUNCATED 1
|
||||
#endif
|
||||
|
||||
#if SECUREC_USING_STD_SECURE_LIB
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
/* Declare secure functions that are not available in the VS compiler */
|
||||
#ifndef SECUREC_ENABLE_MEMSET
|
||||
#define SECUREC_ENABLE_MEMSET 1
|
||||
#endif
|
||||
/* VS 2005 have vsnprintf_s function */
|
||||
#ifndef SECUREC_ENABLE_VSNPRINTF
|
||||
#define SECUREC_ENABLE_VSNPRINTF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SNPRINTF
|
||||
/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */
|
||||
#define snprintf_s _snprintf_s
|
||||
#define SECUREC_ENABLE_SNPRINTF 0
|
||||
#endif
|
||||
/* Before VS 2010 do not have v functions */
|
||||
#if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS)
|
||||
#ifndef SECUREC_ENABLE_VFSCANF
|
||||
#define SECUREC_ENABLE_VFSCANF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSCANF
|
||||
#define SECUREC_ENABLE_VSCANF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSSCANF
|
||||
#define SECUREC_ENABLE_VSSCANF 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else /* MSC VER */
|
||||
#ifndef SECUREC_ENABLE_MEMSET
|
||||
#define SECUREC_ENABLE_MEMSET 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SNPRINTF
|
||||
#define SECUREC_ENABLE_SNPRINTF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSNPRINTF
|
||||
#define SECUREC_ENABLE_VSNPRINTF 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ENABLE_MEMMOVE
|
||||
#define SECUREC_ENABLE_MEMMOVE 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_MEMCPY
|
||||
#define SECUREC_ENABLE_MEMCPY 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRCPY
|
||||
#define SECUREC_ENABLE_STRCPY 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRNCPY
|
||||
#define SECUREC_ENABLE_STRNCPY 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRCAT
|
||||
#define SECUREC_ENABLE_STRCAT 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRNCAT
|
||||
#define SECUREC_ENABLE_STRNCAT 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SPRINTF
|
||||
#define SECUREC_ENABLE_SPRINTF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSPRINTF
|
||||
#define SECUREC_ENABLE_VSPRINTF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SSCANF
|
||||
#define SECUREC_ENABLE_SSCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSSCANF
|
||||
#define SECUREC_ENABLE_VSSCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SCANF
|
||||
#define SECUREC_ENABLE_SCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSCANF
|
||||
#define SECUREC_ENABLE_VSCANF 0
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ENABLE_FSCANF
|
||||
#define SECUREC_ENABLE_FSCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VFSCANF
|
||||
#define SECUREC_ENABLE_VFSCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRTOK
|
||||
#define SECUREC_ENABLE_STRTOK 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_GETS
|
||||
#define SECUREC_ENABLE_GETS 0
|
||||
#endif
|
||||
|
||||
#else /* SECUREC USE STD SECURE LIB */
|
||||
|
||||
#ifndef SECUREC_ENABLE_MEMSET
|
||||
#define SECUREC_ENABLE_MEMSET 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_MEMMOVE
|
||||
#define SECUREC_ENABLE_MEMMOVE 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_MEMCPY
|
||||
#define SECUREC_ENABLE_MEMCPY 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRCPY
|
||||
#define SECUREC_ENABLE_STRCPY 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRNCPY
|
||||
#define SECUREC_ENABLE_STRNCPY 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRCAT
|
||||
#define SECUREC_ENABLE_STRCAT 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRNCAT
|
||||
#define SECUREC_ENABLE_STRNCAT 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SPRINTF
|
||||
#define SECUREC_ENABLE_SPRINTF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSPRINTF
|
||||
#define SECUREC_ENABLE_VSPRINTF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SNPRINTF
|
||||
#define SECUREC_ENABLE_SNPRINTF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSNPRINTF
|
||||
#define SECUREC_ENABLE_VSNPRINTF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SSCANF
|
||||
#define SECUREC_ENABLE_SSCANF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSSCANF
|
||||
#define SECUREC_ENABLE_VSSCANF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SCANF
|
||||
#if SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_SCANF 1
|
||||
#else
|
||||
#define SECUREC_ENABLE_SCANF 0
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSCANF
|
||||
#if SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_VSCANF 1
|
||||
#else
|
||||
#define SECUREC_ENABLE_VSCANF 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ENABLE_FSCANF
|
||||
#if SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_FSCANF 1
|
||||
#else
|
||||
#define SECUREC_ENABLE_FSCANF 0
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VFSCANF
|
||||
#if SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_VFSCANF 1
|
||||
#else
|
||||
#define SECUREC_ENABLE_VFSCANF 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ENABLE_STRTOK
|
||||
#define SECUREC_ENABLE_STRTOK 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_GETS
|
||||
#define SECUREC_ENABLE_GETS 1
|
||||
#endif
|
||||
#endif /* SECUREC_USE_STD_SECURE_LIB */
|
||||
|
||||
#if !SECUREC_ENABLE_SCANF_FILE
|
||||
#if SECUREC_ENABLE_FSCANF
|
||||
#undef SECUREC_ENABLE_FSCANF
|
||||
#define SECUREC_ENABLE_FSCANF 0
|
||||
#endif
|
||||
#if SECUREC_ENABLE_VFSCANF
|
||||
#undef SECUREC_ENABLE_VFSCANF
|
||||
#define SECUREC_ENABLE_VFSCANF 0
|
||||
#endif
|
||||
#if SECUREC_ENABLE_SCANF
|
||||
#undef SECUREC_ENABLE_SCANF
|
||||
#define SECUREC_ENABLE_SCANF 0
|
||||
#endif
|
||||
#if SECUREC_ENABLE_FSCANF
|
||||
#undef SECUREC_ENABLE_FSCANF
|
||||
#define SECUREC_ENABLE_FSCANF 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if SECUREC_IN_KERNEL
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#else
|
||||
#ifndef SECUREC_HAVE_STDIO_H
|
||||
#define SECUREC_HAVE_STDIO_H 1
|
||||
#endif
|
||||
#ifndef SECUREC_HAVE_STRING_H
|
||||
#define SECUREC_HAVE_STRING_H 1
|
||||
#endif
|
||||
#ifndef SECUREC_HAVE_STDLIB_H
|
||||
#define SECUREC_HAVE_STDLIB_H 1
|
||||
#endif
|
||||
#if SECUREC_HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#if SECUREC_HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#if SECUREC_HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable.
|
||||
* The macro is automatically closed on the windows platform and linux kernel
|
||||
*/
|
||||
#ifndef SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
#if SECUREC_IN_KERNEL
|
||||
#define SECUREC_WITH_PERFORMANCE_ADDONS 0
|
||||
#else
|
||||
#define SECUREC_WITH_PERFORMANCE_ADDONS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */
|
||||
#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
|
||||
#ifndef SECUREC_COMPATIBLE_WIN_FORMAT
|
||||
#define SECUREC_COMPATIBLE_WIN_FORMAT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
|
||||
/* On windows platform, can't use optimized function for there is no __builtin_constant_p like function */
|
||||
/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */
|
||||
#ifdef SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
#undef SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
#define SECUREC_WITH_PERFORMANCE_ADDONS 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \
|
||||
defined(SECUREC_VXWORKS_VERSION_5_4)
|
||||
#ifndef SECUREC_VXWORKS_PLATFORM
|
||||
#define SECUREC_VXWORKS_PLATFORM
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */
|
||||
#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && !defined(SECUREC_VXWORKS_PLATFORM)
|
||||
#ifndef SECUREC_COMPATIBLE_LINUX_FORMAT
|
||||
#define SECUREC_COMPATIBLE_LINUX_FORMAT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
|
||||
#ifndef SECUREC_HAVE_STDDEF_H
|
||||
#define SECUREC_HAVE_STDDEF_H 1
|
||||
#endif
|
||||
/* Some system may no stddef.h */
|
||||
#if SECUREC_HAVE_STDDEF_H
|
||||
#if !SECUREC_IN_KERNEL
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Add the -DSECUREC_SUPPORT_FORMAT_WARNING=1 compiler option to supoort -Wformat=2.
|
||||
* Default does not check the format is that the same data type in the actual code.
|
||||
* In the product is different in the original data type definition of VxWorks and Linux.
|
||||
*/
|
||||
#ifndef SECUREC_SUPPORT_FORMAT_WARNING
|
||||
#define SECUREC_SUPPORT_FORMAT_WARNING 0
|
||||
#endif
|
||||
|
||||
#if SECUREC_SUPPORT_FORMAT_WARNING
|
||||
#define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y))))
|
||||
#else
|
||||
#define SECUREC_ATTRIBUTE(x, y)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Add the -DSECUREC_SUPPORT_BUILTIN_EXPECT=0 compiler option, if compiler can not support __builtin_expect.
|
||||
*/
|
||||
#ifndef SECUREC_SUPPORT_BUILTIN_EXPECT
|
||||
#define SECUREC_SUPPORT_BUILTIN_EXPECT 1
|
||||
#endif
|
||||
|
||||
#if SECUREC_SUPPORT_BUILTIN_EXPECT && defined(__GNUC__) && ((__GNUC__ > 3) || \
|
||||
(defined(__GNUC_MINOR__) && (__GNUC__ == 3 && __GNUC_MINOR__ > 3)))
|
||||
/*
|
||||
* This is a built-in function that can be used without a declaration, if warning for declaration not found occurred,
|
||||
* you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to compiler options
|
||||
*/
|
||||
#ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE
|
||||
long __builtin_expect(long exp, long c);
|
||||
#endif
|
||||
|
||||
#define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define SECUREC_LIKELY(x) (x)
|
||||
#define SECUREC_UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
/* Define the max length of the string */
|
||||
#ifndef SECUREC_STRING_MAX_LEN
|
||||
#define SECUREC_STRING_MAX_LEN 0x7fffffffUL
|
||||
#endif
|
||||
#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t))
|
||||
|
||||
/* Add SECUREC_MEM_MAX_LEN for memcpy and memmove */
|
||||
#ifndef SECUREC_MEM_MAX_LEN
|
||||
#define SECUREC_MEM_MAX_LEN 0x7fffffffUL
|
||||
#endif
|
||||
#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t))
|
||||
|
||||
#if SECUREC_STRING_MAX_LEN > 0x7fffffffUL
|
||||
#error "max string is 2G"
|
||||
#endif
|
||||
|
||||
#if (defined(__GNUC__) && defined(__SIZEOF_POINTER__))
|
||||
#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8)
|
||||
#error "unsupported system"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64)
|
||||
#define SECUREC_ON_64BITS
|
||||
#endif
|
||||
|
||||
#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__))
|
||||
#if __SIZEOF_POINTER__ == 8
|
||||
#define SECUREC_ON_64BITS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__SVR4) || defined(__svr4__)
|
||||
#define SECUREC_ON_SOLARIS
|
||||
#endif
|
||||
|
||||
#if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS))
|
||||
#define SECUREC_ON_UNIX
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknown system on default,
|
||||
* and strtold.
|
||||
* The function strtold is referenced first at ISO9899:1999(C99), and some old compilers can
|
||||
* not support these functions. Here provides a macro to open these functions:
|
||||
* SECUREC_SUPPORT_STRTOLD -- If defined, strtold will be used
|
||||
*/
|
||||
#ifndef SECUREC_SUPPORT_STRTOLD
|
||||
#define SECUREC_SUPPORT_STRTOLD 0
|
||||
#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT))
|
||||
#if defined(__USE_ISOC99) || \
|
||||
(defined(_AIX) && defined(_ISOC99_SOURCE)) || \
|
||||
(defined(__hpux) && defined(__ia64)) || \
|
||||
(defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
|
||||
defined(_STDC_C99) || defined(__EXTENSIONS__))
|
||||
#undef SECUREC_SUPPORT_STRTOLD
|
||||
#define SECUREC_SUPPORT_STRTOLD 1
|
||||
#endif
|
||||
#endif
|
||||
#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_)))
|
||||
#undef SECUREC_SUPPORT_STRTOLD
|
||||
#define SECUREC_SUPPORT_STRTOLD 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
|
||||
#ifndef SECUREC_TWO_MIN
|
||||
#define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/* For strncpy_s performance optimization */
|
||||
#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \
|
||||
(((void *)(dest) != NULL && (const void *)(src) != NULL && (size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
|
||||
(SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \
|
||||
(((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \
|
||||
(memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count))))
|
||||
|
||||
#define SECUREC_STRCPY_SM(dest, destMax, src) \
|
||||
(((void *)(dest) != NULL && (const void *)(src) != NULL && (size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
|
||||
(strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \
|
||||
(strcpy_error((dest), (destMax), (src))))
|
||||
|
||||
/* For strcat_s performance optimization */
|
||||
#if defined(__GNUC__)
|
||||
#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \
|
||||
int catRet_ = EOK; \
|
||||
if ((void *)(dest) != NULL && (const void *)(src) != NULL && (size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
|
||||
char *catTmpDst_ = (char *)(dest); \
|
||||
size_t catRestSize_ = (destMax); \
|
||||
while (catRestSize_ > 0 && *catTmpDst_ != '\0') { \
|
||||
++catTmpDst_; \
|
||||
--catRestSize_; \
|
||||
} \
|
||||
if (catRestSize_ == 0) { \
|
||||
catRet_ = EINVAL; \
|
||||
} else if ((strlen(src) + 1) <= catRestSize_) { \
|
||||
memcpy(catTmpDst_, (src), strlen(src) + 1); \
|
||||
catRet_ = EOK; \
|
||||
} else { \
|
||||
catRet_ = ERANGE; \
|
||||
} \
|
||||
if (catRet_ != EOK) { \
|
||||
catRet_ = strcat_s((dest), (destMax), (src)); \
|
||||
} \
|
||||
} else { \
|
||||
catRet_ = strcat_s((dest), (destMax), (src)); \
|
||||
} \
|
||||
catRet_; \
|
||||
})
|
||||
#else
|
||||
#define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src))
|
||||
#endif
|
||||
|
||||
/* For strncat_s performance optimization */
|
||||
#if defined(__GNUC__)
|
||||
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \
|
||||
int ncatRet_ = EOK; \
|
||||
if ((void *)(dest) != NULL && (const void *)(src) != NULL && (size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
|
||||
(((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
|
||||
char *ncatTmpDest_ = (char *)(dest); \
|
||||
size_t ncatRestSize_ = (size_t)(destMax); \
|
||||
while (ncatRestSize_ > 0 && *ncatTmpDest_ != '\0') { \
|
||||
++ncatTmpDest_; \
|
||||
--ncatRestSize_; \
|
||||
} \
|
||||
if (ncatRestSize_ == 0) { \
|
||||
ncatRet_ = EINVAL; \
|
||||
} else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize_) { \
|
||||
if ((size_t)(count) < strlen(src)) { \
|
||||
memcpy(ncatTmpDest_, (src), (count)); \
|
||||
*(ncatTmpDest_ + (count)) = '\0'; \
|
||||
} else { \
|
||||
memcpy(ncatTmpDest_, (src), strlen(src) + 1); \
|
||||
} \
|
||||
} else { \
|
||||
ncatRet_ = ERANGE; \
|
||||
} \
|
||||
if (ncatRet_ != EOK) { \
|
||||
ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \
|
||||
} \
|
||||
} else { \
|
||||
ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \
|
||||
} \
|
||||
ncatRet_; \
|
||||
})
|
||||
#else
|
||||
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count))
|
||||
#endif
|
||||
|
||||
/* This macro do not check buffer overlap by default */
|
||||
#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \
|
||||
(!(((size_t)(destMax) == 0) || \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
|
||||
((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((const void *)(src) == NULL)) ? \
|
||||
(memcpy((dest), (src), (count)), EOK) : \
|
||||
(memcpy_s((dest), (destMax), (src), (count))))
|
||||
|
||||
#define SECUREC_MEMSET_SM(dest, destMax, c, count) \
|
||||
(!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
|
||||
((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \
|
||||
(memset((dest), (c), (count)), EOK) : \
|
||||
(memset_s((dest), (destMax), (c), (count))))
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
|
||||
#ifndef __STEP_H_
|
||||
#define __STEP_H_
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef CONFIG_LOTUS_EDA
|
||||
#ifdef __ASSEMBLY__
|
||||
|
||||
.macro step, num
|
||||
push {r11, r12}
|
||||
|
||||
ldr r11, = SYS_CTRL_REG_BASE
|
||||
mov r12, #\num
|
||||
str r12, [r11, #REG_SC_SYSBOOT2]
|
||||
|
||||
pop {r11, r12}
|
||||
.endm
|
||||
|
||||
.macro step_no_stack, num, tmp_reg1, tmp_reg2
|
||||
ldr \tmp_reg1, = SYS_CTRL_REG_BASE
|
||||
mov \tmp_reg2, #\num
|
||||
str \tmp_reg2, [\tmp_reg1, #REG_SC_SYSBOOT2]
|
||||
.endm
|
||||
|
||||
#else
|
||||
#define step(x) ((*(volatile u32 *) (SYS_CTRL_REG_BASE + REG_SC_SYSBOOT2)) = (x))
|
||||
#endif
|
||||
#else
|
||||
#ifdef __ASSEMBLY__
|
||||
.macro step, num
|
||||
.endm
|
||||
.macro step_no_stack, num, tmp_reg1, tmp_reg2
|
||||
.endm
|
||||
#else
|
||||
#define step(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /*__STEP_H_*/
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*
|
||||
* File: param_atags.h
|
||||
*
|
||||
* Author: Lynn
|
||||
* Created: 12/07/22
|
||||
* Description: Param tag API and data structure
|
||||
*****************************************************************************/
|
||||
#ifndef _PARAM_ATAGS_H
|
||||
#define _PARAM_ATAGS_H
|
||||
|
||||
#include <asm/setup.h>
|
||||
|
||||
void set_param_data(const char *name, const char *buf, int buflen);
|
||||
int get_param_tag_data(char *tagbuf);
|
||||
|
||||
void setup_atags(char *fdt, int fdt_size);
|
||||
void setup_board_tags(struct tag **in_params);
|
||||
|
||||
#endif /* _PARAM_ATAGS_H */
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#ifndef __LOTUS_TIMESTAMP_H__
|
||||
#define __LOTUS_TIMESTAMP_H__
|
||||
|
||||
#include <config.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
|
||||
typedef u64 timestamp_type;
|
||||
|
||||
/*
|
||||
* timestamps storage arrangement
|
||||
* |-----Timestamp Item----|-----Timestamp Item----| ...
|
||||
* |stamp|func |line |type |stamp|func |line |type | ...
|
||||
*/
|
||||
#pragma pack(4)
|
||||
typedef struct {
|
||||
timestamp_type stamp;
|
||||
char *func;
|
||||
u32 line;
|
||||
u32 type;
|
||||
} timestamp_item;
|
||||
#pragma pack()
|
||||
|
||||
#define TIME_STAMP(type) timestamp_mark(__func__, __LINE__, type)
|
||||
|
||||
void timestamp_mark(const char *func, u32 line, u32 type);
|
||||
void timestamp_print(u32 type);
|
||||
void timestamp_clear(void);
|
||||
|
||||
void stopwatch_trigger(void);
|
||||
void stopwatch_clear(void);
|
||||
void stopwatch_print(void);
|
||||
#endif /* __LOTUS_TIMESTAMP_H__ */
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef USB_VENDOR_H
|
||||
#define USB_VENDOR_H
|
||||
|
||||
enum usb_init_types {
|
||||
LOTUS_DWC_U3 = 0, /* usb3 controller is default */
|
||||
LOTUS_DWC_U2 = 1, /* usb2 controller */
|
||||
LOTUS_USB_CTRL_UNKNOWN = 2, /* unknown controller */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_USB_DUAL_PORT_SUPPORT
|
||||
void phy_usb_init(int index, int type);
|
||||
#else
|
||||
void phy_usb_init(int index);
|
||||
#endif
|
||||
void udc_connect(void);
|
||||
void udc_puts(const char *s);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user