Chinaunix首页 | 论坛 | 博客
  • 博客访问: 334402
  • 博文数量: 97
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 636
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-12 22:41
文章分类

全部博文(97)

文章存档

2017年(8)

2015年(87)

2014年(2)

我的朋友

分类: 嵌入式

2015-06-13 13:50:40

在系统启动阶段,可以通过实现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 函数的实现代码即可,代码段如下:

点击(此处)折叠或打开

  1. DWORD GQueryFormatPartCnt = 0;
  2. /*********************************************************************************************************
  3. ** Function name: OALIoCtlQueryFormatPartition
  4. **
  5. ** Descriptions: 是否格式化NandFlash的分区
  6. **
  7. **
  8. ** input parameters: UINT32 code: IOCTL_HAL_QUERY_FORMAT_PARTITION
  9. ** lpInBuf:指向STORAGECONTEXT 结构体
  10. ** nInBufSize: sizeof(STORAGECONTEXT)
  11. ** nOutBufSize: Size of the BOOL value
  12. ** pOutSize:Unused
  13. ** 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
  14. **
  15. **
  16. ** Returned value: TRUE: 初始化成功; FALSE: 初始化失败
  17. *********************************************************************************************************/
  18. BOOL OALIoCtlQueryFormatPartition (
  19.                                    UINT32 code, VOID *lpInBuf , UINT32 nInBufSize, VOID *lpOutBuf,
  20.                                    UINT32 nOutBufSize , UINT32 *pOutSize)
  21. {
  22. #if 1
  23.     STORAGECONTEXT* pContext = (STORAGECONTEXT*)lpInBuf;


  24.     RETAILMSG(1,(_T("INFO: OALIoCtlQueryFormatPartition.\r\n")));

  25.     if (g_pBSPArgs->usRestoreSystem != 2) {
  26.         return FALSE;
  27.     }

  28.     //Flash有两个分区,emmc只有一个分区,在格式完一个分区后就将这个置为RESTORE_SYS_NONE
  29.     GQueryFormatPartCnt++;
  30.     if (GQueryFormatPartCnt >= 1) {                                        /* 目前要格式化的FlashDisk有两个分区*/
  31.         g_pBSPArgs->usRestoreSystem = RESTORE_SYS_NONE;
  32.     }

  33.     /*
  34.     * validate parameters
  35.     */
  36.     if (sizeof(STORAGECONTEXT) != nInBufSize || !lpInBuf ||
  37.         sizeof(BOOL) != nOutBufSize || !lpOutBuf) {
  38.             NKSetLastError(ERROR_INVALID_PARAMETER);
  39.             RETAILMSG(1,(_T("ERROR:OALIoCtlQueryFormatPartition:Invalid Parameter\r\n")));
  40.             return FALSE;
  41.     }

  42.     /*
  43.     * format the root file system? (MountAsRoot=dword:1)
  44.     */
  45.     if (AFS_FLAG_ROOTFS & pContext->dwFlags) {
  46.         RETAILMSG(1,(_T("INFO:OALIoCtlQueryFormatPartition:Format Root File System\r\n")));
  47.         *(BOOL*)lpOutBuf = TRUE;
  48.     }

  49.     /*
  50.     * format the bootable file system? (MountAsBootable=dword:1)
  51.     */
  52.     if (AFS_FLAG_BOOTABLE & pContext->dwFlags) {
  53.         RETAILMSG(1,(_T("INFO:OALIoCtlQueryFormatPartition:Format Bootable File System\r\n")));
  54.         *(BOOL*)lpOutBuf = TRUE;
  55.     }

  56.     return TRUE;
  57. #endif
  58. }


点击(此处)折叠或打开

  1. DWORD GQueryFormatPartCnt = 0;
  2. /*********************************************************************************************************
  3. ** Function name: OALIoCtlQueryFormatPartition
  4. **
  5. ** Descriptions: 是否格式化NandFlash的分区
  6. **
  7. **
  8. ** input parameters: UINT32 code: IOCTL_HAL_QUERY_FORMAT_PARTITION
  9. ** lpInBuf:指向STORAGECONTEXT 结构体
  10. ** nInBufSize: sizeof(STORAGECONTEXT)
  11. ** nOutBufSize: Size of the BOOL value
  12. ** pOutSize:Unused
  13. ** 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
  14. **
  15. **
  16. ** Returned value: TRUE: 初始化成功; FALSE: 初始化失败
  17. *********************************************************************************************************/
  18. BOOL OALIoCtlQueryFormatPartition (
  19.                                    UINT32 code, VOID *lpInBuf , UINT32 nInBufSize, VOID *lpOutBuf,
  20.                                    UINT32 nOutBufSize , UINT32 *pOutSize)
  21. {
  22. #if 1
  23.     STORAGECONTEXT* pContext = (STORAGECONTEXT*)lpInBuf;


  24.     RETAILMSG(1,(_T("INFO: OALIoCtlQueryFormatPartition.\r\n")));

  25.     if (g_pBSPArgs->usRestoreSystem != 2) {
  26.         return FALSE;
  27.     }

  28.     //Flash有两个分区,emmc只有一个分区,在格式完一个分区后就将这个置为RESTORE_SYS_NONE
  29.     GQueryFormatPartCnt++;
  30.     if (GQueryFormatPartCnt >= 1) {                                        /* 目前要格式化的FlashDisk有两个分区*/
  31.         g_pBSPArgs->usRestoreSystem = RESTORE_SYS_NONE;
  32.     }

  33.     /*
  34.     * validate parameters
  35.     */
  36.     if (sizeof(STORAGECONTEXT) != nInBufSize || !lpInBuf ||
  37.         sizeof(BOOL) != nOutBufSize || !lpOutBuf) {
  38.             NKSetLastError(ERROR_INVALID_PARAMETER);
  39.             RETAILMSG(1,(_T("ERROR:OALIoCtlQueryFormatPartition:Invalid Parameter\r\n")));
  40.             return FALSE;
  41.     }

  42.     /*
  43.     * format the root file system? (MountAsRoot=dword:1)
  44.     */
  45.     if (AFS_FLAG_ROOTFS & pContext->dwFlags) {
  46.         RETAILMSG(1,(_T("INFO:OALIoCtlQueryFormatPartition:Format Root File System\r\n")));
  47.         *(BOOL*)lpOutBuf = TRUE;
  48.     }

  49.     /*
  50.     * format the bootable file system? (MountAsBootable=dword:1)
  51.     */
  52.     if (AFS_FLAG_BOOTABLE & pContext->dwFlags) {
  53.         RETAILMSG(1,(_T("INFO:OALIoCtlQueryFormatPartition:Format Bootable File System\r\n")));
  54.         *(BOOL*)lpOutBuf = TRUE;
  55.     }

  56.     return TRUE;
  57. #endif
  58. }

3、在存储设备的注册表中添加注册表信息,以下是一个示例,checkforformat 添加到相应的存储设备中
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\MyStorageProfile\FATFS]
    "CheckForFormat"=dword:1

做完,大功告成。
阅读(2214) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~