summaryrefslogtreecommitdiff
path: root/scripts/dfuboot.sh
blob: 9847579ced4ca5821d1b68e600f8277c4cfcfead (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
#!/usr/bin/env bash

DEVICETREE=
KERNEL=
CMDLINE=

usage() {
	echo "usage: $0 [OPTIONS]"
	echo "This script uploads a kernel and optionally a devicetree"
	echo "and a kernel commandline to barebox via DFU running the"
	echo "'boot dfu' command."
	echo "OPTIONS:"
	echo "  -k <kernel>       kernelimage to upload"
	echo "  -d <dtb>          devicetree binary blob to upload"
	echo "  -c \"cmdline\"      kernel commandline"
	echo "  -h                This help text"

	exit 0
}

while getopts "k:d:c:h" opt
do
	case "$opt" in
	h)
		usage
		;;
	d)
		DEVICETREE="$OPTARG"
		;;
	k)
		KERNEL="$OPTARG"
		;;
	c)
		CMDLINE="$OPTARG"
		;;
	esac
done

dfu-util -D "${KERNEL}" -a kernel
if [ $? != 0 ]; then
	echo "Failed to upload kernel"
	exit 1
fi

if [ -n "$DEVICETREE" ]; then
	dfu-util -D "${DEVICETREE}" -a dtb
	if [ $? != 0 ]; then
		echo "Failed to upload devicetree"
		exit 1
	fi
fi

if [ -n "$CMDLINE" ]; then
	cmdlinefile=$(mktemp)

	echo -e "$CMDLINE" > "${cmdlinefile}"

	dfu-util -D "${cmdlinefile}" -a cmdline -R
	result=$?

	rm -f "${cmdlinefile}"

	if [ $result != 0 ]; then
		echo "Failed to upload cmdline"
		exit 1
	fi

fi