pocketstore.c
来自「SAMSUNG S3C6410 CPU BSP for winmobile6」· C语言 代码 · 共 358 行
C
358 行
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/******************************************************************************
*
* System On Chip(SOC)
*
* Copyright (c) 2002 Software Center, Samsung Electronics, Inc.
* All rights reserved.
*
* This software is the confidential and proprietary information of Samsung
* Electronics, Inc("Confidential Information"). You Shall not disclose such
* Confidential Information and shall use it only in accordance with the terms
* of the license agreement you entered into Samsung.
*
******************************************************************************
*/
#include <windows.h>
#include <bsp.h>
#include <ethdbg.h>
#include "loader.h"
#include <XSR.h>
/*****************************************************************************/
/* Debug Definitions */
/*****************************************************************************/
#define EBNAND_ERR_MSG_ON 1
#define EBNAND_LOG_MSG_ON 1
#define EBNAND_INF_MSG_ON 0
#define EBNAND_RTL_PRINT(x) RETAILMSG(1, x)
#if EBNAND_ERR_MSG_ON
#define EBNAND_ERR_PRINT(x) RETAILMSG(1, x)
#else
#define EBNAND_ERR_PRINT(x)
#endif /* #if EBNAND_ERR_MSG_ON */
#if EBNAND_LOG_MSG_ON
#define EBNAND_LOG_PRINT(x) RETAILMSG(1, x)
#else
#define EBNAND_LOG_PRINT(x)
#endif /* #if EBNAND_LOG_MSG_ON */
#if EBNAND_INF_MSG_ON
#define EBNAND_INF_PRINT(x) RETAILMSG(1, x)
#else
#define EBNAND_INF_PRINT(x)
#endif /* #if EBNAND_INF_MSG_ON */
/*****************************************************************************/
/* Global Variables */
/*****************************************************************************/
XSRPartI gstXSRPartI;
/*****************************************************************************/
/* Code Implementation */
/*****************************************************************************/
#define PARTITION_EBOOTCFG (PARTITION_USER_DEF_BASE + 0x1000)
/*****************************************************************************/
/* Block Size of each Partitions */
/*****************************************************************************/
#define PARTITION_SIZE_ONBL1 1
#define PARTITION_SIZE_IPL 2
#define PARTITION_SIZE_EBOOT 4
#define PARTITION_SIZE_COPIEDOS 430
#define PARTITION_SIZE_FILESYSTEM 1562 //550
#define PARTITION_SIZE_EBOOTCFG 1
/*****************************************************************************/
/* */
/* NAME */
/* _SetXSRPI */
/* DESCRIPTION */
/* This function sets XSR Partition Information */
/* PARAMETERS */
/* None */
/* RETURN VALUES */
/* None */
/* NOTES */
/* */
/*****************************************************************************/
VOID
_SetXSRPI(VOID)
{
/*************************************************************************/
/* */
/* For XSR BML Format (Partition Information Setting) */
/* */
/* - NAND Organization (LargeBlock Case) */
/* */
/* Blk #0 Blk #1 Blk #2 Blk #3 */
/* +------------+------------+------------+------------+-------- */
/* |ONBL1,ONBL2 | IPL | . . . */
/* +------------+------------+------------+------------+-------- */
/* |<---------->| */
/* (1) */
/* */
/* Initial Partition Setting */
/* */
/* (1) PARTITION_ID_ONBL1 */
/* */
/*************************************************************************/
gstXSRPartI.nNumOfPartEntry = 6;
gstXSRPartI.stPEntry[0].nID = PARTITION_ID_ONBL1;
gstXSRPartI.stPEntry[0].nAttr = BML_PI_ATTR_RO | BML_PI_ATTR_FROZEN;
gstXSRPartI.stPEntry[0].n1stVbn = 0;
gstXSRPartI.stPEntry[0].nNumOfBlks = PARTITION_SIZE_ONBL1;
gstXSRPartI.stPEntry[1].nID = PARTITION_ID_IPL;
gstXSRPartI.stPEntry[1].nAttr = BML_PI_ATTR_RO | BML_PI_ATTR_FROZEN;
gstXSRPartI.stPEntry[1].n1stVbn = gstXSRPartI.stPEntry[0].n1stVbn + gstXSRPartI.stPEntry[0].nNumOfBlks;
gstXSRPartI.stPEntry[1].nNumOfBlks = PARTITION_SIZE_IPL;
gstXSRPartI.stPEntry[2].nID = PARTITION_ID_EBOOT;
gstXSRPartI.stPEntry[2].nAttr = BML_PI_ATTR_RO | BML_PI_ATTR_FROZEN;
gstXSRPartI.stPEntry[2].n1stVbn = gstXSRPartI.stPEntry[1].n1stVbn + gstXSRPartI.stPEntry[1].nNumOfBlks;
gstXSRPartI.stPEntry[2].nNumOfBlks = PARTITION_SIZE_EBOOT;
gstXSRPartI.stPEntry[3].nID = PARTITION_ID_COPIEDOS;
gstXSRPartI.stPEntry[3].nAttr = BML_PI_ATTR_RO | BML_PI_ATTR_FROZEN;
gstXSRPartI.stPEntry[3].n1stVbn = gstXSRPartI.stPEntry[2].n1stVbn + gstXSRPartI.stPEntry[2].nNumOfBlks;
gstXSRPartI.stPEntry[3].nNumOfBlks = PARTITION_SIZE_COPIEDOS;
gstXSRPartI.stPEntry[4].nID = PARTITION_ID_FILESYSTEM;
gstXSRPartI.stPEntry[4].nAttr = BML_PI_ATTR_RW;
gstXSRPartI.stPEntry[4].n1stVbn = gstXSRPartI.stPEntry[3].n1stVbn + gstXSRPartI.stPEntry[3].nNumOfBlks;
gstXSRPartI.stPEntry[4].nNumOfBlks = PARTITION_SIZE_FILESYSTEM;
gstXSRPartI.stPEntry[5].nID = PARTITION_ID_EBOOTCFG;
gstXSRPartI.stPEntry[5].nAttr = BML_PI_ATTR_RW;
gstXSRPartI.stPEntry[5].n1stVbn = gstXSRPartI.stPEntry[4].n1stVbn + gstXSRPartI.stPEntry[4].nNumOfBlks;
gstXSRPartI.stPEntry[5].nNumOfBlks = PARTITION_SIZE_EBOOTCFG;
}
#define PSFTL_SAM_BUF_FACTOR 0 /* 0 < FACTOR < 100 */
#define PSFTL_FILLFACTOR 100 /* Percentage, Full Usage Fill Factor = 100 */
#define PSFTL_RSVBLKS 2 /* Reserved Units, should be >= 2 */
#define PSFTL_BLKSPERUNIT 1 /* Maximum sectors per Unit is 256 */
BOOL PocketStoreInitialize(void)
{
/*---------------------------------*/
/* Note */
/* Currently support Volume 0 only */
/*---------------------------------*/
UINT32 nVol = 0;
BOOL32 bRet = FALSE;
INT32 nRet;
UINT32 nBytesReturned;
EdbgOutputDebugString("[EBOOT: IN] ++PocketStoreInitialize()\r\n");
do {
/* BML Init */
if (BML_Init() != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT: ] BML_Init error\r\n");
break;
}
EdbgOutputDebugString("[EBOOT: ] BML_Init success\r\n");
/*-------------------------------*/
/* Set XSR Partition Information */
/*-------------------------------*/
_SetXSRPI();
/* Open Device */
if (BML_Open(nVol) != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT: ] Vol %d is not Opened\r\n", nVol);
/* BML Format */
EdbgOutputDebugString("[EBOOT: ] BML_Format\r\n");
nRet = BML_Format(nVol, &gstXSRPartI, BML_INIT_FORMAT);
if (nRet != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT: ] BML_Format error\r\n");
while(1);
}
EdbgOutputDebugString("[EBOOT: ] BML_Format success\r\n");
if (BML_Open(nVol) != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT: ] Vol %d is not Opened\r\n", nVol);
break;
}
}
EdbgOutputDebugString("[EBOOT: ] Vol %d is Opened\r\n", nVol);
/* Unlock all blocks of NAND flash device */
nRet = BML_IOCtl(nVol,
BML_IOCTL_UNLOCK_WHOLEAREA,
NULL,
0,
NULL,
0,
&nBytesReturned);
if (nRet != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT:ERR] BML_IOCtl error\r\n");
break;
}
#ifdef MULTIDEVICEMULTIFOLDER
nVol = 1;
/* Open Device */
if (BML_Open(nVol) != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT: ] Vol %d is not Opened\r\n", nVol);
/* BML Format */
EdbgOutputDebugString("[EBOOT: ] BML_Format\r\n");
nRet = BML_Format(nVol, &gstXSRPartI2, BML_INIT_FORMAT);
if (nRet != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT: ] BML_Format error\r\n");
while(1);
}
EdbgOutputDebugString("[EBOOT: ] BML_Format success\r\n");
if (BML_Open(nVol) != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT: ] Vol %d is not Opened\r\n", nVol);
break;
}
}
EdbgOutputDebugString("[EBOOT: ] Vol %d is Opened\r\n", nVol);
/* Unlock all blocks of NAND flash device */
nRet = BML_IOCtl(nVol,
BML_IOCTL_UNLOCK_WHOLEAREA,
NULL,
0,
NULL,
0,
&nBytesReturned);
if (nRet != BML_SUCCESS)
{
EdbgOutputDebugString("[EBOOT:ERR] BML_IOCtl error\r\n");
break;
}
#endif
EdbgOutputDebugString("[EBOOT: ] PocketStoreInitialize success\r\n");
bRet = TRUE32;
} while(0);
#if 0
/* Close Device */
if (BML_Close(nVol) != BML_SUCCESS)
{
EBNAND_RTL_PRINT((L"BML_Close error\r\n"));
}
#endif
EBNAND_RTL_PRINT((TEXT("--PocketStoreInitialize()\r\n")));
return bRet;
}
BOOL PocketStoreII_STL_Format(UINT32 nPartID)
{
UINT32 nVol = 0;
BOOL32 bRet = TRUE;
UINT32 nBytesReturned;
INT32 nErr;
STLConfig stSTLCfg;
STLInfo stSTLInfo;
// nErr = STL_Init();
STL_Close(0,PARTITION_ID_COPIEDOS);
if (BML_Open(nVol) != BML_SUCCESS)
{
EBNAND_RTL_PRINT((L"[EBOOT:ERR] BML_Open error\r\n"));
}
nErr = BML_IOCtl(nVol,
BML_IOCTL_UNLOCK_WHOLEAREA,
NULL, 0,
NULL, 0,
&nBytesReturned);
if (nErr != BML_SUCCESS)
{
EBNAND_RTL_PRINT((L"[EBOOT:ERR] BML_IOCtl error\r\n"));
while(1);
}
/* STL Open */
stSTLInfo.nTotalLogScts = 0; /* Output : The number of total logical sectors */
stSTLInfo.nLogSctsPerUnit = 0; /* Output : The number of sectors per a unit */
stSTLInfo.nSamBufFactor = PSFTL_SAM_BUF_FACTOR; /* Input : 0 or 1 ~ 100 */
stSTLInfo.bASyncMode = FALSE32;
/* STL Cfg setting for STL Format */
stSTLCfg.nFillFactor = PSFTL_FILLFACTOR; /* LogSctsPerUnit : UsableSctsPerUnit */
/* Percentage, Full Usage Fill Factor = 100 */
stSTLCfg.nNumOfRsvUnits = PSFTL_RSVBLKS; /* Reserved Units, should be >= 2 */
stSTLCfg.nBlksPerUnit = PSFTL_BLKSPERUNIT; /* Maximum sectors per Unit is 256 */
stSTLCfg.nSnapshots = NUM_OF_SNAPSHOT_1; /* NUM_OF_SNAPSHOT_1 or NUM_OF_SNAPSHOT_4 */
/* STL_Format */
EBNAND_RTL_PRINT((L"[EBOOT:INF] STL_Format Start (Partition ID:%x)\r\n", nPartID));
nErr = STL_Format(nVol,
nPartID,
&stSTLCfg,
STL_FORMAT_REMEMBER_ECNT);
if (nErr != STL_SUCCESS)
{
EBNAND_RTL_PRINT((L"[EBOOT:ERR] STL_Format Error = 0x%x\r\n", nErr));
bRet = FALSE;
}
else EBNAND_RTL_PRINT((L"[EBOOT:INF] STL_Format OK\r\n"));
EBNAND_RTL_PRINT((L"[EBOOT: ] +---------------------------+\r\n"));
EBNAND_RTL_PRINT((L"[EBOOT: ] | STL(FAT) FORMAT FINISHED! |\r\n"));
EBNAND_RTL_PRINT((L"[EBOOT: ] +---------------------------+\r\n"));
if ( nPartID == PARTITION_ID_COPIEDOS )
{
nErr = STL_Open(nVol, PARTITION_ID_COPIEDOS, &stSTLInfo);
if (nErr != STL_SUCCESS)
{
EBNAND_RTL_PRINT((L"STL_Open is failed\r\n"));
while(1);
}
}
return bRet;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?