diff --git a/linux/nucleoFlasher/nucleoFlasher b/linux/nucleoFlasher/nucleoFlasher new file mode 100644 index 00000000..4117f94b Binary files /dev/null and b/linux/nucleoFlasher/nucleoFlasher differ diff --git a/linux/nucleoFlasher/nucleoFlasher.c b/linux/nucleoFlasher/nucleoFlasher.c new file mode 100644 index 00000000..da654186 --- /dev/null +++ b/linux/nucleoFlasher/nucleoFlasher.c @@ -0,0 +1,69 @@ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int i; + int ret = 0; + int device_found = 0; + char input_path[256]; + char output_dev[256]; + char output_path[256]; + char cmd[512]; + struct mntent *ent; + FILE *aFile; + + + for(i = 1; i < argc; i++) { + + if((strcmp(argv[i], "-I") == 0)&&(i+1 < argc)) { + strcpy(input_path, argv[i+1]); + i++; + } else if((strcmp(argv[i], "-O") == 0)&&(i+1 < argc)) { + strcpy(output_dev, argv[i+1]); + i++; + } else { + printf("unknown option %s\n", argv[i]); + ret = -1; + } + } + + if(ret == 0) { + + + //get thee mounted devives list + aFile = setmntent("/proc/mounts", "r"); + if (aFile == NULL) { + perror("setmntent"); + exit(1); + } + + //now lets read the path of the device + while (NULL != (ent = getmntent(aFile))) { + if (strstr(ent->mnt_dir, output_dev)) { + sprintf(output_path, "%s", ent->mnt_dir); + device_found = 1; + } + } + + endmntent(aFile); + + if(device_found) { + printf("copying %s to %s\n", input_path, output_path); + + sprintf(cmd, "scp %s %s", input_path, output_path); + system(cmd); + + } else { + printf("%s not found. please ensure the device is correctly connected\n", + output_dev); + ret = -1; + } + } + + + return ret; +} diff --git a/macos/nucleoFlasher/nucleoFlasherMacOsX b/macos/nucleoFlasher/nucleoFlasherMacOsX new file mode 100644 index 00000000..4fa3550f Binary files /dev/null and b/macos/nucleoFlasher/nucleoFlasherMacOsX differ diff --git a/macos/nucleoFlasher/nucleoFlasherMacOsX.c b/macos/nucleoFlasher/nucleoFlasherMacOsX.c new file mode 100644 index 00000000..6ba4f7ab --- /dev/null +++ b/macos/nucleoFlasher/nucleoFlasherMacOsX.c @@ -0,0 +1,69 @@ + +#include +#include +#include +#include + +#define MAX_FS 128 + +int main(int argc, char *argv[]) +{ + int i; + int ret = 0; + int device_found = 0; + char input_path[256]; + char output_dev[256]; + char output_path[256]; + char cmd[512]; + struct statfs buf[MAX_FS]; + int fs_count; + + if(argc < 4) { + printf("error: missing parameters\n"); + ret = -1; + } + + for(i = 1; i < argc; i++) { + + if((strcmp(argv[i], "-I") == 0)&&(i+1 < argc)) { + strcpy(input_path, argv[i+1]); + i++; + } else if((strcmp(argv[i], "-O") == 0)&&(i+1 < argc)) { + strcpy(output_dev, argv[i+1]); + i++; + } else { + printf("error: unknown option %s\n", argv[i]); + ret = -1; + } + } + + if(ret == 0) { + + fs_count = getfsstat(NULL,0,MNT_WAIT); + if(fs_count < 0) { + perror("getfsstat"); + exit(1); + } + + getfsstat(buf,fs_count*sizeof(buf[0]),MNT_WAIT); + + for(i = 0; i < fs_count; i++) { + if(strstr(buf[i].f_mntonname,output_dev)) { + sprintf(output_path, "%s", buf[i].f_mntonname); + device_found = 1; + } + } + + if(device_found) { + printf("copying %s to %s\n", input_path, output_path); + sprintf(cmd, "scp %s %s", input_path, output_path); + system(cmd); + } else { + printf("%s not found. please ensure the device is correctly connected\n", + output_dev); + ret = -1; + } + } + + return ret; +} diff --git a/win/nucleoFlasher/nucleoFlasher b/win/nucleoFlasher/nucleoFlasher new file mode 100644 index 00000000..4117f94b Binary files /dev/null and b/win/nucleoFlasher/nucleoFlasher differ diff --git a/win/nucleoFlasher/nucleoFlasher.bat b/win/nucleoFlasher/nucleoFlasher.bat new file mode 100644 index 00000000..6d0b1448 --- /dev/null +++ b/win/nucleoFlasher/nucleoFlasher.bat @@ -0,0 +1,16 @@ +@ECHO off + +SET SOURCE=%2 +SET SRC_PARSE=%SOURCE:/=\% +SET TARGET=%4 + +FOR %%I IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO ( + VOL %%I: 2>NUL | FIND "%TARGET%" >NUL && SET DEST=%%I: +) + +IF DEFINED DEST ( + XCOPY %SRC_PARSE% %DEST% /Y /Q >NUL +) ELSE ( + ECHO %TARGET% not found. Please ensure the device is correctly connected + EXIT /B 1 +) diff --git a/win/nucleoFlasher/nucleoFlasher.c b/win/nucleoFlasher/nucleoFlasher.c new file mode 100644 index 00000000..da654186 --- /dev/null +++ b/win/nucleoFlasher/nucleoFlasher.c @@ -0,0 +1,69 @@ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int i; + int ret = 0; + int device_found = 0; + char input_path[256]; + char output_dev[256]; + char output_path[256]; + char cmd[512]; + struct mntent *ent; + FILE *aFile; + + + for(i = 1; i < argc; i++) { + + if((strcmp(argv[i], "-I") == 0)&&(i+1 < argc)) { + strcpy(input_path, argv[i+1]); + i++; + } else if((strcmp(argv[i], "-O") == 0)&&(i+1 < argc)) { + strcpy(output_dev, argv[i+1]); + i++; + } else { + printf("unknown option %s\n", argv[i]); + ret = -1; + } + } + + if(ret == 0) { + + + //get thee mounted devives list + aFile = setmntent("/proc/mounts", "r"); + if (aFile == NULL) { + perror("setmntent"); + exit(1); + } + + //now lets read the path of the device + while (NULL != (ent = getmntent(aFile))) { + if (strstr(ent->mnt_dir, output_dev)) { + sprintf(output_path, "%s", ent->mnt_dir); + device_found = 1; + } + } + + endmntent(aFile); + + if(device_found) { + printf("copying %s to %s\n", input_path, output_path); + + sprintf(cmd, "scp %s %s", input_path, output_path); + system(cmd); + + } else { + printf("%s not found. please ensure the device is correctly connected\n", + output_dev); + ret = -1; + } + } + + + return ret; +} diff --git a/win/nucleoFlasher/nucleoFlasherMacOsX b/win/nucleoFlasher/nucleoFlasherMacOsX new file mode 100644 index 00000000..4fa3550f Binary files /dev/null and b/win/nucleoFlasher/nucleoFlasherMacOsX differ diff --git a/win/nucleoFlasher/nucleoFlasherMacOsX.c b/win/nucleoFlasher/nucleoFlasherMacOsX.c new file mode 100644 index 00000000..6ba4f7ab --- /dev/null +++ b/win/nucleoFlasher/nucleoFlasherMacOsX.c @@ -0,0 +1,69 @@ + +#include +#include +#include +#include + +#define MAX_FS 128 + +int main(int argc, char *argv[]) +{ + int i; + int ret = 0; + int device_found = 0; + char input_path[256]; + char output_dev[256]; + char output_path[256]; + char cmd[512]; + struct statfs buf[MAX_FS]; + int fs_count; + + if(argc < 4) { + printf("error: missing parameters\n"); + ret = -1; + } + + for(i = 1; i < argc; i++) { + + if((strcmp(argv[i], "-I") == 0)&&(i+1 < argc)) { + strcpy(input_path, argv[i+1]); + i++; + } else if((strcmp(argv[i], "-O") == 0)&&(i+1 < argc)) { + strcpy(output_dev, argv[i+1]); + i++; + } else { + printf("error: unknown option %s\n", argv[i]); + ret = -1; + } + } + + if(ret == 0) { + + fs_count = getfsstat(NULL,0,MNT_WAIT); + if(fs_count < 0) { + perror("getfsstat"); + exit(1); + } + + getfsstat(buf,fs_count*sizeof(buf[0]),MNT_WAIT); + + for(i = 0; i < fs_count; i++) { + if(strstr(buf[i].f_mntonname,output_dev)) { + sprintf(output_path, "%s", buf[i].f_mntonname); + device_found = 1; + } + } + + if(device_found) { + printf("copying %s to %s\n", input_path, output_path); + sprintf(cmd, "scp %s %s", input_path, output_path); + system(cmd); + } else { + printf("%s not found. please ensure the device is correctly connected\n", + output_dev); + ret = -1; + } + } + + return ret; +}