在系统启动阶段,可以通过实现OAL的IOCTL_HAL_QUERY_FORMAT_PARTITION 以实现对flash等存储设备的格式化,具体实现方案如下:
1、在ioctl_tab.h 添加 { IOCTL_HAL_QUERY_FORMAT_PARTITION, 0, OALIoCtlQueryFormatPartition },
2、因为IOCTL_HAL_QUERY_FORMAT_PARTITION 已经在D:\WINCE700\public\COMMON\oak\inc\pkfuncs.h 中被定义,所以只需在在ioctl.c中添加 OALIoCtlQueryFormatPartition 函数的实现代码即可,代码段如下:
-
DWORD GQueryFormatPartCnt = 0;
-
/*********************************************************************************************************
-
** Function name: OALIoCtlQueryFormatPartition
-
**
-
** Descriptions: 是否格式化NandFlash的分区
-
**
-
**
-
** input parameters: UINT32 code: IOCTL_HAL_QUERY_FORMAT_PARTITION
-
** lpInBuf:指向STORAGECONTEXT 结构体
-
** nInBufSize: sizeof(STORAGECONTEXT)
-
** nOutBufSize: Size of the BOOL value
-
** pOutSize:Unused
-
** output parameters: lpOutBuf:Pointer to a BOOL value. The OAL should return TRUE if the partition is to be formatted. Otherwise it should return FALSE
-
**
-
**
-
** Returned value: TRUE: 初始化成功; FALSE: 初始化失败
-
*********************************************************************************************************/
-
BOOL OALIoCtlQueryFormatPartition (
-
UINT32 code, VOID *lpInBuf , UINT32 nInBufSize, VOID *lpOutBuf,
-
UINT32 nOutBufSize , UINT32 *pOutSize)
-
{
-
#if 1
-
STORAGECONTEXT* pContext = (STORAGECONTEXT*)lpInBuf;
-
-
-
RETAILMSG(1,(_T("INFO: OALIoCtlQueryFormatPartition.\r\n")));
-
-
if (g_pBSPArgs->usRestoreSystem != 2) {
-
return FALSE;
-
}
-
-
//Flash有两个分区,emmc只有一个分区,在格式完一个分区后就将这个置为RESTORE_SYS_NONE
-
GQueryFormatPartCnt++;
-
if (GQueryFormatPartCnt >= 1) { /* 目前要格式化的FlashDisk有两个分区*/
-
g_pBSPArgs->usRestoreSystem = RESTORE_SYS_NONE;
-
}
-
-
/*
-
* validate parameters
-
*/
-
if (sizeof(STORAGECONTEXT) != nInBufSize || !lpInBuf ||
-
sizeof(BOOL) != nOutBufSize || !lpOutBuf) {
-
NKSetLastError(ERROR_INVALID_PARAMETER);
-
RETAILMSG(1,(_T("ERROR:OALIoCtlQueryFormatPartition:Invalid Parameter\r\n")));
-
return FALSE;
-
}
-
-
/*
-
* format the root file system? (MountAsRoot=dword:1)
-
*/
-
if (AFS_FLAG_ROOTFS & pContext->dwFlags) {
-
RETAILMSG(1,(_T("INFO:OALIoCtlQueryFormatPartition:Format Root File System\r\n")));
-
*(BOOL*)lpOutBuf = TRUE;
-
}
-
-
/*
-
* format the bootable file system? (MountAsBootable=dword:1)
-
*/
-
if (AFS_FLAG_BOOTABLE & pContext->dwFlags) {
-
RETAILMSG(1,(_T("INFO:OALIoCtlQueryFormatPartition:Format Bootable File System\r\n")));
-
*(BOOL*)lpOutBuf = TRUE;
-
}
-
-
return TRUE;
-
#endif
-
}
-
DWORD GQueryFormatPartCnt = 0;
-
/*********************************************************************************************************
-
** Function name: OALIoCtlQueryFormatPartition
-
**
-
** Descriptions: 是否格式化NandFlash的分区
-
**
-
**
-
** input parameters: UINT32 code: IOCTL_HAL_QUERY_FORMAT_PARTITION
-
** lpInBuf:指向STORAGECONTEXT 结构体
-
** nInBufSize: sizeof(STORAGECONTEXT)
-
** nOutBufSize: Size of the BOOL value
-
** pOutSize:Unused
-
** output parameters: lpOutBuf:Pointer to a BOOL value. The OAL should return TRUE if the partition is to be formatted. Otherwise it should return FALSE
-
**
-
**
-
** Returned value: TRUE: 初始化成功; FALSE: 初始化失败
-
*********************************************************************************************************/
-
BOOL OALIoCtlQueryFormatPartition (
-
UINT32 code, VOID *lpInBuf , UINT32 nInBufSize, VOID *lpOutBuf,
-
UINT32 nOutBufSize , UINT32 *pOutSize)
-
{
-
#if 1
-
STORAGECONTEXT* pContext = (STORAGECONTEXT*)lpInBuf;
-
-
-
RETAILMSG(1,(_T("INFO: OALIoCtlQueryFormatPartition.\r\n")));
-
-
if (g_pBSPArgs->usRestoreSystem != 2) {
-
return FALSE;
-
}
-
-
//Flash有两个分区,emmc只有一个分区,在格式完一个分区后就将这个置为RESTORE_SYS_NONE
-
GQueryFormatPartCnt++;
-
if (GQueryFormatPartCnt >= 1) { /* 目前要格式化的FlashDisk有两个分区*/
-
g_pBSPArgs->usRestoreSystem = RESTORE_SYS_NONE;
-
}
-
-
/*
-
* validate parameters
-
*/
-
if (sizeof(STORAGECONTEXT) != nInBufSize || !lpInBuf ||
-
sizeof(BOOL) != nOutBufSize || !lpOutBuf) {
-
NKSetLastError(ERROR_INVALID_PARAMETER);
-
RETAILMSG(1,(_T("ERROR:OALIoCtlQueryFormatPartition:Invalid Parameter\r\n")));
-
return FALSE;
-
}
-
-
/*
-
* format the root file system? (MountAsRoot=dword:1)
-
*/
-
if (AFS_FLAG_ROOTFS & pContext->dwFlags) {
-
RETAILMSG(1,(_T("INFO:OALIoCtlQueryFormatPartition:Format Root File System\r\n")));
-
*(BOOL*)lpOutBuf = TRUE;
-
}
-
-
/*
-
* format the bootable file system? (MountAsBootable=dword:1)
-
*/
-
if (AFS_FLAG_BOOTABLE & pContext->dwFlags) {
-
RETAILMSG(1,(_T("INFO:OALIoCtlQueryFormatPartition:Format Bootable File System\r\n")));
-
*(BOOL*)lpOutBuf = TRUE;
-
}
-
-
return TRUE;
-
#endif
-
}
3、在存储设备的注册表中添加注册表信息,以下是一个示例,checkforformat 添加到相应的存储设备中
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\MyStorageProfile\FATFS]
"CheckForFormat"=dword:1
做完,大功告成。
阅读(2303) | 评论(0) | 转发(0) |