Files
kunlun/mfgtool/efuse_prog_done/efuse_prog_done.c
2024-09-28 14:24:04 +08:00

112 lines
3.8 KiB
C

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#include "os_types.h"
#include "iot_io.h"
#include "dbg_io.h"
#include "hw_reg_api.h"
#include "efuse.h"
#include "efuse_mapping.h"
#define EFUSE_DONE_OK 0
#define EFUSE_EMPTY 1
#define EFUSE_ERROR_DATA 2
uint8_t efuse_prog_done()
{
uint32_t i = 0;
uint32_t tmp = 0;
bool_t check_empty = true;
/* check 2048 efuse bit */
for(i = 0; i < 64; i++) {
tmp = efuse_read(i*4);
if (tmp != 0) {
check_empty = false;
}
}
if (check_empty == true) {
iot_printf("This is empty board, do nothing\n");
return EFUSE_EMPTY;
} else {
/* check mac addr */
tmp = efuse_read(CFG_EFUSE_BITS32_7_ADDR);
iot_printf("efuse pkg version: %x\n",
(tmp & VERSION_PKG_MASK)>>VERSION_PKG_OFFSET);
tmp = efuse_read(CFG_EFUSE_BITS32_0_ADDR);
iot_printf("efuse wafer version: %x\n",
(tmp & VERSION_WAFER_MASK)>>VERSION_WAFER_OFFSET);
iot_printf("efuse reserve version: %x\n",
(tmp & VERSION_WAFER_MASK)>>VERSION_WAFER_OFFSET);
tmp = efuse_read(CFG_EFUSE_BITS32_2_ADDR);
if(0x48 != REG_FIELD_GET(MAC_ADDR_B0,tmp)){
iot_printf("efuse mac address error\n");
return EFUSE_ERROR_DATA;
}
tmp = efuse_read(CFG_EFUSE_BITS32_3_ADDR);
if(0x55 != REG_FIELD_GET(MAC_ADDR_B1,tmp)){
iot_printf("efuse mac address error\n");
return EFUSE_ERROR_DATA;
}
tmp = efuse_read(CFG_EFUSE_BITS32_3_ADDR);
if(0x5c != REG_FIELD_GET(MAC_ADDR_B2,tmp)){
iot_printf("efuse mac address error\n");
return EFUSE_ERROR_DATA;
}
/* efuse prog done */
tmp = efuse_read(CFG_EFUSE_BITS32_0_ADDR);
if (0x1 != REG_FIELD_GET(VENDOR_EFUSE_PROG_DONE, tmp) ||
0x1 != REG_FIELD_GET(VENDOR_EFUSE_PROG_DONE_BACKUP, tmp)) {
iot_printf("efuse program done bit is 0, set it to 1\n");
tmp = 0;
REG_FIELD_SET(VENDOR_EFUSE_PROG_DONE, tmp, 1);
REG_FIELD_SET(VENDOR_EFUSE_PROG_DONE_BACKUP, tmp, 1);
efuse_write(CFG_EFUSE_BITS32_0_ADDR, tmp);
}
/* efuse: user space prog done */
tmp = efuse_read(0x20);
if (((tmp & 0x10000) == 0) || ((tmp & 0x1000000) == 0)) {
iot_printf("efuse user program done bit is 0, set it to 1\n");
tmp = 0;
tmp |= (1 << 16);
tmp |= (1 << 24);
efuse_write(0x20, tmp);
}
return EFUSE_DONE_OK;
}
}
int main(void)
{
uint8_t ret = 0;
dbg_uart_init();
iot_printf("start testing\n");
ret = efuse_prog_done();
if (ret == EFUSE_EMPTY) {
iot_printf("efuse empty, result: ###program done failed###\n");
} else if (ret == EFUSE_ERROR_DATA) {
iot_printf("efuse data not match, result: ###program done failed###\n");
} else if ( ret == EFUSE_DONE_OK) {
iot_printf("efuse program done , result: ###program done successful###\n");
}
return 0;
}