aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/edison/eca-postBuild.sh
blob: e4af1623caf62165d934cd59feb3b43c8ac11d5c (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash

# You need uboot-tools package in Fedora to run this script.

# You should run this script from
#   build-edison/tmp-glibc/deploy/images/edison
# directory.

top_repo_dir=$(dirname $(dirname $(dirname $(readlink -f $0))))

if [ -z "$1" ]; then
    echo "Usage: $0 <edison-src-directory-path>"
    exit 1
fi

EDISON_SRC="$1"
FLASH_DIR="$EDISON_SRC/device-software/utils/flash"

if [ ! -d "$FLASH_DIR" ]; then
    echo "Flash directory $FLASH_DIR not found."
    exit 1
fi

if [ ! -f README_-_DO_NOT_DELETE_FILES_IN_THIS_DIRECTORY.txt ]; then
    echo "Please go to build-edison/tmp-*glibc/deploy/images/edison directory and run this script from there."
    exit 1
fi

if [ ! -f eca-image-edison.ext4 ]; then
    echo "ECA image for Edison not found, please build it first."
    exit 2
fi

if [ ! -x `which mkimage` ]; then
    echo "mkimage binary from uboot-tools package is not found. Please install it."
    exit 3
fi

if [ ! -d toFlash ]; then
    mkdir toFlash
fi

function copy()
{
    FILE=$1
    if [ ! -f $FILE -a ! -d $FILE ]; then
	echo "$FILE not found."
	exit 1
    fi

    if [ -f $FILE ]; then
	cp -p $FILE toFlash/
    else
	cp -pR $FILE toFlash/
    fi
    if [ $? -ne 0 ]; then
	echo "Copy $FILE -> toFlash/ failed."
    fi
}

# Cleanup previous builds
rm -rf toFlash/*

# Some binary files from edison-src directory
copy $FLASH_DIR/filter-dfu-out.js
copy $FLASH_DIR/ota_update.cmd
for f in $FLASH_DIR/*.xml
do
    copy $f
done

# Copy IFWI
for i in $FLASH_DIR/ifwi/edison/*.bin
do
    copy $i
done

# Copy boot partition (contains kernel and ramdisk)
copy eca-image-edison.hddimg

# Copy u-boot
copy u-boot-edison.img
copy u-boot-edison.bin

# Copy u-boot environments files binary
copy u-boot-envs

# build Ifwi file for using in DFU mode
# Remove FUP footer (144 bytes) as it's not needed when we directly write to boot partitions
for ifwi in toFlash/*ifwi*.bin;
do
    dfu_ifwi_name="`basename $ifwi .bin`-dfu.bin"
    dd if=$ifwi of=toFlash/$dfu_ifwi_name bs=4194304 count=1
done

# Copy rootfs
copy eca-image-edison.ext4

# Copy flashing script
copy $top_repo_dir/scripts/edison/flashall

# Preprocess OTA script
# Compute sha1sum of each file under toFlash/ and build an array containing
# @@sha1_filename:SHA1VALUE
pth_out=toFlash/
tab_size=$(for fil in $(find $pth_out -maxdepth 1 -type f -printf "%f\n"); \
	   do sha1_hex=$(sha1sum "$pth_out$fil" | cut -c -40); \
	      echo "@@sha1_$fil:$sha1_hex" ; done ;)
# iterate the array and do tag -> value substitution in ota_update.cmd
for elem in $tab_size;
do IFS=':' read -a fld_elem <<< "$elem"; \
   sed -i "s/${fld_elem[0]}/${fld_elem[1]}/g" toFlash/ota_update.cmd; done;

# Convert OTA script to u-boot script
mkimage -a 0x10000 -T script -C none -n 'ECA updater script for Edison' \
	-d toFlash/ota_update.cmd toFlash/ota_update.scr

# Supress Preprocessed OTA script
rm -f toFlash/ota_update.cmd

# Generates a formatted list of all packages included in the image
awk '{print $1 " " $3}' eca-image-edison.manifest > toFlash/package-list.txt

echo "**** Done ***"
echo "Files ready to flash in toFlash/"
echo "Next do 'cd toFlash'"
echo "Then execute 'sudo ./flashall'"
echo "*************"