MassStorageCopy updated to manage several node names.
Depending of the board revision, mount point name could be different. Ex for: STM32F030R8 with a rev 1 node name is : "NUCLEO" while it is "NODE_F030R8" for rev c Ex: in boards.txt we could have: Nucleo_64.menu.Nucleo_64_board.NUCLEO_F030R8.node="NODE_F030R8,NUCLEO" Fix #6 Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
This commit is contained in:
parent
1ba6db25b6
commit
82eb13a6d6
5 changed files with 127 additions and 42 deletions
Binary file not shown.
Binary file not shown.
|
|
@ -1,9 +0,0 @@
|
||||||
@ECHO off
|
|
||||||
SET SOURCE=%2
|
|
||||||
SET SRC_PARSE=%SOURCE:/=\%
|
|
||||||
SET TARGET=%4
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
for /F "skip=1 tokens=*" %%a in ('WMIC LOGICALDISK where "volumename like '%TARGET%%%'" get deviceid') do if not defined id set id=%%a
|
|
||||||
Call Set "deviceid=%%id: =%%"
|
|
||||||
if not "%deviceid%" == "" (XCOPY %SRC_PARSE% %deviceid% /Y /Q >NUL
|
|
||||||
echo Upload complete ) else ( echo %TARGET% not found. Please ensure the device is correctly connected)
|
|
||||||
|
|
@ -4,13 +4,38 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <mntent.h>
|
#include <mntent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
static char *input_path = NULL;
|
||||||
|
static char *output_path = NULL;
|
||||||
|
static char *output_dev = NULL;
|
||||||
|
static char **list_output_dev = NULL;
|
||||||
|
static char *cmd = NULL;
|
||||||
|
static FILE *aFile = NULL;
|
||||||
|
|
||||||
void usage(char *name)
|
void usage(char *name)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [-I <filepath>] [-O <mountpoint> ]\n\n", name);
|
printf("Usage: %s [-I <filepath>] [-O <mountpoint(s)> ]\n\n", name);
|
||||||
printf("Mandatory options:\n");
|
printf("Mandatory options:\n");
|
||||||
printf("\t-I: filepath binary to copy\n");
|
printf("\t-I: filepath binary to copy\n");
|
||||||
printf("\t-O: mountpoint destination name\n");
|
printf("\t-O: mountpoint(s) destination name.\n");
|
||||||
|
printf("\t Could be a list (separated by','). Ex: \"NODE_1,NODE2,NODE_3\"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_ressource()
|
||||||
|
{
|
||||||
|
if(input_path)
|
||||||
|
free(input_path);
|
||||||
|
if(output_path)
|
||||||
|
free(output_path);
|
||||||
|
if(output_dev)
|
||||||
|
free(output_dev);
|
||||||
|
if(list_output_dev)
|
||||||
|
free(list_output_dev);
|
||||||
|
if(cmd)
|
||||||
|
free(cmd);
|
||||||
|
if(aFile)
|
||||||
|
endmntent(aFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
@ -18,12 +43,10 @@ int main(int argc, char *argv[])
|
||||||
int c, i;
|
int c, i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int device_found = 0;
|
int device_found = 0;
|
||||||
char input_path[256] = "";
|
|
||||||
char output_dev[256] = "";
|
|
||||||
char output_path[256] = "";
|
|
||||||
char cmd[512] = "";
|
|
||||||
struct mntent *ent = NULL;
|
struct mntent *ent = NULL;
|
||||||
FILE *aFile = NULL;
|
char *p = NULL;
|
||||||
|
int n_output_dev = 0;
|
||||||
|
char scp_cmd[]="scp";
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
|
|
||||||
|
|
@ -31,10 +54,14 @@ int main(int argc, char *argv[])
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'I':
|
case 'I':
|
||||||
strcpy(input_path, optarg);
|
input_path = malloc(strlen(optarg)+1);
|
||||||
|
if(input_path != NULL)
|
||||||
|
strcpy(input_path, optarg);
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
strcpy(output_dev, optarg);
|
output_dev = malloc(strlen(optarg)+1);
|
||||||
|
if(output_dev != NULL)
|
||||||
|
strcpy(output_dev, optarg);
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
if ((optopt == 'I') || (optopt == 'O'))
|
if ((optopt == 'I') || (optopt == 'O'))
|
||||||
|
|
@ -46,40 +73,77 @@ int main(int argc, char *argv[])
|
||||||
"Unknown option character `\\x%x'.\n",
|
"Unknown option character `\\x%x'.\n",
|
||||||
optopt);
|
optopt);
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 1;
|
free_ressource();
|
||||||
|
return EINVAL;
|
||||||
default:
|
default:
|
||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((input_path == NULL) || (output_dev == NULL))
|
||||||
|
{
|
||||||
|
free_ressource();
|
||||||
|
exit(ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
if (strlen(input_path) && strlen(output_dev))
|
if (strlen(input_path) && strlen(output_dev))
|
||||||
{
|
{
|
||||||
//get the mounted devives list
|
/* get the mounted devives list */
|
||||||
aFile = setmntent("/proc/mounts", "r");
|
aFile = setmntent("/proc/mounts", "r");
|
||||||
if (aFile == NULL) {
|
if (aFile == NULL) {
|
||||||
perror("setmntent");
|
perror("setmntent");
|
||||||
exit(1);
|
free_ressource();
|
||||||
|
exit(ENOENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//now lets read the path of the device
|
p = strtok (output_dev, ",");
|
||||||
while (NULL != (ent = getmntent(aFile))) {
|
|
||||||
if (strstr(ent->mnt_dir, output_dev)) {
|
/* split output_dev and append tokens to list_output_dev */
|
||||||
sprintf(output_path, "%s", ent->mnt_dir);
|
while (p) {
|
||||||
device_found = 1;
|
list_output_dev = realloc (list_output_dev, sizeof (char*) * ++n_output_dev);
|
||||||
|
|
||||||
|
if (list_output_dev == NULL)
|
||||||
|
exit (ENOMEM);
|
||||||
|
|
||||||
|
list_output_dev[n_output_dev-1] = p;
|
||||||
|
|
||||||
|
p = strtok (NULL, ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* realloc one extra element for the last NULL */
|
||||||
|
list_output_dev = realloc (list_output_dev, sizeof (char*) * (n_output_dev+1));
|
||||||
|
list_output_dev[n_output_dev] = 0;
|
||||||
|
|
||||||
|
/* now lets read the path of the device */
|
||||||
|
while ((NULL != (ent = getmntent(aFile))) && (!device_found)) {
|
||||||
|
for (i = 0; (i < (n_output_dev)) && (!device_found); ++i) {
|
||||||
|
if (strstr(ent->mnt_dir, list_output_dev[i])) {
|
||||||
|
output_path = malloc(strlen(ent->mnt_dir)+1);
|
||||||
|
if(output_path != NULL) {
|
||||||
|
sprintf(output_path, "%s", ent->mnt_dir);
|
||||||
|
} else {
|
||||||
|
free_ressource();
|
||||||
|
exit(ENOMEM);
|
||||||
|
}
|
||||||
|
device_found = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endmntent(aFile);
|
|
||||||
|
|
||||||
if(device_found) {
|
if(device_found) {
|
||||||
printf("copying %s to %s\n", input_path, output_path);
|
printf("copying %s to %s\n", input_path, output_path);
|
||||||
|
cmd = malloc(strlen(scp_cmd)+1+strlen(input_path)+1+strlen(output_path)+1);
|
||||||
sprintf(cmd, "scp %s %s", input_path, output_path);
|
if(cmd != NULL) {
|
||||||
system(cmd);
|
sprintf(cmd, "%s %s %s", scp_cmd, input_path, output_path);
|
||||||
|
} else {
|
||||||
|
free_ressource();
|
||||||
|
exit(ENOMEM);
|
||||||
|
}
|
||||||
|
ret = system(cmd);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("%s not found. please ensure the device is correctly connected\n",
|
printf("%s not found. please ensure the device is correctly connected\n",
|
||||||
output_dev);
|
output_dev);
|
||||||
ret = -1;
|
ret = ENODEV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -87,6 +151,6 @@ int main(int argc, char *argv[])
|
||||||
printf("Missing argument\n");
|
printf("Missing argument\n");
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
}
|
}
|
||||||
|
free_ressource();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,39 @@
|
||||||
@ECHO off
|
@ECHO off
|
||||||
SET SOURCE=%2
|
|
||||||
SET SRC_PARSE=%SOURCE:/=\%
|
REM Exit codes for xcopy
|
||||||
SET TARGET=%4
|
REM code | Description
|
||||||
setlocal enabledelayedexpansion
|
REM 0 | Files were copied without error.
|
||||||
for /F "skip=1 tokens=*" %%a in ('WMIC LOGICALDISK where "volumename like '%TARGET%%%'" get deviceid') do if not defined id set id=%%a
|
REM 1 | No files were found to copy.
|
||||||
Call Set "deviceid=%%id: =%%"
|
REM 2 | The user pressed CTRL+C to terminate xcopy.
|
||||||
if not "%deviceid%" == "" (XCOPY %SRC_PARSE% %deviceid% /Y /Q >NUL
|
REM 4 | Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
|
||||||
echo Upload complete ) else ( echo %TARGET% not found. Please ensure the device is correctly connected)
|
REM 5 | Disk write error occurred.
|
||||||
|
|
||||||
|
SET SOURCE=%2
|
||||||
|
SET SRC_PARSE=%SOURCE:/=\%
|
||||||
|
SET TARGET=%4
|
||||||
|
SET TARGET=%TARGET:\=%
|
||||||
|
|
||||||
|
call :parse %TARGET%
|
||||||
|
echo %TARGET% not found. Please ensure the device is correctly connected.
|
||||||
|
exit 7
|
||||||
|
|
||||||
|
:parse
|
||||||
|
set list=%1
|
||||||
|
set list=%list:"=%
|
||||||
|
|
||||||
|
for /f "tokens=1* delims=," %%a in ("%list%") DO (
|
||||||
|
if not "%%a" == "" call :sub %%a
|
||||||
|
if not "%%b" == "" call :parse "%%b"
|
||||||
|
)
|
||||||
|
goto :eof
|
||||||
|
|
||||||
|
|
||||||
|
:sub
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
for /F "skip=1 tokens=*" %%a in ('WMIC LOGICALDISK where "volumename like '%~1'" get deviceid 2^>NUL') do if not defined id set id=%%a
|
||||||
|
call Set "deviceid=%%id: =%%"
|
||||||
|
if not "%deviceid%" == "" (
|
||||||
|
XCOPY %SRC_PARSE% %deviceid% /Y /Q
|
||||||
|
if !errorlevel! == 0 (echo Upload complete on %1 ^(%deviceid%^))
|
||||||
|
exit !errorlevel!)
|
||||||
|
goto :eof
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue