diff options
author | Ilias Apalodimas <ilias.apalodimas@linaro.org> | 2020-01-31 12:22:44 +0200 |
---|---|---|
committer | Ilias Apalodimas <ilias.apalodimas@linaro.org> | 2020-01-31 12:22:44 +0200 |
commit | a737f620851312250894ee05b2de1f6da8cb560d (patch) | |
tree | 1306d1cfa074bd0ac62c487bd01b616819c43f13 /ledge_installer.sh |
Initial commit for ledge installer
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'ledge_installer.sh')
-rwxr-xr-x | ledge_installer.sh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/ledge_installer.sh b/ledge_installer.sh new file mode 100755 index 0000000..84f584d --- /dev/null +++ b/ledge_installer.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +wic=$1 +dev=$2 +board=$3 + +if [ $# -ne 3 ]; then + echo 'Provide wic image and the destination device' + exit 1 +fi + +loopdev='' +# mounts wic and returns loop device +mount_wic () { + local dev=$(sudo losetup --show -f -P "$wic") + echo "$dev" +} + +board_to_block () { + local board=$1 + case $board in + am572x) + echo "2 3" + ;; + *) + ;; + esac +} + +write_files () { + set -x + loopdev=$(mount_wic) + [ -z "$loopdev" ] && "Echo failed to mount WIC image" && exit 1 + + local esp="$loopdev"p1 + local rootfs="$loopdev"p2 + local esp_part=$(board_to_block "$board" | awk -F ' ' '{ print $1 }') + local rootfs_part=$(board_to_block "$board" | awk -F ' ' '{ print $2 }') + + esp_part="$dev""$esp_part" + rootfs_part="$dev""$rootfs_part" + + sudo dd if="$esp" of="$esp_part" bs=8M conv=fdatasync status=progress + [ $? -ne 0 ] && echo "Failed to write ESP partition" && exit 1 + sudo dd if="$rootfs" of="$rootfs_part" bs=8M conv=fdatasync status=progress + [ $? -ne 0 ] && echo "Failed to write rootfs partition" && exit 1 +} + +cleanup () { + sudo losetup -d "$loopdev" +} + +trap cleanup SIGHUP SIGINT SIGTERM + +write_files +cleanup |