Skip to content

Commit

Permalink
Merge pull request #346 from SumolX/online_update_pr
Browse files Browse the repository at this point in the history
Online Firmware Downloader (Goggle & VTX)
  • Loading branch information
ligenxxxx authored Nov 14, 2023
2 parents 6233610 + 20950e3 commit 9cc8535
Show file tree
Hide file tree
Showing 40 changed files with 1,079 additions and 242 deletions.
Binary file added mkapp/app/resource/OSD/GOGGLE/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions mkapp/app/script/online_downloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/sh

version_gt() { test "$(echo "$@" | tr " " "\n" | sort -g | head -n 1)" != "$1"; }
version_le() { test "$(echo "$@" | tr " " "\n" | sort -g | head -n 1)" == "$1"; }
version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rg | head -n 1)" != "$1"; }
version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rg | head -n 1)" == "$1"; }

download() {
dst_path="$1"
fw_links="$2"
fw_sizes="$3"
fw_notes="$4"
fw_total=1
fw_counter=1

# Do we have a SD Card mounted?
if [ ! -z "$(mount | grep /mnt/extsd)" ]; then
dst_path="/mnt/extsd/FIRMWARE/$dst_path"
else
dst_path="/tmp/FIRMWARE/$dst_path"
fi

# Check if we need to download?
if test -f $dst_path/release.notes; then
echo "Local storage contains latest release!"
return 0
fi

# Blindly create directory, errors checking handled below.
mkdir -p $dst_path 2> /dev/null

# The real download work is performed here!
for link in $fw_links; do
file="$(basename "$link")"
target="$dst_path/$file"
if test -f "$target"; then
current_size=$(wc -c < "$target")
archive_size=$(echo $fw_sizes | cut -d" " -f$fw_counter)
if [ $current_size -ne $archive_size ]; then
echo "Resuming download: $target ...."
curl -s -k -C $current_size -L $link -o "$target" && \
fw_total=$((fw_total + 1)) && \
echo "Resuming download: $target DONE!"
else
fw_total=$((fw_total + 1))
fi
else
echo "Downloading firmware: $target ...."
curl -s -k -L $link -o "$target" && \
fw_total=$((fw_total + 1)) && \
echo "Downloading firmware: $target DONE!"
fi
fw_counter=$((fw_counter + 1))
done

# Having release notes identify a successful download.
if [ $fw_total -eq $fw_counter ]; then
printf "$fw_notes" | tr -d '\r' > $dst_path/release.notes && \
echo "Completed downloading latest release!"
fi
}

app_version_check() {
if version_gt $1 $2; then
echo "Goggle running older firmware!"
return 0
else
echo "Goggle running latest firmware!"
return 1
fi
}

online_goggle_fw_check() {
fw_info="/tmp/hdz_goggle_fw.latest"
echo "Checking Goggle Releases" && \
curl -ks -o $fw_info https://api.github.com/repos/hd-zero/hdzero-goggle/releases/latest && \
fw_link=$(cat $fw_info | grep 'browser_' | cut -d\" -f4) && \
fw_note=$(cat $fw_info | grep 'body' | cut -d\" -f4) && \
fw_size=$(cat $fw_info | grep 'size' | cut -d\" -f4) && \
fw_file=$(basename $fw_link) && \
rversion="$(echo ${fw_file%%.bin} | cut -d "-" -f4)" && \
lversion="$(cat /mnt/app/version | cut -d "-" -f1)" && \
app_version_check $rversion $lversion && \
echo "Searching local storage for latest release..." && \
download "GOGGLE/$rversion" "$fw_link" "$fw_size" "$fw_note"
}

online_vtx_fw_check() {
fw_info="/tmp/hdz_vtx_fw.latest"
echo "Checking VTX Releases" && \
curl -ks -o $fw_info https://api.github.com/repos/hd-zero/hdzero-vtx/releases/latest && \
fw_links=$(cat $fw_info | grep 'browser_' | cut -d\" -f4) && \
fw_notes=$(cat $fw_info | grep 'body' | cut -d\" -f4) && \
fw_sizes=$(cat $fw_info | grep 'size' | cut -d: -f2 | cut -d, -f1) && \
rversion=$(cat $fw_info | grep 'tag_name' | cut -d\" -f4) && \
echo "Searching local storage for latest release..." && \
download "VTX/$rversion" "$fw_links" "$fw_sizes" "$fw_notes"
}

online_goggle_fw_check
online_vtx_fw_check
59 changes: 31 additions & 28 deletions mkapp/app/script/update_goggle.sh
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
#!/bin/sh

GOGGLE_BIN="$1"
TMP_DIR=/tmp/goggle_update

function gpio_export()
gpio_export()
{
if [ ! -f /sys/class/gpio/gpio224/direction ]
then
echo "224">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio224/direction
fi


if [ ! -f /sys/class/gpio/gpio228/direction ]
then
echo "228">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio228/direction
echo "228">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio228/direction
fi

if [ ! -f /sys/class/gpio/gpio258/direction ]
then
echo "258">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio258/direction
fi
echo "258">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio258/direction
fi
}

function gpio_set_reset()
gpio_set_reset()
{
echo "0">/sys/class/gpio/gpio224/value
echo "1">/sys/class/gpio/gpio228/value
}

function gpio_clear_reset()
gpio_clear_reset()
{
echo "1">/sys/class/gpio/gpio224/value
echo "0">/sys/class/gpio/gpio228/value
}

function gpio_set_send()
gpio_set_send()
{
echo "1">/sys/class/gpio/gpio224/value
echo "0">/sys/class/gpio/gpio228/value
}


function disconnect_fpga_flash()
disconnect_fpga_flash()
{
echo "1">/sys/class/gpio/gpio258/value
}

function connect_fpga_flash()
connect_fpga_flash()
{
echo "0">/sys/class/gpio/gpio258/value
}


FILE_TARGET=/mnt/extsd/HDZERO_GOGGLE*.bin
TMP_DIR=/tmp/goggle_update

function untar_fils()
untar_file()
{
FILE_TARGET="$1"

if [ ! -e ${TMP_DIR} ]
then
mkdir ${TMP_DIR}
Expand All @@ -71,10 +69,8 @@ function untar_fils()
mv ${TMP_DIR}/HDZGOGGLE_VA*.bin ${TMP_DIR}/HDZGOGGLE_VA.bin
}


function update_rx()
update_rx()
{

echo "find RX update file, start update"
filesize=`ls -l ${TMP_DIR}/HDZGOGGLE_RX*.bin| awk '{print $5}'`
gpio_export
Expand All @@ -85,15 +81,14 @@ function update_rx()
mtd_debug write /dev/mtd8 0 $filesize ${TMP_DIR}/HDZGOGGLE_RX.bin
mtd_debug erase /dev/mtd9 0 65536
mtd_debug write /dev/mtd9 0 $filesize ${TMP_DIR}/HDZGOGGLE_RX.bin


echo "update finish RX, running"
gpio_clear_reset
sleep 1
rmmod /mnt/app/ko/w25q128.ko
}

function update_fpga()
update_fpga()
{
echo "find VA update file, start update"
filesize2=`ls -l ${TMP_DIR}/HDZGOGGLE_VA*.bin| awk '{print $5}'`
Expand All @@ -110,12 +105,20 @@ function update_fpga()
rmmod /mnt/app/ko/w25q128.ko
}

# If firmware file was NOT supplied then default to primary location for emergency restore
if [ -z "$GOGGLE_BIN" ]; then
if [ `ls /mnt/extsd/HDZERO_GOGGLE*.bin | grep bin | wc -l` -eq 1 ]
then
GOGGLE_BIN="/mnt/extsd/HDZERO_GOGGLE*.bin"
fi
fi

if [ `ls /mnt/extsd/HDZERO_GOGGLE*.bin |grep bin |wc -l` == "1" ]
if [ ! -z "$GOGGLE_BIN" ]
then
echo "Flashing $GOGGLE_BIN"
echo "0" > /tmp/progress_goggle
echo "0"
untar_fils
untar_file "$GOGGLE_BIN"
mv ${TMP_DIR}/hdzgoggle_app_ota*.tar ${TMP_DIR}/hdzgoggle_app_ota.tar
cp -f /mnt/app/setting.ini /mnt/UDISK/
#disable it66021
Expand All @@ -130,12 +133,12 @@ then
echo "100"
echo "100" > /tmp/progress_goggle
echo "all done"

else
if [ `ls /mnt/extsd/HDZERO_GOGGLE*.bin |grep bin |wc -l` == "0" ]
if [ `ls /mnt/extsd/HDZERO_GOGGLE*.bin | grep bin | wc -l` -eq 0 ]
then
echo "skip"
echo "skip"
else
echo "repeat"
fi
fi

53 changes: 33 additions & 20 deletions mkapp/app/script/update_vtx.sh
Original file line number Diff line number Diff line change
@@ -1,59 +1,72 @@
#!/bin/sh

function gpio_export()
VTX_BIN="$1"

gpio_export()
{
if [ ! -f /sys/class/gpio/gpio224/direction ]
then
echo "224">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio224/direction
fi


if [ ! -f /sys/class/gpio/gpio228/direction ]
then
echo "228">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio228/direction
fi
}

function gpio_set_reset()
gpio_set_reset()
{
echo "0">/sys/class/gpio/gpio224/value
echo "1">/sys/class/gpio/gpio228/value
}

function gpio_clear_reset()
gpio_clear_reset()
{
echo "1">/sys/class/gpio/gpio224/value
echo "0">/sys/class/gpio/gpio228/value
}

function gpio_set_send()
gpio_set_send()
{
echo "1">/sys/class/gpio/gpio224/value
echo "0">/sys/class/gpio/gpio228/value
}

if [ -e /mnt/extsd/HDZERO_TX.bin ]
then
gpio_export
gpio_set_send
# If firmware file was NOT supplied then default to primary location for emergency restore
if [ -z "$VTX_BIN" ]; then
if [ `ls /mnt/extsd/HDZERO_TX.bin | grep bin | wc -l` -eq 1 ]
then
VTX_BIN="/mnt/extsd/HDZERO_TX.bin"
fi
fi

if [ -e $VTX_BIN ]
then
echo "Flashing $VTX_BIN"
gpio_export
gpio_set_send
insmod /mnt/app/ko/w25q128.ko
valude=`mtd_debug info /dev/mtd8 | grep mtd.size | grep 1M`
if [ "$valude" != "" ];then
filesize=`ls -l /mnt/extsd/HDZERO_TX.bin| awk '{print $5}'`
value=`mtd_debug info /dev/mtd8 | grep mtd.size | grep 1M`

if [ ! -z "$value" ]
then
filesize=`ls -l $VTX_BIN | awk '{print $5}'`
mtd_debug erase /dev/mtd8 0 65536 > /dev/null
cp /mnt/extsd/HDZERO_TX.bin /tmp/.
mtd_debug write /dev/mtd8 0 $filesize /mnt/extsd/HDZERO_TX.bin > /dev/null
mtd_debug read /dev/mtd8 0 $filesize /tmp/HDZERO_TX_RB.bin > /dev/null
cp $VTX_BIN /tmp/
mtd_debug write /dev/mtd8 0 $filesize $VTX_BIN > /dev/null
mtd_debug read /dev/mtd8 0 $filesize /tmp/HDZERO_TX_RB.bin > /dev/null
echo "all done"
else
echo "detect device failed"
fi
gpio_clear_reset
fi

gpio_clear_reset
sleep 1
rmmod w25q128.ko
rmmod w25q128.ko
else
echo "skip"
fi
echo "skip"
fi

Binary file added mkapp/app/services/bearssl/lib/libbearssl.so
Binary file not shown.
3 changes: 3 additions & 0 deletions mkapp/app/services/scripts/30_bearssl_startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

ln -sfn /mnt/app/services/bearssl/lib/libbearssl.so /lib/libbearssl.so
3 changes: 3 additions & 0 deletions mkapp/app/services/scripts/50_tinycurl_startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

ln -sfn /mnt/app/services/tinycurl/curl /bin/curl
Binary file added mkapp/app/services/tinycurl/curl
Binary file not shown.
8 changes: 4 additions & 4 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "core/sleep_mode.h"
#include "core/thread.h"
#include "driver/TP2825.h"
#include "driver/beep.h"
#include "driver/dm5680.h"
#include "driver/esp32.h"
#include "driver/fans.h"
Expand All @@ -34,7 +35,6 @@
#include "driver/mcp3021.h"
#include "driver/oled.h"
#include "driver/rtc.h"
#include "driver/beep.h"
#include "ui/page_power.h"
#include "ui/page_scannow.h"
#include "ui/page_source.h"
Expand All @@ -44,7 +44,6 @@
#include "ui/ui_osd_element_pos.h"
#include "ui/ui_porting.h"
#include "ui/ui_statusbar.h"
#include "util/file.h"

int gif_cnt = 0;

Expand Down Expand Up @@ -188,14 +187,15 @@ int main(int argc, char *argv[]) {

// 8. Synthetic counter for gif refresh
gif_cnt = 0;

// 8.1 set initial analog module power state
Analog_Module_Power(0);

// 10. Execute main loop
g_init_done = 1;
for (;;) {
pthread_mutex_lock(&lvgl_mutex);
main_menu_update();
sleep_reminder();
statubar_update();
osd_hdzero_update();
Expand Down
Loading

0 comments on commit 9cc8535

Please sign in to comment.