Skip to content

Instantly share code, notes, and snippets.

@aep
Created April 12, 2018 17:41
Show Gist options
  • Save aep/e2aba2a3ea918c3d91ff52525d67cf59 to your computer and use it in GitHub Desktop.
Save aep/e2aba2a3ea918c3d91ff52525d67cf59 to your computer and use it in GitHub Desktop.
int nm_lib_parsePtnIndexFile(NM_PTN_STRUCT *ptnStruct, char *ptr)
{
int index = 0;
int paraId = -1;
int argc;
char *argv[NM_PTN_INDEX_ARG_NUM_MAX];
char buf[NM_PTN_INDEX_SIZE+1] = {0};
NM_PTN_ENTRY *currPtnEntry = NULL;
/* reset partition-table param */
memset(ptnStruct, 0, sizeof(NM_PTN_STRUCT));
for (index=0; index<NM_PTN_NUM_MAX; index++)
{
ptnStruct->entries[index].usedFlag = FALSE;
}
strncpy((char *)buf, (char *)ptr, NM_PTN_INDEX_SIZE+1);
argc = nm_lib_makeArgs(buf, argv, NM_PTN_INDEX_ARG_NUM_MAX);
index = 0;
while (index < argc)
{
if ((paraId = nm_lib_strToKey(nm_ptnIndexFileParaStrMap, argv[index])) < 0)
{
NM_ERROR("invalid partition-index-file para id.");
goto error;
}
index++;
switch (paraId)
{
case NM_PTN_INDEX_PARA_ID_NAME:
/* check if this partition-name already be used */
if (nm_lib_ptnNameToEntry(ptnStruct, argv[index]) != NULL)
{
NM_ERROR("duplicate partition name found.");
goto error;
}
/* get a new partition-entry */
if ((currPtnEntry = nm_lib_fetchUnusedPtnEntry(ptnStruct)) == NULL)
{
NM_ERROR("too many partitions.");
goto error;
}
strncpy(currPtnEntry->name, argv[index], NM_PTN_NAME_LEN);
currPtnEntry->usedFlag = TRUE;
index++;
break;
case NM_PTN_INDEX_PARA_ID_BASE:
if (nm_lib_parseU32((NM_UINT32 *)&currPtnEntry->base, argv[index]) < 0)
{
NM_ERROR("parse base-addr value failed.");
goto error;
}
index++;
break;
case NM_PTN_INDEX_PARA_ID_TAIL:
if (nm_lib_parseU32((NM_UINT32 *)&currPtnEntry->tail, argv[index]) < 0)
{
NM_ERROR("parse tail-addr value failed.");
goto error;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment