mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-15 19:08:54 +00:00
v1.0.3
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2023, ArtInChip Technology Co., Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Authors: mingfeng.li <mingfeng.li@artinchip.com>
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -6,6 +12,160 @@
|
||||
#include <aic_core.h>
|
||||
#include <mtd.h>
|
||||
|
||||
static struct nftl_volume *nftl_new_volume(char *s)
|
||||
{
|
||||
struct nftl_volume *vol = NULL;
|
||||
int cnt = 0;
|
||||
char *p;
|
||||
|
||||
vol = malloc(sizeof(struct nftl_volume));
|
||||
if (!vol)
|
||||
return NULL;
|
||||
|
||||
memset(vol, 0, sizeof(struct nftl_volume));
|
||||
|
||||
p = s;
|
||||
if (*p == '-') {
|
||||
/* All remain space */
|
||||
vol->size = 0;
|
||||
p++;
|
||||
} else {
|
||||
vol->size = strtoull(p, &p, 0);
|
||||
}
|
||||
if (*p == '@') {
|
||||
p++;
|
||||
/* Don't care offset here, just skip it */
|
||||
strtoull(p, &p, 0);
|
||||
}
|
||||
if (*p != '(') {
|
||||
printf("Volume name should be next of size.\n");
|
||||
goto err;
|
||||
}
|
||||
p++;
|
||||
|
||||
cnt = 0;
|
||||
while (*p != ')') {
|
||||
if (cnt >= MAX_NAND_NAME)
|
||||
break;
|
||||
vol->name[cnt++] = *p++;
|
||||
}
|
||||
p++;
|
||||
|
||||
vol->vol_type = 1; /* Default is dynamic */
|
||||
if (*p == 's')
|
||||
vol->vol_type = 0; /* Static volume */
|
||||
|
||||
/* Skip characters until '\0', ',', ';' */
|
||||
while ((*p != '\0') && (*p != ';') && (*p != ','))
|
||||
p++;
|
||||
|
||||
if (*p == ',') {
|
||||
p++;
|
||||
vol->next = nftl_new_volume(p);
|
||||
}
|
||||
|
||||
printf("nftl vol: %s, size %d\n", vol->name, vol->size);
|
||||
return vol;
|
||||
err:
|
||||
if (vol)
|
||||
free(vol);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void nftl_free_volume(struct nftl_volume *vol)
|
||||
{
|
||||
if (!vol)
|
||||
return;
|
||||
|
||||
nftl_free_volume(vol->next);
|
||||
free(vol);
|
||||
}
|
||||
|
||||
void free_nftl_list(struct nftl_mtd *nftl)
|
||||
{
|
||||
if (!nftl)
|
||||
return;
|
||||
|
||||
free_nftl_list(nftl->next);
|
||||
nftl_free_volume(nftl->vols);
|
||||
free(nftl);
|
||||
}
|
||||
|
||||
struct nftl_mtd *build_nftl_list(char *nftlvols)
|
||||
{
|
||||
struct nftl_mtd *head, *cur, *nxt;
|
||||
char *p;
|
||||
int cnt;
|
||||
|
||||
head = NULL;
|
||||
cur = NULL;
|
||||
p = nftlvols;
|
||||
|
||||
next:
|
||||
nxt = malloc(sizeof(struct nftl_mtd));
|
||||
if (!nxt)
|
||||
goto err;
|
||||
memset(nxt, 0, sizeof(struct nftl_mtd));
|
||||
|
||||
if (cur)
|
||||
cur->next = nxt;
|
||||
cur = nxt;
|
||||
if (!head)
|
||||
head = cur;
|
||||
|
||||
cnt = 0;
|
||||
while (*p != '\0' && *p != ':') {
|
||||
if (cnt >= MAX_NAND_NAME)
|
||||
break;
|
||||
cur->name[cnt++] = *p++;
|
||||
}
|
||||
|
||||
if (*p != ':') {
|
||||
printf("nftlvols_nand is invalid\n");
|
||||
goto err;
|
||||
}
|
||||
p++;
|
||||
|
||||
cur->vols = nftl_new_volume(p);
|
||||
if (!cur->vols) {
|
||||
printf("Build nftl volume list failed.\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Check if there is other nftl device */
|
||||
while (*p != '\0' && *p != ';')
|
||||
p++;
|
||||
|
||||
if (*p == ';') {
|
||||
p++;
|
||||
goto next;
|
||||
}
|
||||
|
||||
return head;
|
||||
err:
|
||||
if (head)
|
||||
free_nftl_list(head);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u8 partition_nftl_is_exist(char *mtd_name, struct nftl_mtd *nftl_list)
|
||||
{
|
||||
struct nftl_mtd *current_list;
|
||||
|
||||
if (nftl_list == NULL) {
|
||||
return 0;
|
||||
}
|
||||
current_list = nftl_list;
|
||||
|
||||
while (current_list) {
|
||||
if (strcmp(mtd_name, current_list->name) == 0)
|
||||
return 1;
|
||||
current_list = current_list->next;
|
||||
}
|
||||
pr_debug("NFTL Partition %s is not exist.....\n", mtd_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct mtd_partition *_part_parse(char *parts, u32 start)
|
||||
{
|
||||
struct mtd_partition *part;
|
||||
@@ -76,7 +236,6 @@ err:
|
||||
struct mtd_partition *mtd_parts_parse(char *parts)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = parts;
|
||||
|
||||
while ((*p != '\0') && (*p != ':'))
|
||||
|
||||
Reference in New Issue
Block a user