Skip to content

Commit

Permalink
Rename nucleoFlasher to massStorageCopy
Browse files Browse the repository at this point in the history
Harden massStorageCopy to avoid issue.
Create a linux 32 bits version.

Signed-off-by: Frederic.Pillon <[email protected]>
  • Loading branch information
fpistm committed May 10, 2017
1 parent 4963647 commit 1ba6db2
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 278 deletions.
Binary file added linux/massStorageCopy
Binary file not shown.
Binary file removed linux/nucleoFlasher/nucleoFlasher
Binary file not shown.
69 changes: 0 additions & 69 deletions linux/nucleoFlasher/nucleoFlasher.c

This file was deleted.

Binary file added linux64/massStorageCopy
Binary file not shown.
Binary file removed linux64/nucleoFlasher/nucleoFlasher
Binary file not shown.
69 changes: 0 additions & 69 deletions linux64/nucleoFlasher/nucleoFlasher.c

This file was deleted.

File renamed without changes.
Binary file removed nucleoFlasher/nucleoFlasher
Binary file not shown.
69 changes: 0 additions & 69 deletions nucleoFlasher/nucleoFlasher.c

This file was deleted.

Binary file removed nucleoFlasher/nucleoFlasherMacOsX
Binary file not shown.
69 changes: 0 additions & 69 deletions nucleoFlasher/nucleoFlasherMacOsX.c

This file was deleted.

22 changes: 22 additions & 0 deletions src/massStorageCopy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
all: massStorageCopy32 massStorageCopy


massStorageCopy32: massStorageCopy32.o
gcc -m32 -o $@ $<

massStorageCopy32.o: massStorageCopy.c
gcc -m32 -c $<
mv massStorageCopy.o massStorageCopy32.o

massStorageCopy: massStorageCopy.o
gcc -o $@ $<

massStorageCopy.o: massStorageCopy.c
gcc -c $<

clean:
rm -f *.o massStorageCopy massStorageCopy32

install:
mv massStorageCopy ../../linux64/
mv massStorageCopy32 ../../linux/massStorageCopy
File renamed without changes.
92 changes: 92 additions & 0 deletions src/massStorageCopy/massStorageCopy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <mntent.h>
#include <unistd.h>

void usage(char *name)
{
printf("Usage: %s [-I <filepath>] [-O <mountpoint> ]\n\n", name);
printf("Mandatory options:\n");
printf("\t-I: filepath binary to copy\n");
printf("\t-O: mountpoint destination name\n");
}

int main(int argc, char *argv[])
{
int c, 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 = NULL;
FILE *aFile = NULL;

opterr = 0;

while ((c = getopt (argc, argv, "I:O:")) != -1)
switch (c)
{
case 'I':
strcpy(input_path, optarg);
break;
case 'O':
strcpy(output_dev, optarg);
break;
case '?':
if ((optopt == 'I') || (optopt == 'O'))
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
usage(argv[0]);
return 1;
default:
abort ();
}

if (strlen(input_path) && strlen(output_dev))
{
//get the 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;
}
}
else
{
printf("Missing argument\n");
usage(argv[0]);
}

return ret;
}
File renamed without changes.
Loading

0 comments on commit 1ba6db2

Please sign in to comment.