1891 lines
52 KiB
C
1891 lines
52 KiB
C
/*
|
||
System Storage Callback
|
||
|
||
System Callback for Storage Module.
|
||
|
||
@file SysStrg_Exe.c
|
||
@ingroup mIPRJSYS
|
||
|
||
@note <20>o<EFBFBD><6F><EFBFBD>ɮt<D7AD>d<EFBFBD>@<40><><EFBFBD>
|
||
|
||
1.<2E><><EFBFBD><EFBFBD>Storage Event<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
<20>i<EFBFBD>event<6E><74>:
|
||
|
||
STRG_INSERT --- <20>N<EFBFBD><4E><EFBFBD>CARD<52><44><EFBFBD>J
|
||
<20><><EFBFBD><EFBFBD>unmount<6E><74><EFBFBD>e<EFBFBD>ݭn<DDAD><6E><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>
|
||
<20>I<EFBFBD>sFile unmound (NAND),
|
||
<20><><EFBFBD><EFBFBD>mount<6E><74><EFBFBD>e<EFBFBD>ݭn<DDAD><6E><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>
|
||
<20>I<EFBFBD>sFile mount (CARD)
|
||
|
||
STRG_REMOVE --- <20>N<EFBFBD><4E><EFBFBD>CARD<52>ޥX
|
||
<20><><EFBFBD><EFBFBD>unmount<6E><74><EFBFBD>e<EFBFBD>ݭn<DDAD><6E><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>
|
||
<20>I<EFBFBD>sFile unmount (CARD)
|
||
<20><><EFBFBD><EFBFBD>mount<6E><74><EFBFBD>e<EFBFBD>ݭn<DDAD><6E><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>
|
||
<20>I<EFBFBD>sFile_mount (NAND)
|
||
|
||
STRG_ATTACH --- <20>N<EFBFBD><4E>File mount<6E><74><EFBFBD><EFBFBD>
|
||
<20><><EFBFBD><EFBFBD>mount<6E><74><EFBFBD><EFBFBD>ݭn<DDAD><6E><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>
|
||
<20>o<EFBFBD><6F>|<7C>ǤJmount<6E><74><EFBFBD><EFBFBD><EFBFBD>Gstatus
|
||
|
||
STRG_DETACH --- <20>N<EFBFBD><4E>File unmount<6E><74><EFBFBD><EFBFBD>
|
||
<20><><EFBFBD><EFBFBD>unmount<6E><74><EFBFBD><EFBFBD>ݭn<DDAD><6E><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>
|
||
<20>o<EFBFBD><6F>|<7C>ǤJunmount<6E><74><EFBFBD><EFBFBD><EFBFBD>Gstatus
|
||
|
||
|
||
Copyright Novatek Microelectronics Corp. 2010. All rights reserved.
|
||
*/
|
||
|
||
////////////////////////////////////////////////////////////////////////////////
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <strg_def.h>
|
||
#include <libfdt.h>
|
||
#include <compiler.h>
|
||
#include <rtosfdt.h>
|
||
#include "PrjInc.h"
|
||
#include "PrjCfg.h"
|
||
//#include "sys_storage_partition.h"
|
||
////////////////////////////////////////////////////////////////////////////////
|
||
#include "UIFrameworkExt.h"
|
||
#include "UICommon.h"
|
||
//#include "dma.h"
|
||
#include "PStore.h"
|
||
#include "sf_sd_common.h"
|
||
#if (USE_DCF == ENABLE)
|
||
#include "DCF.h"
|
||
#endif
|
||
//#include "ExifVendor.h"
|
||
#include "FileSysTsk.h"
|
||
#include "SysCommon.h"
|
||
#include "sys_mempool.h"
|
||
#include "DxType.h"
|
||
#include "Dx.h"
|
||
#include "DxApi.h"
|
||
#include "DxStorage.h"
|
||
#include <comm/shm_info.h>
|
||
#include "FwSrvApi.h"
|
||
#include <sys/stat.h>
|
||
#include <sys/mount.h>
|
||
#include "GxStrg.h"
|
||
#include "sdio.h"
|
||
#include <mntent.h>
|
||
#include <string.h>
|
||
#include "emmc.h"
|
||
#if HUNTING_CAMERA_MCU == ENABLE
|
||
#include <sf_message_queue.h>
|
||
#include <sf_param_struct.h>
|
||
#include "sf_sd_common.h"
|
||
#include "sf_mcu.h"
|
||
#endif
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
#include "LogFile.h"
|
||
#endif
|
||
#if (USERLOG_FUNC == ENABLE)
|
||
#include "userlog.h"
|
||
#endif
|
||
//#include "wdt.h"
|
||
#include "SF_SysStrgMng.h"
|
||
|
||
|
||
#if defined(_EMBMEM_SPI_NOR_)
|
||
#define MAX_BLK_PER_SEC 128
|
||
#define MAX_SEC_NUM 8
|
||
#else
|
||
#define MAX_BLK_PER_SEC 512
|
||
#define MAX_SEC_NUM 64
|
||
#endif
|
||
#define LDC_HEADER_SIZE 16
|
||
#define FW_UPD_FW_TMP_MEM_SIZE 0xA00000
|
||
|
||
#define LOADER_UPD_FW_PATH "A:\\"_BIN_NAME_".BIN"
|
||
#define FW_DEL_INDIACTION_PATH "A:\\NVTDELFW"
|
||
|
||
//#NT#2018/04/02#Niven Cho -begin
|
||
//#NT#PARTIAL_COMPRESS, we use last 10MB of APP as working buffer
|
||
#define FW_PARTIAL_COMPRESS_WORK_BUF_SIZE 0xA00000
|
||
//#NT#2018/04/02#Niven Cho -end
|
||
|
||
//global debug level: PRJ_DBG_LVL
|
||
#include "PrjCfg.h"
|
||
//local debug level: THIS_DBGLVL
|
||
#define THIS_DBGLVL 2 // 0=FATAL, 1=ERR, 2=WRN, 3=UNIT, 4=FUNC, 5=IND, 6=MSG, 7=VALUE, 8=USER
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
#define __MODULE__ SysStrgExe
|
||
#define __DBGLVL__ ((THIS_DBGLVL>=PRJ_DBG_LVL)?THIS_DBGLVL:PRJ_DBG_LVL)
|
||
#define __DBGFLT__ "*" //*=All, [mark]=CustomClass
|
||
#include <kwrap/debug.h>
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//Check definition options
|
||
#if defined(_CPU2_ECOS_)
|
||
#if (LOGFILE_FUNC == ENABLE && ECOS_DBG_MSG_FORCE_UART1_DIRECT == ENABLE)
|
||
//#error "LOGFILE_FUNC must turn off ECOS_DBG_MSG_FORCE_UART1_DIRECT"
|
||
#endif
|
||
#endif
|
||
|
||
#if 0
|
||
#define FW_UPDATE_FILE_LEN 16
|
||
static char uiUpdateFWName[FW_UPDATE_FILE_LEN] = FW_UPDATE_NAME;
|
||
static BOOL m_bUpdRename = FALSE;
|
||
#endif
|
||
|
||
#if (FS_FUNC == ENABLE)
|
||
static FST_FS_TYPE m_GxStrgType = FST_FS_TYPE_UITRON;
|
||
#endif
|
||
#if (FWS_FUNC == ENABLE)
|
||
static void *mp_fwsrv_work_buf = NULL;
|
||
#endif
|
||
static BOOL g_bSupportExfat = FALSE;
|
||
|
||
#define STRG_NUM 2
|
||
#define STRG_ID_SD 0
|
||
#define STRG_ID_EMMC 1
|
||
|
||
typedef struct {
|
||
char name[16];
|
||
UINT8 strg_id;
|
||
DCF_HANDLE dcf_hdl;
|
||
CHAR drive;
|
||
} STRG_MAPPING_TABLE;
|
||
|
||
|
||
STRG_MAPPING_TABLE g_strg_mapping_table[STRG_NUM] = {
|
||
[STRG_ID_SD] = { "SD", .strg_id = STRG_ID_SD, .dcf_hdl = -1, .drive = 'A'},
|
||
[STRG_ID_EMMC] = { "EMMC", .strg_id = STRG_ID_EMMC, .dcf_hdl = -1, .drive = 'B'},
|
||
};
|
||
|
||
static DCF_HANDLE g_dcf_hdl_act = -1;
|
||
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//
|
||
// EMBMEM
|
||
//
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//Caculate FAT Start Addr
|
||
#if defined(_CPU2_LINUX_)
|
||
static BOOL xSysStrg_LinuxRun(void);
|
||
#endif
|
||
#if defined(_CPU2_ECOS_)
|
||
static BOOL xSysStrg_eCosRun(void);
|
||
#endif
|
||
#if (defined(_DSP1_FREERTOS_) || defined(_DSP2_FREERTOS_))
|
||
static BOOL xSysStrg_DspRun(DSP_CORE_ID CoreID);
|
||
#endif
|
||
|
||
#if (FWS_FUNC == ENABLE)
|
||
UINT32 System_OnStrgInit_EMBMEM_GetGxStrgType(void)
|
||
{
|
||
return m_GxStrgType;
|
||
}
|
||
|
||
void System_OnStrgInit_EMBMEM(void)
|
||
{
|
||
#if defined(_EMBMEM_SPI_NOR_)
|
||
{
|
||
//if stoarge is SPI, use ram disk as internal FAT
|
||
DXSTRG_INIT UserEmbMemInit = {0};
|
||
UserEmbMemInit.prt.uiDxClassType = DX_CLASS_STORAGE_EXT | USER_DX_TYPE_EMBMEM_FAT;
|
||
UserEmbMemInit.buf.Addr = OS_GetMempoolAddr(POOL_ID_STORAGE_RAMDISK);
|
||
UserEmbMemInit.buf.Size = OS_GetMempoolSize(POOL_ID_STORAGE_RAMDISK);
|
||
DX_HANDLE DxNandDev = Dx_GetObject(UserEmbMemInit.prt.uiDxClassType);
|
||
Dx_Init(DxNandDev, &UserEmbMemInit, 0, STORAGE_VER);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
void System_OnStrgExit_EMBMEM(void)
|
||
{
|
||
//PHASE-1 : Close Drv or DrvExt
|
||
}
|
||
#endif
|
||
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//
|
||
// EXMEM
|
||
//
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//Drv or DrvExt
|
||
#if (FS_FUNC == ENABLE)
|
||
DXSTRG_INIT UserSdioInit;
|
||
#if(COPYCARD2CARD_FUNCTION == ENABLE)
|
||
DXSTRG_INIT UserSdio2Init;
|
||
#endif
|
||
DX_HANDLE DxCardDev1 = 0;
|
||
typedef enum _BOOT_CARD_STATE {
|
||
BOOT_CARD_STATE_UNKNOWN,
|
||
BOOT_CARD_STATE_INSERTED,
|
||
BOOT_CARD_STATE_REMOVED,
|
||
ENUM_DUMMY4WORD(BOOT_CARD_STATE)
|
||
} BOOT_CARD_STATE;
|
||
static BOOT_CARD_STATE m_BootState_Drive[16] = {BOOT_CARD_STATE_UNKNOWN}; //DriveA, DriveB
|
||
static UINT32 m_FsDxTypeMap[2] = {FS_DX_TYPE_DRIVE_A, FS_DX_TYPE_DRIVE_B};
|
||
|
||
void System_OnStrgInit_EXMEM(void)
|
||
{
|
||
static BOOL bStrg_init_EXMEM = FALSE;
|
||
if (bStrg_init_EXMEM) {
|
||
return;
|
||
}
|
||
TM_BOOT_BEGIN("sdio", "init");
|
||
|
||
#if (FS_DX_TYPE_DRIVE_A >= DX_TYPE_CARD1 && FS_DX_TYPE_DRIVE_A <= DX_TYPE_CARD3)
|
||
DX_HANDLE DxCardDev1 = Dx_GetObject(DX_CLASS_STORAGE_EXT | FS_DX_TYPE_DRIVE_A);
|
||
UserSdioInit.buf.addr = mempool_storage_sdio;
|
||
UserSdioInit.buf.size = POOL_SIZE_STORAGE_SDIO;
|
||
Dx_Init(DxCardDev1, &UserSdioInit, 0, STORAGE_VER);
|
||
#endif
|
||
#if (FS_MULTI_STRG_FUNC && FS_DX_TYPE_DRIVE_B >= DX_TYPE_CARD1 && FS_DX_TYPE_DRIVE_B <= DX_TYPE_CARD3)
|
||
DX_HANDLE DxCardDev2 = Dx_GetObject(DX_CLASS_STORAGE_EXT | FS_DX_TYPE_DRIVE_B);
|
||
UserSdio2Init.buf.Addr = OS_GetMempoolAddr(POOL_ID_STORAGE_SDIO2);
|
||
UserSdio2Init.buf.Size = OS_GetMempoolSize(POOL_ID_STORAGE_SDIO2);
|
||
Dx_Init(DxCardDev2, &UserSdio2Init, 0, STORAGE_VER);
|
||
#endif
|
||
bStrg_init_EXMEM = TRUE;
|
||
TM_BOOT_END("sdio", "init");
|
||
}
|
||
|
||
void System_OnStrgExit_EXMEM(void)
|
||
{
|
||
//PHASE-1 : Close Drv or DrvExt
|
||
|
||
}
|
||
#endif
|
||
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//
|
||
// FILESYS
|
||
//
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//Lib or LibExt
|
||
#if (FS_FUNC == ENABLE)
|
||
|
||
extern void Strg_CB(UINT32 event, UINT32 param1, UINT32 param2);
|
||
void Card_DetInsert(void);
|
||
void Card_DetBusy(void);
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
void System_DetErr(void);
|
||
#endif
|
||
#if (SDINSERT_FUNCTION == ENABLE)
|
||
SX_TIMER_ITEM(Card_DetInsert, Card_DetInsert, 2, FALSE)
|
||
#endif
|
||
SX_TIMER_ITEM(System_DetBusy, Card_DetBusy, 25, FALSE)
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
SX_TIMER_ITEM(System_DetErr, System_DetErr,50, FALSE)
|
||
#endif
|
||
int SX_TIMER_DET_STRG_ID = -1;
|
||
int SX_TIMER_DET_SYSTEM_BUSY_ID = -1;
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
int SX_TIMER_DET_SYSTEM_ERROR_ID = -1;
|
||
#endif
|
||
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
#if defined(__FREERTOS)
|
||
_ALIGNED(64) static CHAR gLogFile_Buff[LOGFILE_BUFFER_SIZE]= {0};
|
||
static UINT32 gLogFile_Buff_Size = sizeof(gLogFile_Buff);
|
||
#else //defined(__LINUX_USER__)
|
||
#include <sys/ioctl.h>
|
||
#include <sys/mman.h>
|
||
/* begin/end dma-buf functions used for userspace mmap. */
|
||
struct dma_buf_sync {
|
||
unsigned long long flags;
|
||
};
|
||
#define DMA_BUF_SYNC_READ (1 << 0)
|
||
#define DMA_BUF_SYNC_WRITE (2 << 0)
|
||
#define DMA_BUF_SYNC_RW (DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE)
|
||
#define DMA_BUF_SYNC_START (0 << 2)
|
||
#define DMA_BUF_SYNC_END (1 << 2)
|
||
#define DMA_BUF_SYNC_VALID_FLAGS_MASK \
|
||
(DMA_BUF_SYNC_RW | DMA_BUF_SYNC_END)
|
||
#define DMA_BUF_BASE 'b'
|
||
#define DMA_BUF_IOCTL_SYNC _IOW(DMA_BUF_BASE, 0, struct dma_buf_sync)
|
||
#define LOGFILE_BASE 'l'
|
||
#define LOGFILE_IOCTL_FD _IOR(LOGFILE_BASE, 0, int)
|
||
|
||
static CHAR *gLogFile_Buff = NULL;
|
||
static UINT32 gLogFile_Buff_Size = 0;
|
||
|
||
static void logfile_init_dma_buff(void)
|
||
{
|
||
int fd;
|
||
|
||
fd = open("/dev/logfile", O_RDWR | O_CLOEXEC);
|
||
if (fd < 0) {
|
||
printf("open /dev/logfile failed, %s\n", strerror(errno));
|
||
return;
|
||
}
|
||
|
||
gLogFile_Buff = mmap(NULL, LOGFILE_BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||
if (gLogFile_Buff == MAP_FAILED) {
|
||
printf("mmap dmabuf failed: %s\n", strerror(errno));
|
||
return;
|
||
}
|
||
gLogFile_Buff_Size = LOGFILE_BUFFER_SIZE;
|
||
|
||
close(fd);
|
||
}
|
||
#endif
|
||
#if defined(_CPU2_LINUX_)
|
||
_ALIGNED(64) static CHAR gLogFile_Buff2[LOGFILE_BUFFER_SIZE]= {0};
|
||
static UINT32 gLogFile_Buff2_Size = sizeof(gLogFile_Buff2);
|
||
#endif
|
||
#endif
|
||
void sf_log_confgs(void)
|
||
{
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
UIMenuStoreInfo *puiPara = sf_ui_para_get();
|
||
DBG_WRN("sf_log_confgs s\n");
|
||
if(((puiPara->DebugMode) || (puiPara->AutoLogSwitch)) && (!sf_is_usb_flag()) && (SxTimer_GetFuncActive(SX_TIMER_DET_SYSTEM_ERROR_ID) == 0))
|
||
{
|
||
{
|
||
LOGFILE_OPEN logOpenParm = {0};
|
||
LOGFILE_CFG cfg = {0};
|
||
UINT32 maxFileNum = 32;
|
||
UINT32 maxFileSize = 0x100000; // 1MB
|
||
CHAR rootDir[LOGFILE_ROOT_DIR_MAX_LEN + 1] = "A:\\LOG\\";
|
||
CHAR sysErrRootDir[LOGFILE_ROOT_DIR_MAX_LEN + 1] = "A:\\SYS\\";
|
||
if(puiPara->DebugMode){
|
||
cfg.ConType = LOGFILE_CON_MEM | LOGFILE_CON_UART;
|
||
}
|
||
else {
|
||
cfg.ConType = LOGFILE_CON_MEM;
|
||
}
|
||
logfile_init_dma_buff();
|
||
cfg.TimeType = LOGFILE_TIME_TYPE_DATETIME;
|
||
cfg.LogBuffAddr = (UINT32)gLogFile_Buff;
|
||
cfg.LogBuffSize = gLogFile_Buff_Size;
|
||
maxFileSize = gLogFile_Buff_Size;
|
||
DBG_WRN("LogFile_Config\n");
|
||
LogFile_Config(&cfg);
|
||
|
||
logOpenParm.maxFileNum = maxFileNum;
|
||
logOpenParm.maxFileSize = maxFileSize;
|
||
logOpenParm.isPreAllocAllFiles = FALSE;
|
||
logOpenParm.isSaveLastTimeSysErrLog = FALSE;
|
||
logOpenParm.lastTimeSysErrLogBuffAddr = 0;
|
||
logOpenParm.lastTimeSysErrLogBuffSize = 0;
|
||
logOpenParm.isZeroFile = TRUE;
|
||
strncpy(logOpenParm.rootDir, rootDir, LOGFILE_ROOT_DIR_MAX_LEN);
|
||
strncpy(logOpenParm.sysErrRootDir, sysErrRootDir, LOGFILE_ROOT_DIR_MAX_LEN);
|
||
|
||
DBG_WRN("LogFile_Open\n");
|
||
LogFile_Open(&logOpenParm);
|
||
|
||
//start scan
|
||
SxTimer_SetFuncActive(SX_TIMER_DET_SYSTEM_ERROR_ID, TRUE);
|
||
}
|
||
}
|
||
#endif
|
||
}
|
||
|
||
void sf_log_sava(void)
|
||
{
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
UIMenuStoreInfo *puiPara = sf_ui_para_get();
|
||
struct tm current_time2 = {0};
|
||
char tmp[64] = {'\0'};
|
||
SF_ST_MMC_DEV *mmc_dev = SF_GetMMCDev();
|
||
if((((puiPara->DebugMode) || (puiPara->AutoLogSwitch)) && (!sf_is_usb_flag())) && ((mmc_dev != NULL)))
|
||
{
|
||
DBG_DUMP("LogFile_Close ...\n");
|
||
if(mmc_dev->dcf_handle < 0)
|
||
{
|
||
DBG_ERR("dcf_handle err\n");
|
||
return;
|
||
}
|
||
current_time2 = hwclock_get_time(TIME_ID_CURRENT);
|
||
LogFile_Suspend();
|
||
if((mmc_dev->dev_type == MMC_DEV_SD) && (TRUE != sf_is_card_full()))
|
||
{
|
||
snprintf(tmp, sizeof(tmp), "A:\\LOG\\%lu%02lu%02lu%02lu%02lu%02lu_%d.log", current_time2.tm_year, current_time2.tm_mon, current_time2.tm_mday, current_time2.tm_hour, current_time2.tm_min, current_time2.tm_sec,sf_get_power_on_mode());
|
||
LogFile_DumpToFile(tmp);
|
||
}
|
||
else if((TRUE != sf_is_emmc_full()))
|
||
{
|
||
snprintf(tmp, sizeof(tmp), "B:\\LOG\\%lu%02lu%02lu%02lu%02lu%02lu_%d.log", current_time2.tm_year, current_time2.tm_mon, current_time2.tm_mday, current_time2.tm_hour, current_time2.tm_min, current_time2.tm_sec,sf_get_power_on_mode());
|
||
LogFile_DumpToFile(tmp);
|
||
}
|
||
//
|
||
LogFile_Close();
|
||
|
||
DBG_DUMP("LogFile:%s\n",tmp);
|
||
system("rm -rf /mnt/sd/LOG/*dummy*");//Clear intermediate files.
|
||
system("rm -rf /mnt/sd2/LOG/*dummy*");//Clear intermediate files.
|
||
system("sync");
|
||
}
|
||
#endif
|
||
}
|
||
|
||
void System_OnStrgInit_FS(void)
|
||
{
|
||
CHAR mount_path[KFS_LONGNAME_PATH_MAX_LENG] = {0};
|
||
|
||
TM_BOOT_BEGIN("sdio", "init_fs");
|
||
{
|
||
MEM_RANGE Pool;
|
||
Pool.addr = mempool_filesys;
|
||
#if (FS_MULTI_STRG_FUNC == ENABLE)
|
||
MEM_RANGE Pool2;
|
||
Pool.size = POOL_SIZE_FILESYS;
|
||
GxStrg_SetConfigEx(STRG_ID_SD, FILE_CFG_BUF, (UINT32)&Pool);
|
||
Pool2.addr = Pool.addr + POOL_SIZE_FILESYS;
|
||
Pool2.size = POOL_SIZE_FILESYS;
|
||
GxStrg_SetConfigEx(STRG_ID_EMMC, FILE_CFG_BUF, (UINT32)&Pool2);
|
||
#else
|
||
Pool.size = POOL_SIZE_FILESYS;
|
||
GxStrg_SetConfigEx(STRG_ID_SD, FILE_CFG_BUF, (UINT32)&Pool);
|
||
#endif
|
||
}
|
||
|
||
#if !defined(__FREERTOS)
|
||
GxStrg_SetConfigEx(STRG_ID_SD, FILE_CFG_FS_TYPE, FileSys_GetOPS_Linux()); //for FILE_CFG_FS_TYPE, DevID is don't care
|
||
|
||
#if (FS_MULTI_STRG_FUNC == ENABLE)
|
||
GxStrg_SetConfigEx(STRG_ID_EMMC, FILE_CFG_FS_TYPE, FileSys_GetOPS_Linux());
|
||
#endif
|
||
|
||
#else
|
||
GxStrg_SetConfigEx(STRG_ID_SD, FILE_CFG_FS_TYPE, FileSys_GetOPS_uITRON());
|
||
|
||
#if (FS_MULTI_STRG_FUNC == ENABLE)
|
||
GxStrg_SetConfigEx(STRG_ID_EMMC, FILE_CFG_FS_TYPE, FileSys_GetOPS_uITRON());
|
||
#endif
|
||
|
||
#endif
|
||
|
||
GxStrg_SetConfigEx(STRG_ID_SD, FILE_CFG_MAX_OPEN_FILE, 10);
|
||
|
||
#if (FS_MULTI_STRG_FUNC == ENABLE)
|
||
GxStrg_SetConfigEx(STRG_ID_EMMC, FILE_CFG_MAX_OPEN_FILE, 10);
|
||
#endif
|
||
|
||
|
||
GxStrg_SetConfigEx(STRG_ID_SD, FILE_CFG_SUPPORT_EXFAT, TRUE);
|
||
g_bSupportExfat = TRUE;
|
||
|
||
#if (FS_MULTI_STRG_FUNC == ENABLE)
|
||
GxStrg_SetConfigEx(STRG_ID_EMMC, FILE_CFG_SUPPORT_EXFAT, FALSE);
|
||
#endif
|
||
|
||
|
||
strncpy(mount_path, "/mnt/sd", sizeof(mount_path) - 1);
|
||
mount_path[sizeof(mount_path) - 1] = '\0';
|
||
GxStrg_SetConfigEx(STRG_ID_SD, FILE_CFG_MOUNT_PATH, (UINT32)mount_path);
|
||
|
||
#if !defined(__FREERTOS)
|
||
GxStrg_SetConfigEx(STRG_ID_SD, FILE_CFG_STRG_OBJECT, (UINT32)Dx_GetObject(DX_CLASS_STORAGE_EXT | FS_DX_TYPE_DRIVE_A));
|
||
#endif
|
||
|
||
|
||
#if (FS_MULTI_STRG_FUNC == ENABLE)
|
||
emmc_set_dev_node("/dev/mmcblk1p1"); /* msdc strg obj */
|
||
strncpy(mount_path, "/mnt/sd2", sizeof(mount_path) - 1);
|
||
mount_path[sizeof(mount_path) - 1] = '\0';
|
||
GxStrg_SetConfigEx(STRG_ID_EMMC, FILE_CFG_MOUNT_PATH, (UINT32)mount_path);
|
||
GxStrg_SetConfigEx(STRG_ID_EMMC, FILE_CFG_STRG_OBJECT, (UINT32)Dx_GetObject(DX_CLASS_STORAGE_EXT | FS_DX_TYPE_DRIVE_B));
|
||
#endif
|
||
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
{
|
||
#if 0
|
||
LOGFILE_CFG cfg = {0};
|
||
#if 0
|
||
// only store system error log
|
||
cfg.ConType = LOGFILE_CON_UART|LOGFILE_CON_MEM;
|
||
#else
|
||
// store normal log and system error log
|
||
#if defined(_MODEL_CARDV_HS880C_)
|
||
cfg.ConType = LOGFILE_CON_MEM|LOGFILE_CON_STORE;
|
||
#else
|
||
cfg.ConType = LOGFILE_CON_UART|LOGFILE_CON_STORE;
|
||
#endif
|
||
#endif
|
||
cfg.TimeType = LOGFILE_TIME_TYPE_DATETIME;
|
||
#if defined(__FREERTOS)
|
||
#else //defined(__LINUX_USER__)
|
||
logfile_init_dma_buff();
|
||
#endif
|
||
cfg.LogBuffAddr = (UINT32)gLogFile_Buff;
|
||
cfg.LogBuffSize = gLogFile_Buff_Size;
|
||
#if defined(_CPU2_LINUX_)
|
||
cfg.LogBuffAddr2 = (UINT32)gLogFile_Buff2;
|
||
cfg.LogBuffSize2 = gLogFile_Buff2_Size;
|
||
#endif
|
||
LogFile_Config(&cfg);
|
||
#endif
|
||
sf_log_confgs();
|
||
}
|
||
#endif
|
||
|
||
GxStrg_RegCB(Strg_CB); //Register CB function of GxStorage (NANR or CARD)
|
||
{
|
||
//1.<2E>]<5D>winit<69><74>
|
||
//FileSys:
|
||
//2.<2E>]<5D>wCB<43><42>,
|
||
//3.<2E><><EFBFBD>USxJob<6F>A<EFBFBD><41> ---------> System Job
|
||
//4.<2E><><EFBFBD>USxTimer<65>A<EFBFBD><41> ---------> Detect Job
|
||
#if (SDINSERT_FUNCTION == ENABLE)
|
||
////if (m_GxStrgType == FST_FS_TYPE_UITRON) {
|
||
SX_TIMER_DET_STRG_ID = SxTimer_AddItem(&Timer_Card_DetInsert);
|
||
////}
|
||
#endif
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
{
|
||
SX_TIMER_DET_SYSTEM_ERROR_ID = SxTimer_AddItem(&Timer_System_DetErr);
|
||
}
|
||
#endif
|
||
//SX_TIMER_DET_SYSTEM_BUSY_ID = SxTimer_AddItem(&Timer_System_DetBusy);
|
||
//5.<2E><><EFBFBD>USxCmd<6D>A<EFBFBD><41> ---------> Cmd Function
|
||
//System_AddSxCmd(Storage_OnCommand); //GxStorage
|
||
|
||
//start scan
|
||
SxTimer_SetFuncActive(SX_TIMER_DET_STRG_ID, TRUE);
|
||
SxTimer_SetFuncActive(SX_TIMER_DET_SYSTEM_BUSY_ID, TRUE);
|
||
}
|
||
TM_BOOT_END("sdio", "init_fs");
|
||
|
||
if (m_GxStrgType == FST_FS_TYPE_UITRON) {
|
||
#if (FS_MULTI_STRG_FUNC)
|
||
|
||
/************************************************
|
||
* EMMC
|
||
************************************************/
|
||
GxStrg_Det(1, Dx_GetObject(DX_CLASS_STORAGE_EXT | FS_DX_TYPE_DRIVE_B));
|
||
|
||
UINT32 uiDxState = 0;
|
||
DX_HANDLE pStrgDev = Dx_GetObject(DX_CLASS_STORAGE_EXT | FS_DX_TYPE_DRIVE_B);
|
||
if (Dx_GetState((DX_HANDLE)pStrgDev, STORAGE_STATE_INSERT, &uiDxState) != DX_OK || uiDxState == FALSE) {
|
||
Ux_PostEvent(NVTEVT_STRG_REMOVE, 1, STRG_ID_EMMC);
|
||
} else {
|
||
Ux_PostEvent(NVTEVT_STRG_INSERT, 1, STRG_ID_EMMC);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
#if (USE_DCF == ENABLE)
|
||
|
||
DCF_SetParm(DCF_PRMID_REMOVE_DUPLICATE_FOLDER, TRUE);
|
||
DCF_SetParm(DCF_PRMID_REMOVE_DUPLICATE_FILE, TRUE);
|
||
DCF_SetParm(DCF_PRMID_SET_VALID_FILE_FMT, DCF_FILE_TYPE_JPG|DCF_FILE_TYPE_MP4|DCF_FILE_TYPE_MOV);
|
||
DCF_SetParm(DCF_PRMID_SET_DEP_FILE_FMT, DCF_FILE_TYPE_JPG|DCF_FILE_TYPE_WAV|DCF_FILE_TYPE_MPO);
|
||
DCF_SetDirFreeChars(DCF_DIR_NAME);
|
||
//DCF_SetFileFreeChars(DCF_FILE_TYPE_ANYFORMAT, DCF_FILE_NAME);
|
||
|
||
#endif
|
||
}
|
||
void System_OnStrgInit_FS2(void)
|
||
{
|
||
// update card status again
|
||
if (GxStrg_GetDeviceCtrl(0, CARD_READONLY)) {
|
||
System_SetState(SYS_STATE_CARD, CARD_LOCKED);
|
||
} else if (GxStrg_GetDeviceCtrl(0, CARD_INSERT)) {
|
||
System_SetState(SYS_STATE_CARD, CARD_INSERTED);
|
||
} else {
|
||
System_SetState(SYS_STATE_CARD, CARD_REMOVED);
|
||
}
|
||
}
|
||
void System_OnStrgInit_FS3(void)
|
||
{
|
||
static BOOL bFirst = TRUE;
|
||
if (bFirst) {
|
||
TM_BOOT_BEGIN("sdio", "fdb_create");
|
||
}
|
||
#if 0
|
||
#if(MOVIE_MODE==ENABLE)
|
||
INT32 iCurrMode = System_GetBootFirstMode();
|
||
if (iCurrMode == PRIMARY_MODE_MOVIE) {
|
||
FlowMovie_FileDBCreate_Fast();
|
||
}
|
||
#endif
|
||
#endif
|
||
if (bFirst) {
|
||
TM_BOOT_END("sdio", "fdb_create");
|
||
}
|
||
bFirst = FALSE;
|
||
}
|
||
|
||
void System_OnStrgExit_FS(void)
|
||
{
|
||
//PHASE-2 : Close Lib or LibExt
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
#if HUNTING_CAMERA_MCU == ENABLE
|
||
UIMenuStoreInfo *puiPara = sf_ui_para_get();
|
||
if (puiPara->DebugMode)
|
||
{
|
||
LogFile_Close();
|
||
}
|
||
#else
|
||
LogFile_Close();
|
||
#endif
|
||
|
||
#endif
|
||
#if USE_MMC_DEV_CHECK
|
||
SF_StrgUnInit();// 反初始化sf_mmc设备Obj
|
||
#endif
|
||
// unmount file system
|
||
GxStrg_CloseDevice(0);
|
||
#if (FS_MULTI_STRG_FUNC)
|
||
GxStrg_CloseDevice(1);
|
||
#endif
|
||
|
||
}
|
||
|
||
#if (PWR_FUNC == ENABLE)
|
||
static BOOL FileSys_DetBusy(void)
|
||
{
|
||
return (BOOL)((INT32)FileSys_GetParam(FST_PARM_TASK_STS, 0) == FST_STA_BUSY);
|
||
}
|
||
#endif
|
||
|
||
void Card_DetInsert(void)
|
||
{
|
||
GxStrg_Det(0, 0);
|
||
|
||
#if 0 //FS_MULTI_STRG_FUNC
|
||
GxStrg_Det(1, Dx_GetObject(DX_CLASS_STORAGE_EXT | FS_DX_TYPE_DRIVE_B));
|
||
#endif
|
||
}
|
||
|
||
void Card_DetBusy(void)
|
||
{
|
||
#if (PWR_FUNC == ENABLE)
|
||
static BOOL bBusyLED = FALSE;
|
||
|
||
if (GxPower_GetControl(GXPWR_CTRL_SLEEP_LEVEL) <= 1 && (!GxPower_GetControl(GXPWR_CTRL_BATTERY_CHARGE_EN))) {
|
||
if (FileSys_DetBusy()) {
|
||
if (bBusyLED == FALSE) {
|
||
DBG_IND("System - busy\r\n");
|
||
bBusyLED = TRUE;
|
||
#if (OUTPUT_FUNC == ENABLE)
|
||
GxLED_SetCtrl(KEYSCAN_LED_GREEN, SETLED_SPEED, GXLED_1SEC_LED_TOGGLE_CNT / 5);
|
||
GxLED_SetCtrl(KEYSCAN_LED_GREEN, TURNON_LED, FALSE);
|
||
GxLED_SetCtrl(KEYSCAN_LED_GREEN, SET_TOGGLE_LED, TRUE);
|
||
#endif
|
||
}
|
||
} else {
|
||
if (bBusyLED == TRUE) {
|
||
DBG_IND("System - not busy\r\n");
|
||
bBusyLED = FALSE;
|
||
#if (OUTPUT_FUNC == ENABLE)
|
||
GxLED_SetCtrl(KEYSCAN_LED_GREEN, SET_TOGGLE_LED, FALSE);
|
||
GxLED_SetCtrl(KEYSCAN_LED_GREEN, TURNON_LED, FALSE);
|
||
#endif
|
||
}
|
||
}
|
||
}
|
||
#endif
|
||
}
|
||
|
||
#if (FSCK_FUNC == ENABLE)
|
||
int search_str_in_file(char *path, char *str)
|
||
{
|
||
FILE *fp = NULL;
|
||
UINT32 u32ize = 0;
|
||
int found = 0;
|
||
char *pStrSrc = NULL;
|
||
|
||
fp = fopen(path, "r");
|
||
if (fp) {
|
||
fseek(fp, 0, SEEK_END);
|
||
u32ize = ftell(fp); // take file size
|
||
fseek(fp, 0, SEEK_SET); // move to position zero
|
||
pStrSrc = (char *)malloc(u32ize * sizeof(char));
|
||
|
||
if (pStrSrc) {
|
||
fread(pStrSrc, 1, u32ize, fp);
|
||
if (strstr(pStrSrc, str)) {
|
||
found = 1;
|
||
}
|
||
free(pStrSrc);
|
||
}
|
||
|
||
fclose(fp);
|
||
fp = NULL;
|
||
pStrSrc = NULL;
|
||
u32ize = 0;
|
||
}
|
||
|
||
return found;
|
||
}
|
||
|
||
int System_check_mmcblk0p1(void)
|
||
{
|
||
SysMain_system("ls /dev/mmcblk0p1 > /tmp/lsdev.txt");
|
||
printf("\n=====================================================");
|
||
vos_util_delay_ms(100);
|
||
if (search_str_in_file("/tmp/lsdev.txt", "/dev/mmcblk0p1")) {
|
||
return 1;
|
||
} else {
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
int System_mount_storage(char *pMountPath)
|
||
{
|
||
int ret = 0;
|
||
time_t t, t_local, t_gmt;
|
||
struct tm tt_local, tt_gmt;
|
||
char opts[20];
|
||
char *pDevSrc;
|
||
char *pFileSysType = "vfat";
|
||
char *pFileSysExType = "exfat";
|
||
BOOL bexfat = FALSE;
|
||
|
||
if (System_check_mmcblk0p1()) {
|
||
pDevSrc = "/dev/mmcblk0p1";
|
||
} else {
|
||
pDevSrc = "/dev/mmcblk0";
|
||
}
|
||
|
||
time(&t);
|
||
localtime_r(&t, &tt_local);
|
||
gmtime_r(&t, &tt_gmt);
|
||
t_local = mktime(&tt_local);
|
||
t_gmt = mktime(&tt_gmt);
|
||
|
||
snprintf(opts, 19, "time_offset=%d", (t_local-t_gmt)/60);
|
||
DBG_IND("gtime=%d, ltime=%d, diff=%d, m=%d, %s\r\n", t_gmt, t_local, (t_local-t_gmt), (t_local-t_gmt)/60, opts);
|
||
|
||
{
|
||
long long DevSize = 0;
|
||
int fd = 0;
|
||
long long size = 0;
|
||
|
||
DevSize = 0;//set to zero first
|
||
|
||
fd = open(pDevSrc, O_RDONLY);
|
||
if(fd < 0) {
|
||
DBG_ERR("open %s: errno = %d, errmsg = %s\r\n", pDevSrc, errno, strerror(errno));
|
||
} else {
|
||
if(ioctl(fd, BLKGETSIZE64, &size) < 0) {
|
||
DBG_ERR("ioctl BLKGETSIZE64 failed\r\n");
|
||
}
|
||
|
||
if (0 != close(fd)) {
|
||
DBG_ERR("close %s: errno = %d, errmsg = %s\r\n", pDevSrc, errno, strerror(errno));
|
||
}
|
||
}
|
||
|
||
DBG_DUMP("%s: %s size = %lld\r\n", __func__, pDevSrc, size);
|
||
|
||
DevSize = size;
|
||
|
||
//original SD card
|
||
if(g_bSupportExfat && DevSize > 32*1024*1024*1024LL)
|
||
{
|
||
bexfat = TRUE;
|
||
}
|
||
else
|
||
{
|
||
bexfat = FALSE;
|
||
}
|
||
}
|
||
|
||
// mount sd card
|
||
if (bexfat == FALSE) {
|
||
ret = mount(pDevSrc, pMountPath, pFileSysType, MS_DIRSYNC, opts);
|
||
} else {
|
||
ret = mount(pDevSrc, pMountPath, pFileSysExType, MS_DIRSYNC, opts);
|
||
}
|
||
|
||
if(ret) {
|
||
if (errno == EBUSY) {
|
||
DBG_ERR("%s is existed, don't need to mount again\r\n", pMountPath);
|
||
} else {
|
||
DBG_ERR("mount /mnt/sd failed, errno = %d\r\n",errno);
|
||
}
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
|
||
int System_umount_storage(char *pMountPath)
|
||
{
|
||
int ret = 0;
|
||
|
||
ret = umount(pMountPath);
|
||
|
||
if (ret) {
|
||
if (errno == EBUSY) {
|
||
DBG_ERR("Catn't umount, please use 'lsof' to check the resource\r\n");
|
||
} else if (errno == EINVAL) {
|
||
DBG_ERR("%s isn't existed, don't need to umount again\r\n", pMountPath);
|
||
}
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
#endif
|
||
|
||
const char* System_Get_Strg_Name(UINT32 strg_id)
|
||
{
|
||
if(strg_id >= STRG_NUM){
|
||
DBG_ERR("invalid storage id(%d)!\n", strg_id);
|
||
return NULL;
|
||
}
|
||
|
||
return g_strg_mapping_table[strg_id].name;
|
||
}
|
||
|
||
INT32 System_Set_Storage_Act_Drive(char drive)
|
||
{
|
||
DCF_HANDLE act_handle = -1;
|
||
|
||
for(int i=0 ; i<STRG_NUM ; i++)
|
||
{
|
||
if(drive == g_strg_mapping_table[i].drive){
|
||
act_handle = g_strg_mapping_table[i].dcf_hdl;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if(act_handle == -1){
|
||
DBG_ERR("invalid drive(%c)\n", drive);
|
||
return E_SYS;
|
||
}
|
||
|
||
g_dcf_hdl_act = act_handle;
|
||
DBG_WRN("DCF_ACT_HANDLE, %d\n", act_handle);
|
||
return E_OK;
|
||
}
|
||
|
||
DCF_HANDLE System_Get_DCF_Handle(void)
|
||
{
|
||
#if SF_AGEING_EMMC_TEST == ENABLE
|
||
return 0;//emmc
|
||
#endif
|
||
#if SF_AGEING_SD_TEST == ENABLE
|
||
return 1;//sd
|
||
#endif
|
||
#if USE_MMC_DEV_CHECK
|
||
SF_ST_MMC_DEV *mmc_dev = SF_GetMMCDev();
|
||
static int erflag = 0;
|
||
if(mmc_dev == NULL)
|
||
{
|
||
if(!erflag)
|
||
{
|
||
erflag = 1;
|
||
DBG_ERR("No MMC_Dev Can use!\n");
|
||
}
|
||
return -1;
|
||
}
|
||
if(mmc_dev->dcf_handle < 0)
|
||
{
|
||
if(!erflag)
|
||
{
|
||
erflag = 1;
|
||
DBG_ERR("dcf_handle err!\n");
|
||
}
|
||
return -1;
|
||
}
|
||
erflag = 0;
|
||
//DBG_WRN("DCF_GET_HANDLE, %d\n", mmc_dev->dcf_handle);
|
||
return mmc_dev->dcf_handle;
|
||
#else
|
||
return 0;
|
||
#endif
|
||
}
|
||
|
||
CHAR System_Get_DCF_Disk_Drive(DCF_HANDLE handle)
|
||
{
|
||
CHAR drive = '\0';
|
||
|
||
for(int i=0 ; i<STRG_NUM ; i++)
|
||
{
|
||
if(handle == g_strg_mapping_table[i].dcf_hdl){
|
||
drive = g_strg_mapping_table[i].drive;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if(drive == '\0'){
|
||
DBG_ERR("invalid act handle(%d)\n", handle);
|
||
}
|
||
//DBG_WRN("get disk driver, %c\n", drive);
|
||
return drive;
|
||
}
|
||
|
||
INT32 System_OnStrgSetActDrive(VControl *pCtrl, UINT32 paramNum, UINT32 *paramArray)
|
||
{
|
||
if(paramArray[0] == 0)
|
||
System_Set_Storage_Act_Drive('A');
|
||
else
|
||
System_Set_Storage_Act_Drive('B');
|
||
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
|
||
int search_str_in_file(char *path, char *str)
|
||
{
|
||
FILE *fp = NULL;
|
||
UINT32 u32ize = 0;
|
||
int found = 0;
|
||
char *pStrSrc = NULL;
|
||
|
||
fp = fopen(path, "r");
|
||
if (fp) {
|
||
fseek(fp, 0, SEEK_END);
|
||
u32ize = ftell(fp); // take file size
|
||
fseek(fp, 0, SEEK_SET); // move to position zero
|
||
pStrSrc = (char *)malloc(u32ize * sizeof(char));
|
||
|
||
if (pStrSrc) {
|
||
fread(pStrSrc, 1, u32ize, fp);
|
||
if (strstr(pStrSrc, str)) {
|
||
found = 1;
|
||
}
|
||
free(pStrSrc);
|
||
}
|
||
|
||
fclose(fp);
|
||
fp = NULL;
|
||
pStrSrc = NULL;
|
||
u32ize = 0;
|
||
}
|
||
|
||
return found;
|
||
}
|
||
|
||
int System_check_mmcblk0p1(void)
|
||
{
|
||
SysMain_system("ls /dev/mmcblk0p1 > /tmp/lsdev.txt");
|
||
vos_util_delay_ms(100);
|
||
if (search_str_in_file("/tmp/lsdev.txt", "/dev/mmcblk0p1")) {
|
||
return 1;
|
||
} else {
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
INT32 System_OnStrgInsert(VControl *pCtrl, UINT32 paramNum, UINT32 *paramArray)
|
||
{
|
||
UINT32 strg_id = paramArray[0];
|
||
#if (FSCK_FUNC == ENABLE)
|
||
int ret_val = 0;
|
||
char *pMountPath = "/mnt/sd";
|
||
#endif
|
||
|
||
DBG_DUMP("System_OnStrgInsert: strg_id = %d\n", strg_id);
|
||
|
||
if (m_BootState_Drive[strg_id] != BOOT_CARD_STATE_UNKNOWN) {
|
||
if (strg_id == 0) {
|
||
#if(IPCAM_FUNC==DISABLE && SDHOTPLUG_FUNCTION == DISABLE)
|
||
System_PowerOff(SYS_POWEROFF_NORMAL);
|
||
#endif
|
||
}
|
||
} else {
|
||
TM_BOOT_BEGIN("sdio", "mount_fs");
|
||
m_BootState_Drive[strg_id] = BOOT_CARD_STATE_INSERTED;
|
||
}
|
||
|
||
#if (FSCK_FUNC == ENABLE)
|
||
//SysMain_system("df"); //only for debug, the "/mnt/sd" path must not be existed.
|
||
System_umount_storage(pMountPath);
|
||
/*Under normal situation, fsck checking doesn't need to print the message via UART port.
|
||
We sotre the message to /tmp/fsck.txt (on DRAM). */
|
||
if (System_check_mmcblk0p1()) {
|
||
DBG_IND("fsck /dev/mmcblk0p1\r\n");
|
||
SysMain_system("fsck.fat -a /dev/mmcblk0p1 > /tmp/fsck.txt"); //Store to /tmp/fsck.txt and use "cat /tmp/fsck.txt".
|
||
//SysMain_system("fsck.fat -a /dev/mmcblk0p1"); //The fsck checking will print the message directly.
|
||
} else {
|
||
DBG_IND("no /dev/mmcblk0p1, try to fsck /dev/mmcblk0\r\n");
|
||
SysMain_system("fsck.fat -a /dev/mmcblk0 > /tmp/fsck.txt"); //Store to /tmp/fsck.txt and use "cat /tmp/fsck.txt".
|
||
//SysMain_system("fsck.fat -a /dev/mmcblk0"); //The fsck checking will print the message directly.
|
||
}
|
||
|
||
ret_val = System_mount_storage(pMountPath);
|
||
if (ret_val) {
|
||
GxStrg_SetStrgMountStatus(strg_id, FALSE);
|
||
DBG_ERR("mount /mnt/sd failed, ret_val is %d; errno = %d\r\n", ret_val, errno);
|
||
} else {
|
||
GxStrg_SetStrgMountStatus(strg_id, TRUE);
|
||
}
|
||
//SysMain_system("df"); //only for debug, the "/mnt/sd" path must be existed.
|
||
#endif
|
||
|
||
/* wait mmcblk */
|
||
if(strg_id == STRG_ID_SD){
|
||
|
||
UINT32 count = 0 , delay = 50, timeout = 60;
|
||
|
||
while(count++ < timeout)
|
||
{
|
||
if (System_check_mmcblk0p1()){
|
||
break;
|
||
}
|
||
else{
|
||
vos_util_delay_ms(delay);
|
||
}
|
||
}
|
||
|
||
if(System_check_mmcblk0p1()){
|
||
/* hotplug */
|
||
if(count != 1)
|
||
vos_util_delay_ms(50);
|
||
}
|
||
else{
|
||
DBG_ERR("mmcblk0p1 not found!\n");
|
||
}
|
||
}
|
||
|
||
if(strg_id == STRG_ID_SD){
|
||
DX_HANDLE pStrgDev = (DX_HANDLE)sdio_getStorageObject(STRG_OBJ_FAT1);
|
||
if (GxStrg_OpenDevice(strg_id, pStrgDev) != TRUE) {
|
||
char *pDxName = "unknown";
|
||
Dx_GetInfo(pStrgDev, DX_INFO_NAME, &pDxName);
|
||
DBG_ERR("Storage mount %s fail\r\n", pDxName);
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
}
|
||
else if(strg_id == STRG_ID_EMMC)
|
||
{
|
||
DX_HANDLE pStrgDev = (DX_HANDLE)emmc_getStorageObject(STRG_OBJ_FAT1);
|
||
if (GxStrg_OpenDevice(strg_id, pStrgDev) != TRUE) {
|
||
char *pDxName = "unknown";
|
||
Dx_GetInfo(pStrgDev, DX_INFO_NAME, &pDxName);
|
||
DBG_ERR("Storage mount %s fail\r\n", pDxName);
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
}
|
||
|
||
#if (USE_DCF == ENABLE)
|
||
{
|
||
DCF_OPEN_PARM dcfParm = {0};
|
||
|
||
/*****************************************************************
|
||
* drive is pre defined in the mapping table
|
||
*****************************************************************/
|
||
dcfParm.Drive = g_strg_mapping_table[strg_id].drive;
|
||
|
||
#if (FS_MULTI_STRG_FUNC)
|
||
switch(strg_id)
|
||
{
|
||
case STRG_ID_SD:
|
||
dcfParm.WorkbuffAddr = mempool_dcf;
|
||
break;
|
||
case STRG_ID_EMMC:
|
||
dcfParm.WorkbuffAddr = mempool_dcf + POOL_SIZE_DCF_BUFFER;
|
||
break;
|
||
default:
|
||
DBG_ERR("unknown strg_id=%d\r\n", strg_id);
|
||
dcfParm.WorkbuffAddr = 0;
|
||
break;
|
||
}
|
||
#else
|
||
|
||
dcfParm.WorkbuffAddr = mempool_dcf;//dma_getCacheAddr(OS_GetMempoolAddr(POOL_ID_DCF_BUFFER));
|
||
#endif
|
||
dcfParm.WorkbuffSize = POOL_SIZE_DCF_BUFFER;
|
||
|
||
DCF_HANDLE handle = DCF_Open(&dcfParm);
|
||
|
||
DBG_WRN("DCF_Open(strg id = %lu, name = %s, handle = %lu, drive = %c)\n", strg_id, System_Get_Strg_Name(strg_id), handle, dcfParm.Drive);
|
||
/*****************************************************************
|
||
* update strg mapping table
|
||
*****************************************************************/
|
||
g_strg_mapping_table[strg_id].dcf_hdl = handle;
|
||
|
||
/*****************************************************************
|
||
* init dcf act handle with sd card
|
||
*****************************************************************/
|
||
if(strg_id == STRG_ID_SD){
|
||
DBG_WRN("sd act\n");
|
||
System_Set_Storage_Act_Drive(g_strg_mapping_table[strg_id].drive);
|
||
//DCF_SetFileFreeChars(DCF_FILE_TYPE_ANYFORMAT, SF_SD_DCF_FILE_NAME);
|
||
}
|
||
else if(strg_id == STRG_ID_EMMC){
|
||
DBG_WRN("emmc act\n");
|
||
//DCF_SetFileFreeChars(DCF_FILE_TYPE_ANYFORMAT, SF_EMMC_DCF_FILE_NAME);
|
||
System_Set_Storage_Act_Drive(g_strg_mapping_table[strg_id].drive);
|
||
}
|
||
#if USE_MMC_DEV_CHECK
|
||
SF_StrgSetDcfHandle(strg_id, g_strg_mapping_table[strg_id].dcf_hdl); //获取mmc设备dcf_handle
|
||
#endif
|
||
}
|
||
#endif
|
||
|
||
if(strg_id == STRG_ID_SD){
|
||
if (GxStrg_GetDeviceCtrl(strg_id, CARD_READONLY)) {
|
||
System_SetState(SYS_STATE_CARD, CARD_LOCKED);
|
||
DBG_WRN("Card Locked\r\n");
|
||
} else {
|
||
System_SetState(SYS_STATE_CARD, CARD_INSERTED);
|
||
DBG_WRN("Card inserted\r\n");
|
||
}
|
||
}
|
||
/************************************************
|
||
* EMMC is non-removable and only scan once
|
||
************************************************/
|
||
else if(strg_id == STRG_ID_EMMC){
|
||
DCF_HANDLE handle = g_strg_mapping_table[strg_id].dcf_hdl;
|
||
DBG_WRN("DCF_ScanObjEx(strg id = %lu, name = %s, dcf handle = %d)\n", strg_id, System_Get_Strg_Name(strg_id), handle);
|
||
DCF_ScanObjEx(handle);
|
||
}
|
||
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
|
||
|
||
INT32 System_OnStrgRemove(VControl *pCtrl, UINT32 paramNum, UINT32 *paramArray)
|
||
{
|
||
UINT32 strg_id = paramArray[0];
|
||
if (m_BootState_Drive[strg_id] != BOOT_CARD_STATE_UNKNOWN) {
|
||
if (strg_id == 0) {
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
#if HUNTING_CAMERA_MCU == ENABLE
|
||
UIMenuStoreInfo *puiPara = sf_ui_para_get();
|
||
if (puiPara->DebugMode)
|
||
{
|
||
LogFile_Suspend();
|
||
LogFile_Close();
|
||
}
|
||
#else
|
||
LogFile_Suspend();
|
||
LogFile_Close();
|
||
#endif
|
||
|
||
#endif
|
||
#if (USERLOG_FUNC == ENABLE)
|
||
{
|
||
userlog_close();
|
||
}
|
||
#endif
|
||
#if (USE_DCF == ENABLE)
|
||
//Fix the error "DCF_GetInfoByHandle() Dcf Handle 0 Data may be overwritted" when card plug out/in
|
||
|
||
DCF_HANDLE handle = g_strg_mapping_table[strg_id].dcf_hdl;
|
||
DBG_WRN("DCF_Close(strg id = %lu, name = %s, handle = %d)\n", strg_id, System_Get_Strg_Name(strg_id), handle);
|
||
DCF_Close(handle);
|
||
#endif
|
||
System_SetState(SYS_STATE_CARD, CARD_REMOVED);
|
||
|
||
GxStrg_CloseDevice(strg_id);
|
||
#if(IPCAM_FUNC==DISABLE && SDHOTPLUG_FUNCTION == DISABLE)
|
||
System_PowerOff(SYS_POWEROFF_NORMAL);
|
||
#endif
|
||
}
|
||
} else {
|
||
TM_BOOT_BEGIN("sdio", "mount_fs");
|
||
m_BootState_Drive[strg_id] = BOOT_CARD_STATE_REMOVED;
|
||
#if (FS_SWITCH_STRG_FUNC == ENABLE)
|
||
if (strg_id==0) {
|
||
DX_HANDLE pStrgDev = Dx_GetObject(DX_CLASS_STORAGE_EXT|FS_DX_TYPE_DRIVE_B);
|
||
if (GxStrg_OpenDevice(strg_id, pStrgDev)!= TRUE) {
|
||
char* pDxName="unknown";
|
||
Dx_GetInfo(pStrgDev, DX_INFO_NAME,&pDxName);
|
||
DBG_ERR("Storage mount %s fail\r\n",pDxName);
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
System_SetState(SYS_STATE_CARD, CARD_INSERTED);
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
#else
|
||
// boot without card, send attach to continue UI flow.
|
||
// because of UserWaitEvent(NVTEVT_STRG_ATTACH, ¶mNum, paramArray);
|
||
Ux_PostEvent(NVTEVT_STRG_ATTACH, 2, strg_id, 0xFF);
|
||
#endif
|
||
}
|
||
|
||
DX_HANDLE pStrgDev = Dx_GetObject(DX_CLASS_STORAGE_EXT | m_FsDxTypeMap[strg_id]);
|
||
if (GxStrg_CloseDevice(strg_id) != TRUE) {
|
||
char *pDxName = "unknown";
|
||
Dx_GetInfo(pStrgDev, DX_INFO_NAME, &pDxName);
|
||
DBG_ERR("Storage mount %s fail\r\n", pDxName);
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
|
||
INT32 System_OnStrgAttach(VControl *pCtrl, UINT32 paramNum, UINT32 *paramArray)
|
||
{
|
||
#if defined(__FREERTOS)
|
||
SHMINFO *p_shm;
|
||
unsigned char *p_fdt = (unsigned char *)fdt_get_base();
|
||
int len;
|
||
int nodeoffset;
|
||
const void *nodep; /* property node pointer */
|
||
unsigned int *p_data;
|
||
#endif
|
||
UINT32 result = paramArray[1];
|
||
#if HUNTING_CAMERA_MCU == ENABLE
|
||
SF_MESSAGE_BUF_S stMessageBuf = {0};
|
||
UINT32 strg_id = paramArray[0];
|
||
|
||
#endif
|
||
#if defined(__FREERTOS)
|
||
if (p_fdt== NULL) {
|
||
DBG_ERR("p_fdt is NULL.\n");
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
|
||
// read SHMEM_PATH
|
||
nodeoffset = fdt_path_offset(p_fdt, SHMEM_PATH);
|
||
if (nodeoffset < 0) {
|
||
DBG_ERR("failed to offset for %s = %d \n", SHMEM_PATH, nodeoffset);
|
||
} else {
|
||
DBG_DUMP("offset for %s = %d \n", SHMEM_PATH, nodeoffset);
|
||
}
|
||
nodep = fdt_getprop(p_fdt, nodeoffset, "reg", &len);
|
||
if (len == 0 || nodep == NULL) {
|
||
DBG_ERR("failed to access reg.\n");
|
||
return NVTEVT_CONSUME;
|
||
} else {
|
||
p_data = (unsigned int *)nodep;
|
||
p_shm = (SHMINFO *)be32_to_cpu(p_data[0]);
|
||
DBG_DUMP("p_shm = 0x%08X\n", (int)p_shm);
|
||
}
|
||
//////////////////////////////////////////////////
|
||
#endif
|
||
|
||
//DBG_IND("System_OnStrgAttach: strg_id = %d\n", strg_id);
|
||
if (m_GxStrgType == FST_FS_TYPE_LINUX) {
|
||
//Do Nothing
|
||
} else { //m_GxStrgType == FST_FS_TYPE_UITRON
|
||
//if spi use RamDisk as inner Memory,need to format RamDisk
|
||
#if defined(_EMBMEM_SPI_NOR_)
|
||
FS_HANDLE pStrgDevCur = (FS_HANDLE)GxStrg_GetDevice(0);
|
||
FS_HANDLE pStrgDevRAM = (FS_HANDLE)Dx_GetObject(DX_CLASS_STORAGE_EXT | USER_DX_TYPE_EMBMEM_FAT);
|
||
|
||
if ((pStrgDevCur == pStrgDevRAM) && (result != FST_STA_OK)) {
|
||
result = FileSys_FormatDisk(pStrgDevCur, TRUE);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
DBG_WRN("strg_id = %lu result = %d\n", paramArray[0], result);
|
||
|
||
switch (result) {
|
||
case FST_STA_OK:
|
||
|
||
if(strg_id == 0){
|
||
printf("read only = %llu\n", FileSys_GetDiskInfoEx('A', FST_INFO_IS_READ_ONLY));
|
||
if(FileSys_GetDiskInfoEx('A', FST_INFO_IS_READ_ONLY)){
|
||
system("mount -t vfat /dev/mmcblk0 /mnt/sd/ -o remount,rw");
|
||
}
|
||
}
|
||
|
||
#if (USE_DCF == ENABLE)
|
||
|
||
DCF_HANDLE handle = g_strg_mapping_table[strg_id].dcf_hdl;
|
||
DBG_WRN("DCF_ScanObjEx(strg id = %lu, name = %s, dcf handle = %d)\n", strg_id, System_Get_Strg_Name(strg_id), handle);
|
||
DCF_ScanObjEx(handle);
|
||
|
||
#endif
|
||
//FileSys_GetDiskInfo(FST_INFO_DISK_SIZE);
|
||
System_SetState(SYS_STATE_FS, FS_INIT_OK);
|
||
|
||
#if HUNTING_CAMERA_MCU == ENABLE
|
||
INT32 uiStatus = 0;
|
||
UINT8 ucAttrib = 0;
|
||
char tmp[128] = {'\0'};
|
||
|
||
snprintf(tmp, sizeof(tmp), "%c%s", System_Get_DCF_Disk_Drive(handle), PHOTO_THUMB_PATH); /* DCF 8.3 naming rule */
|
||
|
||
uiStatus = FileSys_GetAttrib(tmp, &ucAttrib);
|
||
if (uiStatus == FST_STA_OK) {
|
||
if(!(ucAttrib&FST_ATTRIB_HIDDEN)){
|
||
#if SF_IQ_TEST != ENABLE
|
||
FileSys_SetAttrib(tmp, FST_ATTRIB_HIDDEN/* | FST_ATTRIB_SYSTEM*/, TRUE);
|
||
#endif
|
||
}
|
||
}
|
||
else {
|
||
FileSys_MakeDir(tmp);
|
||
#if SF_IQ_TEST != ENABLE
|
||
FileSys_SetAttrib(tmp, FST_ATTRIB_HIDDEN/* | FST_ATTRIB_SYSTEM*/, TRUE);
|
||
#endif
|
||
}
|
||
#if HUNTING_CAMERA_MCU == ENABLE
|
||
|
||
if((CMD_FORMAT_SD_STA != sf_get_card_statu())){
|
||
stMessageBuf.arg1 = STRG_CB_MOUNT_FINISH;
|
||
stMessageBuf.arg2 = strg_id;//result;
|
||
stMessageBuf.arg3 = FST_STA_OK;
|
||
stMessageBuf.cmdId = CMD_SD;
|
||
sf_com_message_send_to_app(&stMessageBuf);
|
||
#if USE_MMC_DEV_CHECK
|
||
SF_StrgRegister(&stMessageBuf);
|
||
#endif
|
||
printf("System_OnStrgAttach send MOUNT! dev_id = %d\n", strg_id);
|
||
Ux_PostEvent(NVTEVT_STRG_MOUNT_OK, 0);
|
||
}
|
||
#endif
|
||
#endif
|
||
#if defined(__FREERTOS)
|
||
if (p_shm && p_shm->boot.LdCtrl2 & LDCF_UPDATE_FW) {
|
||
FST_FILE hFile = FileSys_OpenFile(FW_DEL_INDIACTION_PATH, FST_OPEN_READ | FST_OPEN_EXISTING);
|
||
if (hFile != NULL) {
|
||
DBG_DUMP("Detected %s, delete %s \r\n", FW_DEL_INDIACTION_PATH, LOADER_UPD_FW_PATH);
|
||
FileSys_CloseFile(hFile);
|
||
// Delete FW bin from A:
|
||
if (FileSys_DeleteFile(LOADER_UPD_FW_PATH) != FST_STA_OK) {
|
||
DBG_ERR("delete "_BIN_NAME_".BIN failed .\r\n");
|
||
}
|
||
if (FileSys_DeleteFile(FW_DEL_INDIACTION_PATH) != FST_STA_OK) {
|
||
DBG_ERR("delete %s failed .\r\n", FW_DEL_INDIACTION_PATH);
|
||
}
|
||
}
|
||
}
|
||
#endif
|
||
|
||
#if 0//(LOGFILE_FUNC==ENABLE)
|
||
#if HUNTING_CAMERA_MCU == ENABLE
|
||
UIMenuStoreInfo *puiPara = sf_ui_para_get();
|
||
|
||
if ((puiPara->DebugMode) && SxTimer_GetFuncActive(SX_TIMER_DET_SYSTEM_ERROR_ID) == 0)
|
||
#else
|
||
if (SxTimer_GetFuncActive(SX_TIMER_DET_SYSTEM_ERROR_ID) == 0)
|
||
#endif
|
||
{
|
||
LOGFILE_OPEN logOpenParm = {0};
|
||
UINT32 maxFileNum = 32;
|
||
UINT32 maxFileSize = 0x100000; // 1MB
|
||
CHAR rootDir[LOGFILE_ROOT_DIR_MAX_LEN + 1] = "A:\\LOG\\";
|
||
#if defined(_CPU2_LINUX_)
|
||
CHAR rootDir2[LOGFILE_ROOT_DIR_MAX_LEN + 1] = "A:\\Novatek\\LOG2\\";
|
||
#endif
|
||
CHAR sysErrRootDir[LOGFILE_ROOT_DIR_MAX_LEN + 1] = "A:\\SYS\\";
|
||
|
||
logOpenParm.maxFileNum = maxFileNum;
|
||
logOpenParm.maxFileSize = maxFileSize;
|
||
logOpenParm.isPreAllocAllFiles = TRUE;
|
||
#if defined(__FREERTOS)
|
||
logOpenParm.isSaveLastTimeSysErrLog = wdt_getResetNum()>0 ? TRUE : FALSE;
|
||
#else //defined(__LINUX_USER__)
|
||
logOpenParm.isSaveLastTimeSysErrLog = FALSE;
|
||
#endif
|
||
logOpenParm.lastTimeSysErrLogBuffAddr = mempool_logfile;
|
||
logOpenParm.lastTimeSysErrLogBuffSize = POOL_SIZE_LOGFILE;
|
||
strncpy(logOpenParm.rootDir, rootDir, LOGFILE_ROOT_DIR_MAX_LEN);
|
||
#if defined(_CPU2_LINUX_)
|
||
strncpy(logOpenParm.rootDir2, rootDir2, LOGFILE_ROOT_DIR_MAX_LEN);
|
||
#endif
|
||
strncpy(logOpenParm.sysErrRootDir, sysErrRootDir, LOGFILE_ROOT_DIR_MAX_LEN);
|
||
logOpenParm.isZeroFile = TRUE;
|
||
LogFile_Open(&logOpenParm);
|
||
|
||
//start scan
|
||
SxTimer_SetFuncActive(SX_TIMER_DET_SYSTEM_ERROR_ID, TRUE);
|
||
|
||
}
|
||
#endif
|
||
#if (USERLOG_FUNC == ENABLE)
|
||
{
|
||
userlog_open();
|
||
}
|
||
#endif
|
||
break;
|
||
case FST_STA_DISK_UNFORMAT:
|
||
if(strg_id == 0)
|
||
System_SetState(SYS_STATE_FS, FS_UNFORMATTED);
|
||
break;
|
||
case FST_STA_DISK_UNKNOWN_FORMAT:
|
||
if(strg_id == 0)
|
||
System_SetState(SYS_STATE_FS, FS_UNKNOWN_FORMAT);
|
||
break;
|
||
case FST_STA_CARD_ERR:
|
||
if(strg_id == 0)
|
||
System_SetState(SYS_STATE_FS, FS_DISK_ERROR);
|
||
break;
|
||
default:
|
||
if(strg_id == 0)
|
||
System_SetState(SYS_STATE_FS, FS_DISK_ERROR);
|
||
break;
|
||
}
|
||
|
||
#if HUNTING_CAMERA_MCU == ENABLE
|
||
if((FS_DISK_ERROR == System_GetState(SYS_STATE_FS))){
|
||
stMessageBuf.arg1 = CMD_SD_STRG_CB_UNMOUNT_FINISH;
|
||
stMessageBuf.arg2 = strg_id;
|
||
stMessageBuf.cmdId = CMD_SD;
|
||
sf_com_message_send_to_app(&stMessageBuf);
|
||
#if USE_MMC_DEV_CHECK
|
||
SF_StrgRegister(&stMessageBuf);
|
||
#endif
|
||
printf("System_OnStrgAttach send UNMOUNT! dev_id = %d\n", strg_id);
|
||
}
|
||
#endif
|
||
#if (POWERON_FAST_BOOT == ENABLE)
|
||
INIT_SETFLAG(FLGINIT_STRGATH);
|
||
#endif
|
||
Ux_PostEvent(NVTEVT_STORAGE_INIT, 0, 0);
|
||
#if (PWR_FUNC == ENABLE)
|
||
GxPower_SetControl(GXPWR_CTRL_AUTOSLEEP_EN, 0xff); //reset
|
||
#endif
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
|
||
INT32 System_OnStrgDetach(VControl *pCtrl, UINT32 paramNum, UINT32 *paramArray)
|
||
{
|
||
if (m_GxStrgType == FST_FS_TYPE_LINUX) {
|
||
UINT32 strg_id = paramArray[0];
|
||
|
||
if (strg_id != 0) { //not sd-1
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
}
|
||
|
||
switch (paramArray[1]) {
|
||
case FST_STA_OK:
|
||
DBG_IND("FS: unmount OK\r\n");
|
||
break;
|
||
|
||
default:
|
||
DBG_ERR("^RFS: unmount FAIL\r\n");
|
||
break;
|
||
}
|
||
return NVTEVT_CONSUME;
|
||
}
|
||
|
||
BOOL gChkCardPwrOn = FALSE;
|
||
BOOL gChkCardChange = FALSE;
|
||
|
||
void Storage_PowerOn_Start(void)
|
||
{
|
||
gChkCardPwrOn = GxStrg_GetDeviceCtrl(0, CARD_INSERT);
|
||
DBG_IND("^BStg Power On = %d\r\n", gChkCardPwrOn);
|
||
}
|
||
void Storage_UpdateSource(void)
|
||
{
|
||
DBG_IND("^Y-------------CARD det\r\n");
|
||
if (gChkCardPwrOn) {
|
||
if (FALSE == GxStrg_GetDeviceCtrl(0, CARD_INSERT)) { //CARD<52>w<EFBFBD>ް<EFBFBD>
|
||
gChkCardChange = TRUE;
|
||
}
|
||
} else {
|
||
if (TRUE == GxStrg_GetDeviceCtrl(0, CARD_INSERT)) { //CARD<52>w<EFBFBD><77><EFBFBD>J
|
||
gChkCardChange = TRUE;
|
||
}
|
||
}
|
||
}
|
||
void Storage_PowerOn_End(void)
|
||
{
|
||
Storage_UpdateSource();
|
||
gChkCardPwrOn = GxStrg_GetDeviceCtrl(0, CARD_INSERT);
|
||
|
||
if (TRUE == gChkCardChange) { //CARD<52><44><EFBFBD>g<EFBFBD><67><EFBFBD><EFBFBD>
|
||
System_PowerOff(SYS_POWEROFF_NORMAL); //<2F><><EFBFBD><EFBFBD>
|
||
return;
|
||
}
|
||
}
|
||
#endif
|
||
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//
|
||
// PSTORE
|
||
//
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
#if (PST_FUNC == ENABLE)
|
||
#define PST_IND_FILE "/mnt/pstore/.psinit"
|
||
|
||
void System_PS_Format(void)
|
||
{
|
||
PSFMT gFmtStruct = {MAX_BLK_PER_SEC, MAX_SEC_NUM};
|
||
PStore_Format(&gFmtStruct);
|
||
}
|
||
void System_OnStrgInit_PS(void)
|
||
{
|
||
struct stat st;
|
||
char ind_file_name[64];
|
||
|
||
//PHASE-2 : Init & Open Lib or LibExt
|
||
TM_BOOT_BEGIN("nand", "init_ps");
|
||
#if (PST_FUNC == ENABLE)
|
||
// Open PStore
|
||
PSFMT gFmtStruct = {MAX_BLK_PER_SEC, MAX_SEC_NUM};
|
||
PSTORE_INIT_PARAM gPStoreParam;
|
||
UINT32 result = 0;
|
||
#if defined(__FREERTOS)
|
||
UINT8 *pBuf;
|
||
#endif
|
||
#if defined(_CPU2_LINUX_) && defined(_EMBMEM_EMMC_)
|
||
PStore_Init(PS_TYPE_FILESYS, PST_FS_DRIVE[0]);
|
||
UINT32 paramNum;
|
||
UINT32 paramArray[MAX_MESSAGE_PARAM_NUM];
|
||
do {
|
||
UserWaitEvent(NVTEVT_STRG_ATTACH, ¶mNum, paramArray);
|
||
} while(paramArray[0] != PST_DEV_ID); //PStore will mount first before dev[0],dev[1]
|
||
#else
|
||
PStore_Init(PS_TYPE_EMBEDED, 0);
|
||
#endif
|
||
#if defined(__FREERTOS)
|
||
pBuf = (UINT8 *)mempool_pstore;
|
||
if(!pBuf){
|
||
DBG_ERR("fail to allocate pstore buffer of %d bytes\n", POOL_SIZE_PS_BUFFER);
|
||
return;
|
||
}
|
||
|
||
gPStoreParam.pBuf = pBuf;
|
||
gPStoreParam.uiBufSize = POOL_SIZE_PS_BUFFER;
|
||
DBG_DUMP("PStore uiBufSize=%d\r\n", gPStoreParam.uiBufSize);
|
||
#else
|
||
gPStoreParam.pBuf = NULL;
|
||
gPStoreParam.uiBufSize = 0;
|
||
#endif
|
||
result = PStore_Open(NULL, &gPStoreParam);
|
||
|
||
if ((result != E_PS_OK) || (stat(PST_IND_FILE, &st) != 0)) {
|
||
DBG_ERR("PStore Open fail %d format \r\n", result);
|
||
// close pstore to umount pstore partition
|
||
PStore_Close();
|
||
// after format, pstore partition will be re-mounted, so don't call open again
|
||
PStore_Format(&gFmtStruct);
|
||
// create indicated file
|
||
strncpy(ind_file_name, "touch ", 10);
|
||
strncat(ind_file_name, PST_IND_FILE, 50);
|
||
system(ind_file_name);
|
||
}
|
||
|
||
#if defined(_CPU2_LINUX_)
|
||
{
|
||
PSTOREIPC_OPEN PsopenObj = {0};
|
||
// open pstore ipc
|
||
PstoreIpc_Open(&PsopenObj);
|
||
}
|
||
#endif
|
||
#endif
|
||
#if (POWERON_FAST_BOOT == ENABLE)
|
||
INIT_SETFLAG(FLGINIT_MOUNTPS);
|
||
#endif
|
||
TM_BOOT_END("nand", "init_ps");
|
||
}
|
||
void System_OnStrgExit_PS(void)
|
||
{
|
||
#if (PST_FUNC == ENABLE)
|
||
#if defined(_CPU2_LINUX_)
|
||
PstoreIpc_Close();
|
||
#endif
|
||
PStore_Close();
|
||
#endif
|
||
}
|
||
#endif
|
||
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
//
|
||
// FWSTORE
|
||
//
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
#if (FWS_FUNC == ENABLE)
|
||
#include "FileSysTsk.h"
|
||
#if (FWS_FUNC == ENABLE)
|
||
#include "FwSrvApi.h"
|
||
#endif
|
||
#include "MemCheck.h"
|
||
|
||
typedef enum {
|
||
CODE_SECTION_01 = 0,
|
||
CODE_SECTION_02,
|
||
CODE_SECTION_03,
|
||
CODE_SECTION_04,
|
||
CODE_SECTION_05,
|
||
CODE_SECTION_06,
|
||
CODE_SECTION_07,
|
||
CODE_SECTION_08,
|
||
CODE_SECTION_09,
|
||
CODE_SECTION_10,
|
||
CODE_SECTION_11,
|
||
CODE_SECTION_12,
|
||
CODE_SECTION_13,
|
||
CODE_SECTION_14,
|
||
CODE_SECTION_15,
|
||
CODE_SECTION_16,
|
||
ENUM_DUMMY4WORD(_CODE_SECTION_)
|
||
}
|
||
CODE_SECTION;
|
||
|
||
UINT32 UserSection_Load[10] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||
UINT32 UserSection_Order_full[] = {
|
||
CODE_SECTION_02, CODE_SECTION_03, CODE_SECTION_04, CODE_SECTION_05, CODE_SECTION_06,
|
||
CODE_SECTION_07, CODE_SECTION_08, CODE_SECTION_09, CODE_SECTION_10, FWSRV_PL_BURST_END_TAG
|
||
};
|
||
|
||
int order = 1;
|
||
void UserSection_LoadCb(const UINT32 Idx)
|
||
{
|
||
DBG_DUMP("Section-%.2ld: (LOAD)\r\n", Idx + 1);
|
||
|
||
UserSection_Load[Idx] = 1; //mark loaded
|
||
order++;
|
||
|
||
if (Idx == 9) { //Section-10
|
||
if (mp_fwsrv_work_buf) {
|
||
free(mp_fwsrv_work_buf);
|
||
mp_fwsrv_work_buf = NULL;
|
||
}
|
||
}
|
||
#if (POWERON_FAST_BOOT == ENABLE)
|
||
if (Idx == 0) { //Section-01
|
||
INIT_SETFLAG(FLGINIT_LOADCODE1);
|
||
}
|
||
if (Idx == 1) { //Section-02
|
||
INIT_SETFLAG(FLGINIT_LOADCODE2);
|
||
}
|
||
if (Idx == 2) { //Section-03
|
||
INIT_SETFLAG(FLGINIT_LOADCODE3);
|
||
}
|
||
if (Idx == 9) { //Section-10
|
||
}
|
||
#endif
|
||
}
|
||
|
||
void System_OnStrgInit_FWS(void)
|
||
{
|
||
SHMINFO *p_shm;
|
||
FWSRV_INIT Init = {0};
|
||
unsigned char *p_fdt = (unsigned char *)fdt_get_base();
|
||
|
||
|
||
if (p_fdt == NULL) {
|
||
DBG_ERR("p_fdt is NULL.\n");
|
||
return;
|
||
}
|
||
|
||
int len;
|
||
int nodeoffset;
|
||
const void *nodep; /* property node pointer */
|
||
|
||
// read SHMEM_PATH
|
||
nodeoffset = fdt_path_offset(p_fdt, SHMEM_PATH);
|
||
if (nodeoffset < 0) {
|
||
DBG_ERR("failed to offset for %s = %d \n", SHMEM_PATH, nodeoffset);
|
||
} else {
|
||
DBG_DUMP("offset for %s = %d \n", SHMEM_PATH, nodeoffset);
|
||
}
|
||
nodep = fdt_getprop(p_fdt, nodeoffset, "reg", &len);
|
||
if (len == 0 || nodep == NULL) {
|
||
DBG_ERR("failed to access reg.\n");
|
||
return;
|
||
} else {
|
||
unsigned int *p_data = (unsigned int *)nodep;
|
||
p_shm = (SHMINFO *)be32_to_cpu(p_data[0]);
|
||
DBG_DUMP("p_shm = 0x%08X\n", (int)p_shm);
|
||
if (p_shm->boot.LdCtrl2 & LDCF_BOOT_CARD) {
|
||
DBG_DUMP(DBG_COLOR_HI_YELLOW"\r\nNotice: Boot from T.bin. app.dtb will load from flash!!!\r\n\r\n"DBG_COLOR_END);
|
||
}
|
||
}
|
||
|
||
// init fwsrv
|
||
Init.uiApiVer = FWSRV_API_VERSION;
|
||
Init.StrgMap.pStrgFdt = EMB_GETSTRGOBJ(STRG_OBJ_FW_FDT);
|
||
Init.StrgMap.pStrgApp = EMB_GETSTRGOBJ(STRG_OBJ_FW_APP);
|
||
Init.StrgMap.pStrgUboot = EMB_GETSTRGOBJ(STRG_OBJ_FW_UBOOT);
|
||
Init.StrgMap.pStrgRtos = EMB_GETSTRGOBJ(STRG_OBJ_FW_RTOS);
|
||
Init.PlInit.uiApiVer = PARTLOAD_API_VERSION;
|
||
Init.PlInit.pStrg = EMB_GETSTRGOBJ(STRG_OBJ_FW_RTOS);
|
||
#if defined(_FW_TYPE_PARTIAL_COMPRESS_)
|
||
mp_fwsrv_work_buf = (void *)malloc(FW_PARTIAL_COMPRESS_WORK_BUF_SIZE);
|
||
Init.PlInit.DataType = PARTLOAD_DATA_TYPE_COMPRESS_GZ;
|
||
Init.PlInit.uiWorkingAddr = (UINT32)mp_fwsrv_work_buf;
|
||
Init.PlInit.uiWorkingSize = FW_PARTIAL_COMPRESS_WORK_BUF_SIZE ;
|
||
|
||
#elif defined(_FW_TYPE_PARTIAL_)
|
||
mp_fwsrv_work_buf = (void *)malloc(_EMBMEM_BLK_SIZE_);
|
||
Init.PlInit.DataType = PARTLOAD_DATA_TYPE_UNCOMPRESS;
|
||
Init.PlInit.uiWorkingAddr = (UINT32)mp_fwsrv_work_buf;
|
||
Init.PlInit.uiWorkingSize = _EMBMEM_BLK_SIZE_ ;
|
||
#endif
|
||
Init.PlInit.uiAddrBegin = _BOARD_RTOS_ADDR_ + p_shm->boot.LdLoadSize;
|
||
FwSrv_Init(&Init);
|
||
FwSrv_Open();
|
||
}
|
||
|
||
void System_OnStrgExit_FWS(void)
|
||
{
|
||
#if (FWS_FUNC == ENABLE)
|
||
ER er;
|
||
er = FwSrv_Close();
|
||
if (er != FWSRV_ER_OK) {
|
||
DBG_ERR("Close failed!\r\n");
|
||
}
|
||
#endif
|
||
}
|
||
|
||
void System_CPU2_Start(void)
|
||
{
|
||
}
|
||
|
||
void System_CPU2_Stop(void)
|
||
{
|
||
}
|
||
|
||
void System_CPU2_WaitReady(void)
|
||
{
|
||
}
|
||
|
||
void System_DSP_Start(void)
|
||
{
|
||
}
|
||
|
||
void System_DSP_WaitReady(void)
|
||
{
|
||
}
|
||
|
||
void System_OnStrg_DownloadFW(void)
|
||
{
|
||
#if defined(_FW_TYPE_PARTIAL_) || defined(_FW_TYPE_PARTIAL_COMPRESS_)
|
||
SHMINFO *p_shm;
|
||
unsigned char *p_fdt = (unsigned char *)fdt_get_base();
|
||
|
||
if (p_fdt == NULL) {
|
||
DBG_ERR("p_fdt is NULL.\n");
|
||
return;
|
||
}
|
||
|
||
int len;
|
||
int nodeoffset;
|
||
const void *nodep; /* property node pointer */
|
||
|
||
// read SHMEM_PATH
|
||
nodeoffset = fdt_path_offset(p_fdt, SHMEM_PATH);
|
||
if (nodeoffset < 0) {
|
||
DBG_ERR("failed to offset for %s = %d \n", SHMEM_PATH, nodeoffset);
|
||
} else {
|
||
DBG_DUMP("offset for %s = %d \n", SHMEM_PATH, nodeoffset);
|
||
}
|
||
nodep = fdt_getprop(p_fdt, nodeoffset, "reg", &len);
|
||
if (len == 0 || nodep == NULL) {
|
||
DBG_ERR("failed to access reg.\n");
|
||
return;
|
||
} else {
|
||
unsigned int *p_data = (unsigned int *)nodep;
|
||
p_shm = (SHMINFO *)be32_to_cpu(p_data[0]);
|
||
DBG_DUMP("p_shm = 0x%08X\n", (int)p_shm);
|
||
}
|
||
|
||
if ((p_shm->boot.LdCtrl2 & LDCF_BOOT_CARD) == 0) {
|
||
FWSRV_CMD Cmd = {0};
|
||
FWSRV_PL_LOAD_BURST_IN pl_in = {0};
|
||
|
||
// start partial load
|
||
void (*LoadCallback)(const UINT32 Idx) = UserSection_LoadCb;
|
||
UINT32 *SecOrderTable = UserSection_Order_full;
|
||
|
||
LoadCallback(CODE_SECTION_01); // 1st part has loaded by loader
|
||
|
||
ER er;
|
||
pl_in.puiIdxSequence = SecOrderTable;
|
||
pl_in.fpLoadedCb = LoadCallback;
|
||
Cmd.Idx = FWSRV_CMD_IDX_PL_LOAD_BURST; //continue load
|
||
Cmd.In.pData = &pl_in;
|
||
Cmd.In.uiNumByte = sizeof(pl_in);
|
||
Cmd.Prop.bExitCmdFinish = TRUE;
|
||
|
||
er = FwSrv_Cmd(&Cmd);
|
||
if (er != FWSRV_ER_OK) {
|
||
DBG_ERR("Process failed!\r\n");
|
||
return;
|
||
}
|
||
}
|
||
#endif
|
||
return;
|
||
}
|
||
#endif
|
||
|
||
#if (IPCAM_FUNC != ENABLE)
|
||
|
||
#include "SysFW_Upgrade.h"
|
||
|
||
UINT32 System_OnStrg_UploadFW(UINT32 DevID)
|
||
{
|
||
INT32 fst_er;
|
||
// ER fws_er;
|
||
unsigned char *p_Mem = NULL;
|
||
FST_FILE hFile = NULL;
|
||
UINT32 uiFwSize = 0;
|
||
DBG_FUNC_BEGIN("\r\n");
|
||
|
||
//m_bUpdRename = FALSE;
|
||
UINT32 dcf_handle = (UINT32)System_Get_DCF_Handle(); /* 0:emmc 1:sd */
|
||
char font = System_Get_DCF_Disk_Drive(dcf_handle) == 'B' ? 'B' : 'A';
|
||
char fw_file[64] = {'\0'};
|
||
sprintf((char *)fw_file, "%c%s", font, FW_UPDATE_NAME);
|
||
|
||
uiFwSize = FileSys_GetFileLen(fw_file);
|
||
uiFwSize += _EMBMEM_BLK_SIZE_; /* IMPOARTANT!! */
|
||
|
||
hFile = FileSys_OpenFile(fw_file, FST_OPEN_READ);
|
||
|
||
if (hFile == 0) {
|
||
DBG_ERR("cannot find %s\r\n", fw_file);
|
||
return UPDNAND_STS_FW_INVALID_STG;
|
||
}
|
||
|
||
|
||
|
||
p_Mem = (unsigned char *)SxCmd_GetTempMem(uiFwSize);
|
||
if(NULL == p_Mem){
|
||
DBG_ERR("Alloc Temp Mem is NULL(uiFwSize=%d)\r\n",uiFwSize);
|
||
return UPDNAND_STS_FW_READ2_ERR;
|
||
}
|
||
|
||
fst_er = FileSys_ReadFile(hFile, (UINT8 *)p_Mem, &uiFwSize, 0, NULL);
|
||
DBG_IND("Update Filename=%s, File Size=%d\r\n",fw_file,uiFwSize);
|
||
FileSys_CloseFile(hFile);
|
||
if (fst_er != FST_STA_OK) {
|
||
DBG_ERR("FW bin read fail\r\n");
|
||
return UPDNAND_STS_FW_READ_ERR;
|
||
}
|
||
|
||
DBG_DUMP("p_Mem = %lx size = %lx\n", (UINT32)p_Mem, (UINT32)uiFwSize);
|
||
|
||
SysFW_Upgrade_Init();
|
||
SysFW_Upgrade((UINT32)p_Mem, (UINT32)uiFwSize);
|
||
|
||
// FWSRV_BIN_UPDATE_ALL_IN_ONE Desc = {0};
|
||
// Desc.uiSrcBufAddr = (UINT32)p_Mem;
|
||
// Desc.uiSrcBufSize = (UINT32)uiFwSize;
|
||
// Desc.fpCheckSumCb = CheckSumOKCb; //we rename bin after check sum OK
|
||
//
|
||
// FWSRV_CMD Cmd = {0};
|
||
// Cmd.Idx = FWSRV_CMD_IDX_BIN_UPDATE_ALL_IN_ONE; //continue load
|
||
// Cmd.In.pData = &Desc;
|
||
// Cmd.In.uiNumByte = sizeof(Desc);
|
||
// Cmd.Prop.bExitCmdFinish = TRUE;
|
||
//
|
||
// fws_er = FwSrv_Cmd(&Cmd);
|
||
|
||
|
||
SxCmd_RelTempMem((UINT32)p_Mem);
|
||
|
||
/*
|
||
if(fws_er == FWSRV_ER_INVALID_UPDATED_DATA || fws_er == FWSRV_ER_WRITE_BLOCK)
|
||
{
|
||
DBG_ERR("update failed, start to use loader update mechanism.\r\n");
|
||
//GxSystem_EnableHWReset(0);
|
||
//GxSystem_PowerOff();
|
||
return UPDNAND_STS_FW_WRITE_CHK_ERR;
|
||
}
|
||
else if(fws_er != FWSRV_ER_OK)
|
||
{
|
||
DBG_ERR("FW bin check failed %d\r\n",fws_er);
|
||
if(m_bUpdRename)
|
||
{
|
||
if(FileSys_RenameFile(&uiUpdateFWName[3],LOADER_UPD_FW_PATH, TRUE)==FST_STA_OK) //[3]: remove "A:\\"
|
||
{
|
||
FileSys_DeleteFile(FW_DEL_INDIACTION_PATH);
|
||
}
|
||
}
|
||
return UPDNAND_STS_FW_READ_CHK_ERR;
|
||
}
|
||
*/
|
||
DBG_FUNC_END("\r\n");
|
||
return UPDNAND_STS_FW_OK;
|
||
}
|
||
#endif
|
||
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
void System_DetErr(void)
|
||
{
|
||
#if 0 //LOGFILE_FUNC TODO
|
||
extern void LogFile_DumpMemAndSwReset(void);
|
||
|
||
#if (LOGFILE_FUNC==ENABLE)
|
||
if (LogFile_ChkSysErr() != E_OK) {
|
||
LogFile_DumpMemAndSwReset();
|
||
}
|
||
#endif
|
||
#endif //LOGFILE_FUNC TODO
|
||
}
|
||
#endif
|
||
|
||
///////////////////////////////////////////////////////////////////////////////
|