Files
2025-12-03 11:12:34 +08:00

212 lines
5.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef __TZFLASH_API_H__
#define __TZFLASH_API_H__
#include "typedef.h"
#include "device.h"
struct flash_func_len {
u16 all_len;
u8 version;
u8 func_len;//lb
u8 sta_len;//lb
u8 func_otp;//lb
u8 func_dtr;
u8 func_wp;//bp,tb,sec,cmp
u8 func_wps;
u8 func_wps_op;
u8 func_qe;
u8 func_srp;
u8 func_sus;
u8 func_dc;
u8 func_drv;
u8 func_mpm;//dp
u8 func_qpi;
u8 func_init;
u8 func_read_continue;
} __attribute__((packed));
#define TZFLASH_STA_NUM 4
struct flash_sta_cmd {
u8 sta_cmd_r[TZFLASH_STA_NUM];
u8 sta_cmd_w[TZFLASH_STA_NUM];
} __attribute__((packed));
struct flash_otp_cfg {//flash otp信息
u32 otp_offset[5];//otp page的偏移地址组数
u16 otp_page_size;//otp的page大小
u8 otp_NumberOfpage;//otp的page数量
// struct flash_reg lock_cfg[2];//read,write
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
u8 sr_mask[TZFLASH_STA_NUM];
u8 sr_value[TZFLASH_STA_NUM];//注意:锁定后不可擦写,sr的值也常是1
} __attribute__((packed));
struct flash_wps_cfg {//flash wps信息
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
u8 sr_mask[TZFLASH_STA_NUM];
u8 sr_value[TZFLASH_STA_NUM];
// struct flash_reg r_reg_cfg;//read
// struct flash_reg w_reg_cfg;//write
} __attribute__((packed));
struct flash_wp_cfg { //写保护配置信息
u8 numOfwp_array;//写保护参数的个数
u8 wr_en_cmd;//0x50h:sr,06h:
u8 sr_mask[TZFLASH_STA_NUM]; //sr要保留或修改的bit
struct {
u8 sr_value[TZFLASH_STA_NUM]; //写保护sr取值
u16 wp_addr;//写保护结束地址,单位K
} wp_array[0]; //写保护的组数,修改可变长
} __attribute__((packed));
struct flash_dtr_cfg {
s8 x1_dummy;//-1:使用默认值
s8 x2_dummy;//-1:使用默认值
s8 x4_dummy;//-1:使用默认值,-2:不支持
} __attribute__((packed));
struct flash_io_drv {
u8 cs_drv: 2;
u8 clk_drv: 2;
u8 do_drv: 2;
u8 di_drv: 2;
u8 d2_drv: 2;
u8 d3_drv: 2;
} __attribute__((packed));
struct flash_reg {
u8 cmd[4];
u8 sr_value[4];
u8 sr_mask[4];
u8 continue_mode: 4;
u8 num_of_reg: 2;
u8 wr_en_mode: 1;
u8 rev: 1;
};
#define FLASH_SUPPORT_MPM_FUNC 0
#define FLASH_SUPPORT_DC_FUNC 0
#define FLASH_SUPPORT_QPI_FUNC 0
#if FLASH_SUPPORT_MPM_FUNC
struct flash_mpm_cfg {//flash 多page模式;无该功能配0
u16 mpm_size;//page len:256/512/1024/4096; 默认:0256byte
u8 sr_mask[TZFLASH_STA_NUM];
u8 sr_value[TZFLASH_STA_NUM];
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
//页擦除命令擦除大小为mpm_size
} __attribute__((packed));
#endif
#if FLASH_SUPPORT_DC_FUNC
//dummy:cfg
//spi模式下:str:bbh,ebh
// dtr:bdh,edh
//qpi: dtr:0dh,edh
struct flash_dc_cfg {//flash dc信息。
u32 dtr_freq;
u32 str_freq;
u8 dtr_2io_NumberOfdummy;//bdh 含M7-M0
u8 dtr_4io_NumberOfdummy;//edh 含M7-M0
u8 str_2io_NumberOfdummy;//bbh 含M7-M0
u8 str_4io_NumberOfdummy;//ebh 含M7-M0
// struct flash_reg reg_cfg[2];//read,write
u8 sr_mask[TZFLASH_STA_NUM];//set DC
u8 sr_value[TZFLASH_STA_NUM];
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
} __attribute__((packed));
#endif
#if FLASH_SUPPORT_QPI_FUNC
//dummy:cfg
//qpi: str:0bh,ebh(C0H)
// dtr:0dh,edh(DC)
struct flash_qpi_cfg {//flash dc信息
u32 dtr_freq;
u32 str_freq;
u8 dtr_1io_NumberOfdummy;//0dh
u8 dtr_4io_NumberOfdummy;//edh
u8 str_1io_NumberOfdummy;//0bh
u8 str_4io_NumberOfdummy;//ebh
// struct flash_reg reg_cfg[2];//read,write
u8 sr_mask[TZFLASH_STA_NUM];//set DC,cmd_w与qpi_cmd_w只能二选一,不能同时赋值
u8 sr_value[TZFLASH_STA_NUM];//set DC
u8 wr_en_cmd; //set DC//0x50h:sr,0x06h:wr_en
u8 qpi_cmd_w;//set C0H
u8 qpi_dummy_wl_value;//dummy & wrap len
u8 qpi_dummy_wl_mask;//cmd_w与qpi_cmd_w只能二选一,不能同时赋值
} __attribute__((packed));
#endif
struct flash_wps_area_cfg {
u32 start_addr;//任意地址,非对齐时不包含地址所在块
u32 end_addr;//任意地址,非对齐时不包含地址所在块
u8 lock_en;//1:保护, 0:解保护
} __attribute__((packed)); //size(1byte)
typedef enum {
TEE_SUCCESS = 0,
TEE_ERROR_TZASC_OUT_OF_IDX = 1,
TEE_ERROR_TZASC_IDX_CONFLICT = 2,
TEE_ERROR_TZASC_IDX_ACCESS_DENIED = 3,
TEE_ERROR_TZMPU_OUT_OF_IDX = 4,
TEE_ERROR_TZMPU_IDX_CONFLICT = 5,
TEE_ERROR_TZMPU_IDX_ACCESS_DENIED = 6,
TEE_ERROR_OUT_OF_MEMORY = 7,
TEE_ERROR_NOT_FOUND_TA = 8,
TEE_ERROR_EINVAL = 22, /* Invalid argument */
TEE_ERROR_ACCESS_DENIED = 23,
} TEE_Result;
struct tzspi_target {
void (*suspend)(u32 id);
void (*resume)(u32 id);
};
#define REGISTER_TZSPI_TARGET(target) \
const struct tzspi_target target SEC_USED(.tzspi_target)
extern const struct tzspi_target tzspi_target_begin[];
extern const struct tzspi_target tzspi_target_end[];
#define list_for_each_tzspi_target(p) \
for (p = tzspi_target_begin; p < tzspi_target_end; p++)
int tzflash_init(void *arg);
int tzflash_origin_read(u8 *buf, u32 offset, u32 len);
int tzflash_read(void *buf, u32 len, u32 offset);
int tzflash_write(const void *buf, u32 len, u32 offset);
int tzflash_ioctl(u32 cmd, u32 arg);
void tzflash_dump();
u32 sfc0_flash_addr2cpu_addr(u32 offset);
void tzflash_read_uuid(u8 *buf);
u8 *tzflash_get_uuid(void);
u32 tzflash_erase_otp();
u32 tzflash_read_otp(void *buf, u32 len, u32 addr);
u32 tzflash_write_otp(const u8 *buf, u32 len, u32 addr);
void tzflash_vm_info_set(void *_arg, u8 early_mode);
void tzflash_mutex_enter();
void tzflash_mutex_exit();
int tzflash_set_write_protect(u32 lock_en, u32 wp_s_addr, u32 wp_e_addr);
void tzflash_change_mode();//dtr(clk),continue,wps
u32 syscfg_read_otp(u32 id, u8 *buf, u32 len);
#endif