-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflash.sh
More file actions
executable file
·41 lines (40 loc) · 1.9 KB
/
flash.sh
File metadata and controls
executable file
·41 lines (40 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#Remember to chmod +x this file to make it executable:)
DEVICE=/dev/sdg #default for AMMDK
MNTPOINT=/mnt/AMMDK #default for AMMDK
#Check to see if path was supplied
if [ $# -eq 0 ]; then
echo "Please supply a path to the file you want to flash. Usage : ./flash.sh ./path-to-file.bin"
else
sudo mkdir -p $MNTPOINT #create a mount point, dont complain if it exists
if [ ! -e $DEVICE ]; then echo "Can't find device"; exit 1; fi # check if device exists
sudo umount $DEVICE #unmount the device [Linux automounts it :(]
sudo modprobe msdos #wake msdos module
sudo mount -t msdos $DEVICE $MNTPOINT # mount device with msdos type
INPUT="$1" #Argument - path to file (e.g ./amm-tiny.bin)
if [[ "$INPUT" == *".elf" ]]
then
echo "Found an .elf converting to .bin"
sudo objcopy -O binary "$INPUT" temp-converted-file.bin #convert elf to bin and and copy
echo "Copying bin to device"
sudo cp temp-converted-file.bin "$MNTPOINT"
echo "removing temporary bin file"
sudo rm temp-converted-file.bin
elif [[ "$INPUT" == *".bin" ]]
then
echo "Found a .bin copying to device"
sudo cp "$INPUT" "$MNTPOINT" #copy the bin
else
echo "Unknown Input File Type"
exit 1
fi
echo "Writing data to disk"
sync # write data buffered in memory to device
echo "Waiting 1 second"
sleep 1 # 1 second wait is necessary from testing
echo "Unmounting Device"
sudo umount $DEVICE # unmount
echo "Resetting the chip"
sudo openocd -f kinetis_daplink.cfg -c "init;reset;exit"
echo "Done!"
fi