mirror of
https://gitee.com/Vancouver2017/luban-lite.git
synced 2025-12-25 21:48:54 +00:00
v1.2.1
This commit is contained in:
@@ -8,7 +8,7 @@ CPPPATH = []
|
||||
LOCAL_CFLAGS = ''
|
||||
|
||||
if GetDepend('LPKG_USING_SFUD'):
|
||||
src += ['src/sfud.c', 'src/sfud_qe.c']
|
||||
src += ['src/sfud.c', 'src/sfud_qe.c', 'src/sfud_private.c']
|
||||
src += ['src/sfud_sfdp.c']
|
||||
CPPPATH += [cwd + '/inc']
|
||||
|
||||
|
||||
@@ -193,6 +193,7 @@ sfud_err sfud_read_cr(const sfud_flash *flash, uint8_t *status);
|
||||
sfud_err sfud_read_secur(const sfud_flash *flash, uint8_t reg, uint8_t *data);
|
||||
sfud_err sfud_erase_secur(const sfud_flash *flash, uint8_t reg);
|
||||
sfud_err sfud_write_secur(const sfud_flash *flash, uint8_t reg, size_t size, const uint8_t *data);
|
||||
sfud_err sfud_read_unique_id(const sfud_flash *flash, uint8_t *send_bytes, uint8_t id_len, uint8_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -205,6 +205,14 @@ extern void sfud_log_info(const char *format, ...);
|
||||
#define SFUD_WRITE_MAX_PAGE_SIZE 256
|
||||
#endif
|
||||
|
||||
#ifndef SFUD_CMD_FAST_READ
|
||||
#define SFUD_CMD_FAST_READ 0x0B
|
||||
#endif
|
||||
|
||||
#ifndef SFUD_MIN_FREQ_FAST_READ
|
||||
#define SFUD_MIN_FREQ_FAST_READ 55000000
|
||||
#endif
|
||||
|
||||
/* send dummy data for read data */
|
||||
#ifndef SFUD_DUMMY_DATA
|
||||
#define SFUD_DUMMY_DATA 0xFF
|
||||
@@ -367,10 +375,11 @@ typedef struct {
|
||||
uint32_t init_hz; /** Reading SFDP, bus frequency should be <=50MHz, this is requirement from SPEC */
|
||||
uint32_t bus_hz; /** Working bus frequency */
|
||||
#endif
|
||||
|
||||
void *get_uid;
|
||||
} sfud_flash, *sfud_flash_t;
|
||||
|
||||
typedef void (*quad_enable_func)(sfud_flash *flash);
|
||||
typedef int (*get_uid_func)(sfud_flash *flash, uint8_t *data);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -87,6 +87,17 @@ typedef struct {
|
||||
} sfud_qspi_flash_qe_info;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t mf_id; /**< manufacturer ID */
|
||||
uint8_t type_id; /**< memory type ID */
|
||||
uint8_t capacity_id; /**< capacity ID */
|
||||
uint8_t rd_cmd; /**< instruction of read Unique ID number */
|
||||
uint8_t byte1; /**< the 1st byte was sent to device immediately following the instruction */
|
||||
uint8_t byte2; /**< the 2nd byte was sent to device immediately following the instruction */
|
||||
uint8_t byte3; /**< the 3rd byte was sent to device immediately following the instruction */
|
||||
uint8_t byte4; /**< the 4th byte was sent to device immediately following the instruction */
|
||||
uint8_t id_len; /**< the length of Unique ID number, in bytes */
|
||||
} sfud_qspi_flash_private_info;
|
||||
|
||||
/* SFUD support manufacturer JEDEC ID */
|
||||
#define SFUD_MF_ID_CYPRESS 0x01
|
||||
@@ -108,6 +119,46 @@ typedef struct {
|
||||
#define SFUD_MF_ID_ISSI 0xD5
|
||||
#define SFUD_MF_ID_WINBOND 0xEF
|
||||
#define SFUD_MF_ID_ZETTA 0xBA
|
||||
#define SFUD_MF_ID_BOYA 0x68
|
||||
#define SFUD_MF_ID_XTX 0x0B
|
||||
#define SFUD_MF_ID_PUYA 0x85
|
||||
|
||||
/* | name | mf_id | type_id | read—_uid_cmd | addr0 | addr1 | addr2 | addr3 | id_len | */
|
||||
#define SFUD_FLASH_PRIVATE_INFO_TABLE \
|
||||
{ \
|
||||
/* BOYA128B */ \
|
||||
{SFUD_MF_ID_BOYA, 0x40, 0x18, 0x48, 0x0, 0x0, 0x0, 0x0, 16}, \
|
||||
/* BOYA32B */ \
|
||||
{SFUD_MF_ID_BOYA, 0x49, 0x19, 0x48, 0x0, 0x0, 0x0, 0x0, 16}, \
|
||||
/* XTX128B */ \
|
||||
{SFUD_MF_ID_XTX, 0x40, 0x18, 0x5A, 0x0, 0x0, 0x94, 0xff, 16}, \
|
||||
/* "GD25Q256B", */ \
|
||||
{SFUD_MF_ID_GIGADEVICE, 0x40, 0x19, 0x4B, 0xff, 0xff, 0xff, 0xff, 16}, \
|
||||
/* "GD25Q128B", */ \
|
||||
{SFUD_MF_ID_GIGADEVICE, 0x40, 0x18, 0x4B, 0x0, 0x0, 0x0, 0xff, 16}, \
|
||||
/* "GD25Q64B" */ \
|
||||
{SFUD_MF_ID_GIGADEVICE, 0x40, 0x17, 0x4B, 0x0, 0x0, 0x0, 0xff, 16}, \
|
||||
/* "GD25Q32B" */ \
|
||||
{SFUD_MF_ID_GIGADEVICE, 0x40, 0x16, 0x4B, 0x0, 0x0, 0x0, 0xff, 16}, \
|
||||
/* PUYA256B */ \
|
||||
{SFUD_MF_ID_PUYA, 0x20, 0x19, 0x4B, 0xff, 0xff, 0xff, 0xff, 16}, \
|
||||
/* PUYA128B */ \
|
||||
{SFUD_MF_ID_PUYA, 0x20, 0x18, 0x4B, 0xff, 0xff, 0xff, 0xff, 16}, \
|
||||
/* PUYA64B */ \
|
||||
{SFUD_MF_ID_PUYA, 0x20, 0x17, 0x4B, 0xff, 0xff, 0xff, 0xff, 16}, \
|
||||
/* PUYA32B */ \
|
||||
{SFUD_MF_ID_PUYA, 0x20, 0x16, 0x4B, 0xff, 0xff, 0xff, 0xff, 16}, \
|
||||
/* PUYA16B */ \
|
||||
{SFUD_MF_ID_PUYA, 0x20, 0x15, 0x4B, 0xff, 0xff, 0xff, 0xff, 16}, \
|
||||
/* ZB25VQ128 */ \
|
||||
{SFUD_MF_ID_ZBIT, 0x40, 0x18, 0x4B, 0x0, 0x0, 0x0, 0xff, 16}, \
|
||||
/* ZB25VQ164 */ \
|
||||
{SFUD_MF_ID_ZBIT, 0x40, 0x17, 0x4B, 0x0, 0x0, 0x0, 0xff, 16}, \
|
||||
/* ZB25VQ132 */ \
|
||||
{SFUD_MF_ID_ZBIT, 0x40, 0x16, 0x4B, 0x0, 0x0, 0x0, 0xff, 16}, \
|
||||
/* ZB25VQ116 */ \
|
||||
{SFUD_MF_ID_ZBIT, 0x40, 0x15, 0x4B, 0x0, 0x0, 0x0, 0xff, 16}, \
|
||||
}
|
||||
|
||||
/* SFUD supported manufacturer information table */
|
||||
#define SFUD_MF_TABLE \
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "../inc/sfud.h"
|
||||
#include "sfud_qe.h"
|
||||
#include <string.h>
|
||||
#include "sfud_private.h"
|
||||
|
||||
/* send dummy data for read data */
|
||||
#define DUMMY_DATA 0xFF
|
||||
@@ -238,7 +239,12 @@ sfud_err sfud_qspi_fast_read_enable(sfud_flash *flash, uint8_t data_line_width)
|
||||
/* determine qspi supports which read mode and set read_cmd_format struct */
|
||||
switch (data_line_width) {
|
||||
case 1:
|
||||
qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1);
|
||||
#ifdef SFUD_USING_SFDP
|
||||
if (flash->bus_hz > SFUD_MIN_FREQ_FAST_READ)
|
||||
qspi_set_read_cmd_format(flash, SFUD_CMD_FAST_READ, 1, 1, 8, 1);
|
||||
else
|
||||
#endif
|
||||
qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1);
|
||||
break;
|
||||
case 2:
|
||||
if (read_mode & DUAL_IO) {
|
||||
@@ -432,6 +438,8 @@ static sfud_err hardware_init(sfud_flash *flash) {
|
||||
qe(flash);
|
||||
#endif /* SFUD_USING_QSPI */
|
||||
|
||||
flash->get_uid = spi_nor_get_unique_id;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1560,3 +1568,33 @@ __exit:
|
||||
return result;
|
||||
}
|
||||
#endif // SFUD_USING_SECURITY_REGISTER
|
||||
|
||||
sfud_err sfud_read_unique_id(const sfud_flash *flash, uint8_t *send_bytes, uint8_t id_len, uint8_t *data)
|
||||
{
|
||||
sfud_err result = SFUD_SUCCESS;
|
||||
const sfud_spi *spi = &flash->spi;
|
||||
static uint8_t cmd_data[5 + 16];
|
||||
|
||||
SFUD_ASSERT(flash);
|
||||
|
||||
/* must be call this function after initialize OK */
|
||||
SFUD_ASSERT(flash->init_ok);
|
||||
/* lock SPI */
|
||||
if (spi->lock) {
|
||||
spi->lock(spi);
|
||||
}
|
||||
|
||||
memcpy(cmd_data, send_bytes, 5);
|
||||
result = spi->wr(spi, cmd_data, 5, cmd_data + 5, id_len);
|
||||
memcpy(data, &cmd_data[5], 8);
|
||||
|
||||
/* unlock SPI */
|
||||
if (spi->unlock) {
|
||||
spi->unlock(spi);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
return id_len;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
55
bsp/peripheral/spinor_sfud/src/sfud_private.c
Normal file
55
bsp/peripheral/spinor_sfud/src/sfud_private.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2025, ArtInChip Technology Co., Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "../inc/sfud.h"
|
||||
#include <string.h>
|
||||
#include "sfud_flash_def.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static const sfud_qspi_flash_private_info qspi_flash_private_info_table[] = SFUD_FLASH_PRIVATE_INFO_TABLE;
|
||||
|
||||
int spi_nor_get_unique_id(sfud_flash *flash, uint8_t *data)
|
||||
{
|
||||
uint8_t id_len = 16;
|
||||
int ret = 0;
|
||||
uint8_t *send_byte;
|
||||
|
||||
send_byte = malloc(5 * sizeof(uint8_t));
|
||||
if (!send_byte) {
|
||||
SFUD_INFO("Malloc failed!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Default situation of readding Unique ID Number.
|
||||
* SI byte0: instruction 0x4b
|
||||
* SI byte1 - byte4: 4 bytes dummy
|
||||
* SO 128-bit Unique Serial Number
|
||||
* */
|
||||
memset(send_byte, 0xff, 5 * sizeof(uint8_t));
|
||||
send_byte[0] = 0x4b;
|
||||
|
||||
for (int i = 0;
|
||||
i < sizeof(qspi_flash_private_info_table) / sizeof(sfud_qspi_flash_private_info); i++) {
|
||||
if ((qspi_flash_private_info_table[i].mf_id == flash->chip.mf_id) &&
|
||||
(qspi_flash_private_info_table[i].type_id == flash->chip.type_id) &&
|
||||
(qspi_flash_private_info_table[i].capacity_id ==
|
||||
flash->chip.capacity_id)) {
|
||||
send_byte[0] = qspi_flash_private_info_table[i].rd_cmd;
|
||||
send_byte[1] = qspi_flash_private_info_table[i].byte1;
|
||||
send_byte[2] = qspi_flash_private_info_table[i].byte2;
|
||||
send_byte[3] = qspi_flash_private_info_table[i].byte3;
|
||||
send_byte[4] = qspi_flash_private_info_table[i].byte4;
|
||||
id_len = qspi_flash_private_info_table[i].id_len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = sfud_read_unique_id(flash, send_byte, id_len, data);
|
||||
free (send_byte);
|
||||
|
||||
return ret;
|
||||
}
|
||||
22
bsp/peripheral/spinor_sfud/src/sfud_private.h
Normal file
22
bsp/peripheral/spinor_sfud/src/sfud_private.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2025, ArtInChip Technology Co., Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _SFUD_PRIVATE_H_
|
||||
#define _SFUD_PRIVATE_H_
|
||||
|
||||
#include "sfud_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int spi_nor_get_unique_id(sfud_flash *flash, uint8_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SFUD_PRIVATE_H_ */
|
||||
Reference in New Issue
Block a user