Skip to content
Snippets Groups Projects
Commit d95633e6 authored by Ronny Nilsson's avatar Ronny Nilsson
Browse files

Support for erasing UBI volumes.

parent aefb770c
Branches
No related tags found
No related merge requests found
...@@ -114,6 +114,37 @@ static unsigned int ubi_read_blk(unsigned char *start, unsigned int blk, unsigne ...@@ -114,6 +114,37 @@ static unsigned int ubi_read_blk(unsigned char *start, unsigned int blk, unsigne
//-------------------------------------------------------------
// Erase an UBI volume (if exists).
int ubi_erase_volume(int devId, int volId)
{
char nodePath[UBI_MAX_VOLUME_NAME];
struct ubi_vol_info volInfo;
memset(&volInfo, 0, sizeof(volInfo));
if(!ubi_dev_present(libubi, devId)) return -1;
if(ubi_get_vol_info1(libubi, devId, volId, &volInfo) && errno == ENODEV) {
fprintf(stderr, "Error deleting volume %d: %s\n", volId, strerror(errno));
return -1;
}
else if(volInfo.dev_num != devId || volInfo.vol_id != volId) {
fprintf(stderr, "Error deleting volume %d\n", volId);
return -1;
}
snprintf(nodePath, UBI_MAX_VOLUME_NAME, "/dev/ubi%d", devId);
if(ubi_rmvol(libubi, nodePath, volId)) {
fprintf(stderr, "Error deleting volume %d: %s\n", volId, strerror(errno));
return -1;
}
return 0;
}
//------------------------------------------------------------- //-------------------------------------------------------------
// Init the UBI library and query system for info. // Init the UBI library and query system for info.
static int ubi_probe(void) static int ubi_probe(void)
...@@ -424,6 +455,7 @@ static int meta_generate_blob(int seqNo) ...@@ -424,6 +455,7 @@ static int meta_generate_blob(int seqNo)
static int meta_manage_vols(void) static int meta_manage_vols(void)
{ {
int highSeqNo, highMeta, i, newMeta, delMeta; int highSeqNo, highMeta, i, newMeta, delMeta;
struct metaInfo_t *tmpMeta;
highSeqNo = 0; highSeqNo = 0;
highMeta = 0; highMeta = 0;
...@@ -477,6 +509,11 @@ static int meta_manage_vols(void) ...@@ -477,6 +509,11 @@ static int meta_manage_vols(void)
printf(".\n"); printf(".\n");
} }
tmpMeta = meta_by_id(newMeta);
if(tmpMeta) {
ubi_erase_volume(tmpMeta->volInfo.dev_num, tmpMeta->volInfo.vol_id);
}
//delete_volume(newMeta); //delete_volume(newMeta);
//create_new_ubi(newMeta) //create_new_ubi(newMeta)
//write_metadata(newMeta) //write_metadata(newMeta)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment