-
Notifications
You must be signed in to change notification settings - Fork 1
/
updatehub-active-set
76 lines (63 loc) · 1.84 KB
/
updatehub-active-set
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
#!/bin/sh -e
BOOTCOUNT_ENV=1
SETENV_EXTRA_ARGS=""
active_set_prepare() {
:
}
active_set_finish() {
:
}
log() {
logger -t updatehub "updatehub-active-set: $@"
}
prepare_setenv_args() {
defenv=/tmp/updatehub.defenv
fw_env_config=/tmp/updatehub.fw_env_config
# Pass the configuration file coming from the update package.
if [ -e $fw_env_config ]; then
SETENV_EXTRA_ARGS="$SETENV_EXTRA_ARGS --config $fw_env_config"
log "using fw_env.config from the update package"
fi
# Pass the default environment coming from the update package.
if [ -e $defenv ]; then
if fw_setenv --help 2>&1 | grep -q '\-\-defenv'; then
SETENV_EXTRA_ARGS="$SETENV_EXTRA_ARGS --defenv $defenv --script $defenv"
log "using default environment from the update package"
else
log "could not use the default environment from the update \
package as fw_setenv does not support it"
exit 1
fi
fi
}
setenv() {
log "setting variable $1 to $2"
fw_setenv $SETENV_EXTRA_ARGS "$1" "$2"
log "variable $1 is now $2"
}
if [ -f /etc/default/updatehub-active ]; then
. /etc/default/updatehub-active
fi
active=$1
case "$active" in
0|1)
prepare_setenv_args
# By default, machines use the bootcount inside environment so
# we must set 'upgrade_available' to force U-Boot to count
# the boot attempts. We also need to set 'bootcount' to 0 to ensure
# a proper initialization.
if [ "$BOOTCOUNT_ENV" = "1" ]; then
active_set_prepare
setenv upgrade_available 1
setenv bootcount 0
active_set_finish
fi
active_set_prepare
setenv updatehub_active "$1"
active_set_finish
exit $?
;;
*)
exit 1
;;
esac