Skip to content

Commit

Permalink
Export px4 binaries to temp dir
Browse files Browse the repository at this point in the history
Removed old shell commands which were for the update with old
bootloader and didn't work anymore.

Added "tail -f /dev/null" to keep the container running in drone
so the px4 binaries are available when the update happens.
  • Loading branch information
TimoSairiala committed May 2, 2024
1 parent 053f925 commit 36077dc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tiiuae-pixhawk-and-saluki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
workflow_dispatch:
inputs:
jfrog-upload:
description: 'upload to Artifactory'
description: 'upload to UAE Artifactory'
required: false
default: false
type: boolean
Expand Down
23 changes: 5 additions & 18 deletions Tools/px_uploader.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,18 @@ FROM python:alpine3.14

ARG saluki_fpga_directory
ARG SALUKI_FILE_INFO_JSON=saluki_file_info.json

# run this with something like:
#
# $ docker run --rm -it --network=host --device=/dev/ttyS7:/dev/px4serial px4-fw-updater \
# --udp-addr=192.168.200.101 \
# --udp-port=14541 \
# --port=/dev/px4serial \
# --baud-bootloader=2000000 \
# px4_fmu-v5_ssrc.px4

# This gets built in environment with somewhat unorthodox paths:
# - The build context is at /
# - The repository itself is mounted in /px4-firmware/
# - Built firmware files are in /bin/
#
# ("/" above is relative to GH action runner home dir)
# (see .github/workflows/tiiuae-pixhawk.yaml)

ARG PX4_EXPORT_DIR
ENV PX4_EXPORT_DIR=$PX4_EXPORT_DIR

COPY $saluki_fpga_directory /firmware/fpga
COPY $SALUKI_FILE_INFO_JSON /$SALUKI_FILE_INFO_JSON
WORKDIR /firmware

ENTRYPOINT ["/entrypoint.sh"]

# tools needed to extract binaries from px4 files
RUN apk add pigz jq

# dependency of px_uploader.py
RUN pip3 install --user pyserial

Expand Down
50 changes: 42 additions & 8 deletions Tools/px_uploader.entrypoint
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
#!/bin/sh -e

aframe=""
if [ ! -z "$AIRFRAME" ]; then
aframe="--airframe ${AIRFRAME}"
fi
SALUKI_FILE_INFO="/saluki_file_info.json"

extract_bin_from_px4() {
local px4_file=$1
local target_dir=$2
local target=${target_dir}/$(basename ${px4_file%.px4}).bin

# check file exists
if [ ! -f $px4_file ]; then
echo "File $px4_file does not exist"
exit 1
fi

echo "Extracting $target from $px4_file"
# binary is stored in the 'image' field of the json file
# as base64 encoded and gzipped
cat ${px4_file} | jq -r '.image' | base64 -d | pigz -d > $target
validation_file=${target_dir}/$(basename ${px4_file%.px4})-validation.txt
generate_validation_file ${px4_file} ${validation_file}
}

function generate_validation_file() {
local px4_filename=${1}
local validation_file=${2}
echo "generating validation file for ${px4_filename} to ${validation_file}"

cat ${SALUKI_FILE_INFO} |jq -c '.files[] |select (.filename | contains("'${px4_filename}'"))' > ${validation_file}
}

# export px4 files if the container is started with the PX4_EXPORT_DIR
if [ -n "$PX4_EXPORT_DIR" ]; then
echo "Exporting PX4 files to $PX4_EXPORT_DIR"

# find all px4 files in the firmware directory
for px4_file in /firmware/*.px4; do
extract_bin_from_px4 $px4_file $PX4_EXPORT_DIR
done

mode=""
if [ ! -z "$FLIGHT_MODE" ]; then
mode="--flightmode ${FLIGHT_MODE}"
# copy saluki_file_info.json to the export directory
cp ${SALUKI_FILE_INFO} $PX4_EXPORT_DIR/saluki_file_info.json
fi

/bin/px_uploader.py --port=/dev/px4serial --udp-addr=192.168.200.101 --baud-flightstack=57600,115200,1000000,2000000 --baud-bootloader=2000000 px4_fmu-v5x_ssrc-*.px4 ssrc_saluki-v1_default-*.px4 ssrc_saluki-v2_default-*.px4
# keep the container running so px4 update can get the
# px4 firmware files from the container
# tail -f /dev/null

0 comments on commit 36077dc

Please sign in to comment.