system/cfgdata: implement "format" option
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
parent
f1a74533f2
commit
c88dd4bbaf
@ -31,6 +31,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private data
|
||||
@ -87,7 +88,9 @@ static void cfgdatacmd_help(void)
|
||||
static int cfgdatacmd_idtok(int startpos, char *token)
|
||||
{
|
||||
while (token[startpos] != ',' && token[startpos] != '\0')
|
||||
{
|
||||
startpos++;
|
||||
}
|
||||
|
||||
if (token[startpos] != ',')
|
||||
{
|
||||
@ -295,7 +298,7 @@ static void cfgdatacmd_set(int argc, char *argv[])
|
||||
|
||||
if (isnumber)
|
||||
{
|
||||
sscanf(&argv[3][2], "%x", (int32_t *) &cfg.configdata);
|
||||
sscanf(&argv[3][2], "%" SCNx32, (int32_t *)&cfg.configdata);
|
||||
cfg.len = 4;
|
||||
}
|
||||
}
|
||||
@ -331,7 +334,7 @@ static void cfgdatacmd_set(int argc, char *argv[])
|
||||
|
||||
/* Now open the /dev/config file and set the config item */
|
||||
|
||||
if ((fd = open(g_config_dev, O_RDONLY)) < 2)
|
||||
if ((fd = open(g_config_dev, O_WRONLY)) < 2)
|
||||
{
|
||||
/* Display error */
|
||||
|
||||
@ -339,7 +342,7 @@ static void cfgdatacmd_set(int argc, char *argv[])
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ioctl(fd, CFGDIOC_SETCONFIG, (unsigned long) &cfg);
|
||||
ret = ioctl(fd, CFGDIOC_SETCONFIG, (unsigned long)(uintptr_t)&cfg);
|
||||
|
||||
/* Close the file and report error if any */
|
||||
|
||||
@ -398,7 +401,7 @@ static void cfgdatacmd_unset(int argc, char *argv[])
|
||||
|
||||
/* Try to open the /dev/config file */
|
||||
|
||||
if ((fd = open(g_config_dev, O_RDONLY)) < 2)
|
||||
if ((fd = open(g_config_dev, O_WRONLY)) < 2)
|
||||
{
|
||||
/* Display error */
|
||||
|
||||
@ -408,7 +411,7 @@ static void cfgdatacmd_unset(int argc, char *argv[])
|
||||
|
||||
/* Delete the config item */
|
||||
|
||||
ret = ioctl(fd, CFGDIOC_DELCONFIG, (unsigned long) &cfg);
|
||||
ret = ioctl(fd, CFGDIOC_DELCONFIG, (unsigned long)(uintptr_t)&cfg);
|
||||
close(fd);
|
||||
|
||||
if (ret != OK)
|
||||
@ -478,7 +481,7 @@ static void cfgdatacmd_print(int argc, char *argv[])
|
||||
|
||||
/* Get the config item */
|
||||
|
||||
ret = ioctl(fd, CFGDIOC_GETCONFIG, (unsigned long) &cfg);
|
||||
ret = ioctl(fd, CFGDIOC_GETCONFIG, (unsigned long)(uintptr_t)&cfg);
|
||||
close(fd);
|
||||
|
||||
if (ret != OK)
|
||||
@ -575,7 +578,7 @@ static void cfgdatacmd_show_all_config_items(void)
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ioctl(fd, CFGDIOC_FIRSTCONFIG, (unsigned long) &cfg);
|
||||
ret = ioctl(fd, CFGDIOC_FIRSTCONFIG, (unsigned long)(uintptr_t)&cfg);
|
||||
|
||||
while (ret != -1)
|
||||
{
|
||||
@ -636,13 +639,41 @@ static void cfgdatacmd_show_all_config_items(void)
|
||||
/* Get the next config item */
|
||||
|
||||
cfg.len = 256;
|
||||
ret = ioctl(fd, CFGDIOC_NEXTCONFIG, (unsigned long) &cfg);
|
||||
ret = ioctl(fd, CFGDIOC_NEXTCONFIG, (unsigned long)(uintptr_t)&cfg);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
free(cfg.configdata);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Erase all config items
|
||||
****************************************************************************/
|
||||
|
||||
static void cfgdatacmd_format(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
/* Try to open the /dev/config file */
|
||||
|
||||
if ((fd = open(g_config_dev, O_WRONLY)) < 2)
|
||||
{
|
||||
/* Display error */
|
||||
|
||||
printf("error: unable to open %s\n", g_config_dev);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ioctl(fd, MTDIOC_BULKERASE, 0);
|
||||
close(fd);
|
||||
|
||||
if (ret != OK)
|
||||
{
|
||||
printf("Error %d config format\n", errno);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -721,6 +752,16 @@ int main(int argc, FAR char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Test for "format" cmd */
|
||||
|
||||
if (strcmp(argv[1], "format") == 0)
|
||||
{
|
||||
/* Call the routine to erase all config items */
|
||||
|
||||
cfgdatacmd_format();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Unknown cmd */
|
||||
|
||||
printf("Unknown config command: %s\n", argv[1]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user