forked from mudita/MuditaOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheepromgen.sh
executable file
·54 lines (47 loc) · 1.25 KB
/
eepromgen.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
#!/bin/bash -e
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
usage() {
cat << ==usage
Usage: $(basename "$0") [image_path] [key=value...]
image_path: Destination image path name for. ex eeprom.img
key=value: pairs of key and value to put into json eeprom file
==usage
exit 1
}
if [ $# -lt 2 ]; then
echo "Error! Invalid argument count"
usage
exit 1
fi
NVROM_FS_SIZE=32768
NVROM_LFS_BLOCK_SIZE=128
FACTORY_FILENAME="personalization.json"
IMAGE_NAME=$(realpath "$1")
#Find genlittlefs tool
GENLFS=$(find $SDIR -type f -iname genlittlefs -executable -print -quit)
if [ -z ${GENLFS} ]; then
echo "Error: Unable to find genlilttlefs..."
exit 1
fi
#Process all arguments in form key=value and create json string from it
shift
JSON="{"
for ARGUMENT in "$@"
do
if [[ ${ARGUMENT} == *"="* ]]; then
key=${ARGUMENT%=*}
value=${ARGUMENT##*=}
JSON+="\"$key\":\"$value\""
JSON+=","
else
echo "Invalid argument: $ARGUMENT"
usage
fi
done
JSON=${JSON%?}
JSON+="}"
echo $JSON > "$FACTORY_FILENAME"
#Generate eeprom image
$GENLFS --image "$IMAGE_NAME" --block_size=$NVROM_LFS_BLOCK_SIZE --filesystem_size=$NVROM_FS_SIZE --overwrite -- $FACTORY_FILENAME
sync