-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp-sketch-data-upload.sh
executable file
·62 lines (54 loc) · 1.84 KB
/
esp-sketch-data-upload.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Variables and Options
DATA_FOLDER="./data"
IMAGE_FILE="./filesystem.bin"
BLOCK_SIZE=4096
PAGE_SIZE=256
FILESYSTEM_SIZE=0x100000
CHIP_PORT="/dev/ttyUSB0"
BAUD_RATE=115200
FLASH_ADDRESS=0x110000
FILESYSTEM_TYPE=${1:-littlefs} # Default to littlefs, can be overridden by first argument
CHIP=${2:-esp8266} # Default to esp8266, can be overridden by second argument
# Function to create filesystem image
create_filesystem_image() {
if [ "$FILESYSTEM_TYPE" == "littlefs" ]; then
if ! command -v mklittlefs &> /dev/null; then
echo "mklittlefs command not found. Please install it and try again."
exit 1
fi
mklittlefs -c "$DATA_FOLDER" -b "$BLOCK_SIZE" -p "$PAGE_SIZE" -s "$FILESYSTEM_SIZE" "$IMAGE_FILE"
elif [ "$FILESYSTEM_TYPE" == "spiffs" ]; then
if ! command -v mkspiffs &> /dev/null; then
echo "mkspiffs command not found. Please install it and try again."
exit 1
fi
mkspiffs -c "$DATA_FOLDER" -b "$BLOCK_SIZE" -p "$PAGE_SIZE" -s "$FILESYSTEM_SIZE" "$IMAGE_FILE"
else
echo "Unsupported filesystem type: $FILESYSTEM_TYPE"
exit 1
fi
}
# Function to upload filesystem image
upload_filesystem_image() {
if ! command -v esptool.py &> /dev/null; then
echo "esptool.py command not found. Please install it and try again."
exit 1
fi
esptool.py --chip "$CHIP" --port "$CHIP_PORT" --baud "$BAUD_RATE" write_flash -z "$FLASH_ADDRESS" "$IMAGE_FILE"
}
# Step 1: Generate filesystem image
create_filesystem_image
# Check if the filesystem image was created successfully
if [ ! -f "$IMAGE_FILE" ]; then
echo "Failed to create $FILESYSTEM_TYPE image"
exit 1
fi
# Step 2: Upload filesystem image
upload_filesystem_image
# Check if the upload was successful
if [ $? -ne 0 ]; then
echo "Failed to upload $FILESYSTEM_TYPE image"
exit 1
fi
echo "$FILESYSTEM_TYPE image successfully uploaded to $CHIP"