Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlong13 authored and loki077 committed Nov 27, 2024
1 parent 08e1b51 commit 5e19531
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 89 deletions.
48 changes: 26 additions & 22 deletions .github/workflows/carbonix_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ jobs:
source ~/ccache.conf &&
Tools/scripts/cygwin_build.sh &&
ccache -s
mkdir -p output/sitl
cp -r artifacts output/sitl
- name: Check build files
id: check_files
Expand All @@ -213,7 +215,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: sitl
path: artifacts
path: output
retention-days: 90

build-apj:
Expand All @@ -222,6 +224,16 @@ jobs:
strategy:
fail-fast: false # don't cancel if a job from the matrix fails
matrix:
config: [
CubeOrange,
CubeOrange-Volanti,
CubeOrange-Ottano,
CubeOrangePlus,
CubeOrangePlus-Volanti,
CubeOrangePlus-Ottano,
CarbonixF405,
CarbonixF405-no-crystal,
]
toolchain: [
chibios,
#chibios-clang,
Expand All @@ -246,8 +258,8 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.ccache
key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{ matrix.gcc }}-${{steps.ccache_cache_timestamp.outputs.timestamp}}
restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{ matrix.gcc }} # restore ccache from either previous build on this branch or on master
key: ${{github.workflow}}-ccache-${{matrix.config}}-${{ matrix.toolchain }}-${{ matrix.gcc }}-${{steps.ccache_cache_timestamp.outputs.timestamp}}
restore-keys: ${{github.workflow}}-ccache-${{matrix.config}}-${{ matrix.toolchain }}-${{ matrix.gcc }} # restore ccache from either previous build on this branch or on master
- name: setup ccache
run: |
. .github/workflows/ccache.env
Expand All @@ -257,7 +269,7 @@ jobs:
sudo apt-get update
sudo apt-get -y install xxd
- name: build
- name: build ${{matrix.config}} ${{ matrix.toolchain }} gcc-${{matrix.gcc}}
shell: bash
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
Expand All @@ -267,28 +279,27 @@ jobs:
fi
PATH="/usr/lib/ccache:/opt/gcc-arm-none-eabi-${{matrix.gcc}}/bin:$PATH"
PATH="/github/home/.local/bin:$PATH"
Tools/Carbonix_scripts/carbonix_waf_build.sh
Tools/Carbonix_scripts/carbonix_waf_build.sh ${{ matrix.config }}
ccache -s
ccache -z
- name: Check build files
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "build/CubeOrange/*, build/CubeOrangePlus/*, build/CubeOrange-Volanti/*, build/CubeOrangePlus-Volanti/*, build/CubeOrange-Ottano/*, build/CubeOrangePlus-Ottano/*, build/CarbonixF405/*, build/CarbonixF405-no-crystal/*"
files: "build/${{ matrix.config }}/*"
fail: true
- name: Gather build output
run: |
mkdir -p temp/others
for dir in CubeOrange CubeOrangePlus CubeOrange-Volanti CubeOrangePlus-Volanti CubeOrange-Ottano CubeOrangePlus-Ottano CarbonixF405 CarbonixF405-no-crystal; do
mkdir -p temp/others/$dir/bin
cp -vr build/$dir/bin/* temp/others/$dir/bin/
mkdir -p temp/boards
mkdir -p temp/boards/${{ matrix.config }}/bin
cp -vr build/${{ matrix.config }}/bin/* temp/boards/$dir/bin/
done
cp -vr output/* temp/
mv temp/others/CubeOrange-Volanti temp/Volanti
mv temp/others/CubeOrangePlus-Volanti temp/Volanti
mv temp/others/CubeOrange-Ottano temp/Ottano
mv temp/others/CubeOrangePlus-Ottano temp/Ottano
mv temp/boards/CubeOrange-Volanti temp/Volanti
mv temp/boards/CubeOrangePlus-Volanti temp/Volanti
mv temp/boards/CubeOrange-Ottano temp/Ottano
mv temp/boards/CubeOrangePlus-Ottano temp/Ottano
if [ -d "ArduPlane/ReleaseNotes.txt" ]; then
cp -v ArduPlane/ReleaseNotes.txt temp/
else
Expand Down Expand Up @@ -325,18 +336,11 @@ jobs:
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
shell: sh -e {0}

- name: Download APJ build
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: apj
path: temp

- name: Download SITL build
uses: actions/download-artifact@v4
with:
name: sitl
path: temp/sitl

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
140 changes: 73 additions & 67 deletions Tools/Carbonix_scripts/carbonix_waf_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,94 @@ echo "Running distclean..."
./waf distclean
rm -Rf output

main_boards=("CubeOrange" "CubeOrangePlus" "CubeOrange-Volanti" "CubeOrangePlus-Volanti" "CubeOrange-Ottano" "CubeOrangePlus-Ottano")
for board in "${main_boards[@]}"; do
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <board_name>"
exit 1
fi

# Set the board name
board=$1

is_periph_board= ./waf configure --board "$board" -g | tee >(grep -c "env set AP_PERIPH=1")

if [ $is_periph_board -eq 0 ]; then
echo "Compiling ArduPlane for $board..."
./waf configure --board "$board" -g
./waf plane
done
echo "Script finished successfully."
exit 0
fi

periph_boards=("CarbonixF405" "CarbonixF405-no-crystal")
# For periph boards, we take the extra step of generating a modified binary
# for each CPN param file in the AP_HAL_ChibiOS/hwdef/CarbonixCommon/cpn_params
# folder. This modified binary will have the CPN parameters embedded in it, and
# the board name set to the board name followed by the CPN parameter file name.

# Create a magic string as a placeholder for the board name, this will be
# find/replaced within the AP_Periph binary. This makes the build much faster,
# as changing CAN_APP_NODE_NAME causes pretty-much a full rebuild.
board_magic_string="lm3eBX7cJeaUer67lXdkNr83q2WzPRbE2MxAgnGq9esBjPVecYynx9Pry5sRJMgCX8384NTYZRDpuR8K"

# We use a subset of that magic string, because we don't want to waste the full
# 80 bytes (max length allowed in the NodeStatus message) on the board name.
# We use 40 bytes, which is slightly more than the longest board name:
# "CarbonixF405-no-crystal-Volanti-LWing" (at time of writing).
# If we ever need more than 40 bytes, we can increase this limit.
# We build a version of AP_Periph with a long random string as the board name.
# This random string is replaced with the actual board name in the final binary.
# The random string is chosen to be long enough to accommodate the longest board
# name that we expect to use. Currently, we use 40, which is a little larger
# than the longest board name we have used so far:
# "CarbonixF405-no-crystal-Volanti-LWing". (and error is thrown if the board
# name is too long, so we can adjust this if we ever need a longer name)
max_board_name_length=40
board_magic_string="lm3eBX7cJeaUer67lXdkNr83q2WzPRbE2MxAgnGq9esBjPVecYynx9Pry5sRJMgCX8384NTYZRDpuR8K"
if [ ${#board_magic_string} -lt $max_board_name_length ]; then
echo "max_board_name_length is too long (max ${#board_magic_string} bytes)"
exit 1
fi
board_magic_string=${board_magic_string:0:max_board_name_length}

# Create extra hwdef file
# Compile AP_Periph
echo "Compiling AP_Periph for $board..."
printf "undef CAN_APP_NODE_NAME\ndefine CAN_APP_NODE_NAME \"$board_magic_string\"" > temp.hwdef
./waf configure --board "$board" --extra-hwdef=temp.hwdef -g
./waf AP_Periph

# Build all periph board with custom parameters
for board in "${periph_boards[@]}"; do
echo "Compiling AP_Periph for $board..."
./waf configure --board "$board" --extra-hwdef=temp.hwdef
./waf AP_Periph
bin_folder=build/$board/bin
for file in $(find libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/cpn_params/ -name "*.parm"); do
echo "Processing parameter file $file for $board..."
# Extract the filename without the extension
filename=$(basename -- "$file")
filename="${filename%.*}"
# Extract the Parent folder name
foldername=$(basename -- "$(dirname -- "$file")")
# Loop through all CPN parameter files and generate modified binaries
bin_folder=build/$board/bin
for file in $(find libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/cpn_params/ -name "*.parm"); do
echo "Processing parameter file $file for $board..."
# Extract the filename without the extension
filename=$(basename -- "$file")
filename="${filename%.*}"
# Extract the Parent folder name
foldername=$(basename -- "$(dirname -- "$file")")

# Create output folder
output_folder=output/$foldername/${filename}_$board
mkdir -p $output_folder
# Copy param file in the output folder
cp $file $output_folder
# Create output folder
output_folder=output/$foldername/${filename}_$board
mkdir -p $output_folder
# Copy param file in the output folder
cp $file $output_folder

# The find/replace operation works by converting the binary to a single long
# line of hex, then uses sed to replace the magic string with the board name
# that has been padded with zeros to the same length as the magic string,
# then converts the hex back to binary.
new_board_name="$board-$filename"
if [ ${#new_board_name} -gt $max_board_name_length ]; then
echo "Board name '$new_board_name' is too long (max $max_board_name_length bytes)"
exit 1
fi
board_magic_string_hex=$(echo -n "$board_magic_string" | xxd -p | tr -d '\n')
board_name_hex=$(echo -n "$new_board_name" | xxd -p | tr -d '\n')
# Pad with zeros to the same length as the magic string
board_name_hex=$(printf "%-${#board_magic_string_hex}s" "$board_name_hex" | tr ' ' '0')
for binary in $bin_folder/AP_Periph $bin_folder/AP_Periph.bin; do
# Embed the parameters
echo "Embedding parameter file $filename into $binary..."
Tools/scripts/apj_tool.py $binary --set-file $file &> /dev/null
# The find/replace operation works by converting the binary to a single long
# line of hex, then uses sed to replace the magic string with the board name
# that has been padded with zeros to the same length as the magic string,
# then converts the hex back to binary.
new_board_name="$board-$filename"
if [ ${#new_board_name} -gt $max_board_name_length ]; then
echo "Board name '$new_board_name' is too long (max $max_board_name_length bytes)"
exit 1
fi
board_magic_string_hex=$(echo -n "$board_magic_string" | xxd -p | tr -d '\n')
board_name_hex=$(echo -n "$new_board_name" | xxd -p | tr -d '\n')
# Pad with zeros to the same length as the magic string
board_name_hex=$(printf "%-${#board_magic_string_hex}s" "$board_name_hex" | tr ' ' '0')

for binary in $bin_folder/AP_Periph $bin_folder/AP_Periph.bin; do
# Embed the parameters
echo "Embedding parameter file $filename into $binary..."
Tools/scripts/apj_tool.py $binary --set-file $file &> /dev/null

# Set the board name
echo "Setting board name to $new_board_name in $binary..."
cp $binary $binary.bak
xxd -p $binary.bak | tr -d '\n' | sed "s/$board_magic_string_hex/$board_name_hex/g" | xxd -r -p > $binary
cp $binary $output_folder
done
echo ""
# Set the board name
echo "Setting board name to $new_board_name in $binary..."
cp $binary $binary.tmp
xxd -p $binary | tr -d '\n' | sed "s/$board_magic_string_hex/$board_name_hex/g" | xxd -r -p > $binary.tmp
mv $binary.tmp $output_folder/$(basename $binary)
done
echo ""
done

# Cleanup
rm temp.hwdef

# Build all Default periph board
for board in "${periph_boards[@]}"; do
echo "Compiling AP_Periph for $board..."
./waf configure --board "$board" -g
./waf AP_Periph
done

echo "Script completed successfully."
echo "Script finished successfully."

0 comments on commit 5e19531

Please sign in to comment.