-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathuniversal-silabs-flasher-up
executable file
·68 lines (58 loc) · 2.6 KB
/
universal-silabs-flasher-up
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/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Start universal-silabs-flasher if requested
# ==============================================================================
# shellcheck disable=SC2034
declare autoflash_firmware
declare device
declare firmware
declare usb_device_path
declare usb_manufacturer
declare usb_product
declare gpio_reset_flag
function exit_no_firmware {
bashio::log.warning "No firmware found for the selected device, assuming firmware is installed."
exit 0
}
device=$(bashio::config 'device')
if bashio::config.false 'autoflash_firmware'; then
bashio::log.info "Flashing firmware is disabled"
exit 0
fi
# Assume to run on Yellow if UART4 is mapped to ttyAMA1
if [ -d /sys/devices/platform/soc/fe201800.serial/tty/ttyAMA1 ] && [ "${device}" == "/dev/ttyAMA1" ]; then
bashio::log.info "Detected Home Assistant Yellow"
firmware="NabuCasa_Yellow_RCP_v4.3.1_rcp-uart-hw-802154_460800.gbl"
gpio_reset_flag="--yellow-gpio-reset"
else
# Check device manufacturer/product information
# shellcheck disable=SC2046,SC2086
usb_device_path=$(realpath /sys/class/tty/$(readlink /sys/class/tty/$(basename ${device}))/../../../../)
if [ ! -f "${usb_device_path}/idProduct" ]; then
bashio::log.info "The selected serial port is not a USB device."
exit_no_firmware
fi
if [ ! -f "${usb_device_path}/manufacturer" ] || [ ! -f "${usb_device_path}/product" ]; then
bashio::log.info "USB device is missing manufacturer or product name."
exit_no_firmware
fi
usb_manufacturer=$(cat "${usb_device_path}/manufacturer")
usb_product=$(cat "${usb_device_path}/product")
bashio::log.info "Checking ${device} identifying ${usb_product} from ${usb_manufacturer}."
if [[ "${usb_manufacturer}" == "Nabu Casa" && "${usb_product}" == "SkyConnect"* ]]; then
firmware="NabuCasa_SkyConnect_RCP_v4.3.1_rcp-uart-hw-802154_460800.gbl"
elif [[ "${usb_manufacturer}" == "Nabu Casa" && "${usb_product}" == "Home Assistant Connect ZBT-1"* ]]; then
firmware="NabuCasa_SkyConnect_RCP_v4.3.1_rcp-uart-hw-802154_460800.gbl"
else
exit_no_firmware
fi
gpio_reset_flag=""
fi
# All firmware we flash have a known baudrate of 460800, let cpcd know.
echo 460800 > /tmp/known-baudrate
bashio::log.info "Starting universal-silabs-flasher with ${device}"
# shellcheck disable=SC2086
exec universal-silabs-flasher --device ${device} \
flash ${gpio_reset_flag} --ensure-exact-version --allow-cross-flashing --firmware "/root/${firmware}"