Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/firmwares/*
/venv/
/boards.local.txt
/platform.local.txt

llext-edk/
cflags.txt
Expand Down
8 changes: 6 additions & 2 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,18 @@ portentac33.upload.interface=1
portentac33.upload.use_1200bps_touch=true
portentac33.upload.wait_for_upload_port=false
portentac33.upload.native_usb=true
portentac33.upload.dfuse=-Q -w
portentac33.upload.dfuse=-w

portentac33.bootloader.tool=dfu-util
portentac33.bootloader.tool.default=dfu-util
portentac33.bootloader.file=zephyr-{build.variant}.bin
portentac33.bootloader.interface=0
portentac33.bootloader.address=0x10000
portentac33.bootloader.dfuse=-Q
portentac33.bootloader.dfuse=

# the space before -Q is important
portentac33.empty=
portentac33.leave.dfuse={empty} -Q

##########################################################################################

Expand Down
5 changes: 3 additions & 2 deletions cores/arduino/usb_device_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <zephyr/usb/bos.h>

#include <zephyr/logging/log.h>
#include <zephyr/app_version.h>

#ifdef CONFIG_USB_DEVICE_STACK_NEXT

Expand All @@ -32,8 +33,8 @@ USBD_DESC_PRODUCT_DEFINE(sample_product, CONFIG_USB_DEVICE_PRODUCT);
USBD_DESC_SERIAL_NUMBER_DEFINE(sample_sn);
/* doc string instantiation end */

USBD_DESC_CONFIG_DEFINE(fs_cfg_desc, "FS Configuration");
USBD_DESC_CONFIG_DEFINE(hs_cfg_desc, "HS Configuration");
USBD_DESC_CONFIG_DEFINE(fs_cfg_desc, APP_VERSION_EXTENDED_STRING);
USBD_DESC_CONFIG_DEFINE(hs_cfg_desc, APP_VERSION_EXTENDED_STRING);

/* doc configuration instantiation start */
static const uint8_t attributes = 0;
Expand Down
54 changes: 36 additions & 18 deletions extra/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ else
fi
fi

# Save the build version to loader/VERSION and for later use in local files
build_version=$(extra/get_core_version.sh loader/VERSION)

echo
echo "Build version: $build_version"
echo "Build target: $target $args"

# Get the variant name (NORMALIZED_BOARD_TARGET in Zephyr)
Expand Down Expand Up @@ -138,40 +142,54 @@ update_local_field() {
local field=$1
local value="$2"
local comment="$3"
local full_field_name="${board}.${field}"

if [ -z "$board" ]; then
local file="platform.local.txt"
local full_field_name="${field}"
else
local file="boards.local.txt"
local full_field_name="${board}.${field}"
fi
local match_regexp="${full_field_name//./\\.}" # escape dots

if [ ! -f $file ] ; then
cat << EOF > $file
#########################################################################################
#
# AUTO GENERATED FILE - DO NOT EDIT
# This file is manipulated by extra/build.sh; manual changes may be overwritten.
#
#########################################################################################

EOF
fi

if [ -n "$comment" ]; then
# if there's a comment, add/update it as a commented-out line above the actual field
if grep -qE "^# ${match_regexp}:" boards.local.txt; then
sed -i -e "s/^# ${match_regexp}:.*/# ${full_field_name}: ${comment}/" boards.local.txt
if grep -qE "^# ${match_regexp}:" $file; then
sed -i -e "s/^# ${match_regexp}:.*/# ${full_field_name}: ${comment}/" $file
else
echo "# ${full_field_name}: ${comment}" >> boards.local.txt
echo "# ${full_field_name}: ${comment}" >> $file
fi
fi

# update the actual field line
if grep -qE "^${match_regexp}" boards.local.txt; then
sed -i -e "s/^${match_regexp}=.*/${full_field_name}=${value}/" boards.local.txt
if grep -qE "^${match_regexp}" $file; then
sed -i -e "s/^${match_regexp}=.*/${full_field_name}=${value}/" $file
else
echo "${full_field_name}=${value}" >> boards.local.txt
echo "${full_field_name}=${value}" >> $file
fi
}

# update properties on boards.local.txt from the generated files
if [ ! -z "$board" ]; then

if [ ! -f boards.local.txt ] ; then
cat << EOF > boards.local.txt
#########################################################################################
#
# AUTO GENERATED FILE - DO NOT EDIT
# This file is manipulated by extra/build.sh; manual changes may be overwritten.
#
#########################################################################################

EOF
fi
# save version to both platform.local.txt and boards.local.txt:
# - the platform one is reported by the IDE as _the_ core version;
# - the board-specific one is used by the auto-update-loader feature
# (when developing, each board build should be tracked separately).
board="" update_local_field "version" "$build_version"
update_local_field "version" "$build_version"

# sketch load address: start of sketch partition, hex (exact)
CODE_ADDR=$(get_value_from_text_file variants/${variant}/syms-static.ld '_sketch_start')
Expand Down
3 changes: 3 additions & 0 deletions extra/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ if [ ! -z "$GITHUB_STEP_SUMMARY" ] ; then
echo "### Variant build results:" >> "$GITHUB_STEP_SUMMARY"
fi

# This will force all boards to share the same build version
export PINNED_CORE_VERSION=$(extra/get_core_version.sh)

final_result=0
while read -r item; do
board=$(jq -cr '.board' <<< "$item")
Expand Down
4 changes: 2 additions & 2 deletions extra/get_board_details.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
set -e

get_boards() {
cat boards.txt | sed -e 's/\s*#.*//' | grep -E '^.*\.build\.variant=' | sed -e 's/\.build\.variant=.*//'
cat boards.txt | sed -e 's/\s*#.*//' | grep -E '^.*\.build\.variant=' | sed -e 's/\.build\.variant=.*//' -e 's/["\\]/\\&/g'
}

get_board_field() {
board=$1
field=$2
cat boards.txt | sed -e 's/\s*#.*//' | grep -E "^$board\\.$field=" | cut -d '=' -f2- | sed -e 's/"/\"/g'
cat boards.txt | sed -e 's/\s*#.*//' | grep -E "^$board\\.$field=" | cut -d '=' -f2- | sed -e 's/["\\]/\\&/g'
}

for BOARD in $(get_boards); do
Expand Down
104 changes: 78 additions & 26 deletions extra/get_core_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
# environments the correct commit is used, even in pull requests where HEAD
# might be a temporary detached commit.

# The computed version is also written to a file in the Zephyr-compatible
# VERSION format if a filename is provided as the first argument.

# Determine pre-release label based on build context
if [ -z "$GITHUB_ACTIONS" ]; then
# local build, highest precedence
Expand All @@ -66,36 +69,85 @@ else
exit 1
fi

VERSION=$(git describe --tags --exact-match --exclude '*/*' 2>/dev/null)
if [ -z "$VERSION" ]; then
DESCRIBE=$(git describe --tags --exclude '*/*' 2>/dev/null)
if [[ "$DESCRIBE" =~ ^([0-9]+\.[0-9]+\.)([0-9]+)(-.*)?-([0-9]+)-g ]]; then
maj_min="${BASH_REMATCH[1]}"
patch="${BASH_REMATCH[2]}"
prerel="${BASH_REMATCH[3]}" # optional
count="${BASH_REMATCH[4]}"
# echo "Git describe: maj_min='$maj_min' patch='$patch' prerel='$prerel' count='$count'" >&2
if [ "$KIND" == "tag" ] ; then
# number of commits since tag is irrelevant for a tag push
label="${KIND}.${NAME}"
if [ -n "$PINNED_CORE_VERSION" ] ; then
# If PINNED_CORE_VERSION is set, use it as the version (extract fields)
# must match <maj>.<min>.<patch>(-<prerel>)(+<buildinfo>)
pattern='^([0-9]+)\.([0-9]+)\.([0-9]+)(-[^+]*)?(\+.*)?'
if [[ $PINNED_CORE_VERSION =~ $pattern ]]; then
v_maj="${BASH_REMATCH[1]}"
v_min="${BASH_REMATCH[2]}"
v_patch="${BASH_REMATCH[3]}"
v_extra="${BASH_REMATCH[4]}" # optional, lead -
v_tweak="${BASH_REMATCH[5]}" # optional, lead +
else
echo "Error: unexpected pinned ver '$PINNED_CORE_VERSION'" >&2
exit 1
fi
else
exact_version=$(git describe --tags --exact-match --exclude '*/*' 2>/dev/null)
if [ -n "$exact_version" ] ; then
# this is a tagged build, extract the version components from the tag
# must match <maj>.<min>.<patch>(-<prerel>)
pattern='^([0-9]+)\.([0-9]+)\.([0-9]+)(-.*)?'
if [[ $exact_version =~ $pattern ]]; then
v_maj="${BASH_REMATCH[1]}"
v_min="${BASH_REMATCH[2]}"
v_patch="${BASH_REMATCH[3]}"
v_extra="${BASH_REMATCH[4]}" # optional, lead -
else
label="${KIND}.${NAME}.${count}"
echo "Error: unexpected tag '$exact_version'" >&2
exit 1
fi
if [ -z "$prerel" ]; then
STEM="${maj_min}$((patch+1))-0.${label}"

# no additional information
v_tweak=""
else
version_from_git=$(git describe --tags --long --exclude '*/*' 2>/dev/null)
# must match <maj>.<min>.<patch>(-<prerel>)-<number-of-commits-since-tag>-g<commit-hash>
pattern='^([0-9]+)\.([0-9]+)\.([0-9]+)(-.*)?-([0-9]+)-g.*'
if [[ $version_from_git =~ $pattern ]]; then
v_maj="${BASH_REMATCH[1]}"
v_min="${BASH_REMATCH[2]}"
v_patch="${BASH_REMATCH[3]}"
v_extra="${BASH_REMATCH[4]}" # optional, lead -
count="${BASH_REMATCH[5]}"
else
STEM="${maj_min}${patch}${prerel}.${label}"
echo "Error: unexpected git describe output '$version_from_git'" >&2
exit 1
fi
else
echo "Warning: unexpected git describe output '$DESCRIBE'" >&2
fi
if [ -z "$STEM" ]; then
# no tags: build in a fork or locally, use a maxed out version with date+hash
STEM="9.9.9-$(date '+%Y%m%d-%H%M%S')"
fi

# If HEAD_REF is not set, we're not in CI but in a local clone. Use the
# implicit HEAD and include --dirty to test for uncommitted changes.
VERSION="${STEM}+$(git describe --always ${HEAD_REF:---dirty})"
if [ -z "${v_extra}" ]; then
v_patch=$((v_patch+1))
v_extra="-0"
fi

if [ "$KIND" == "tag" ] ; then
# number of commits since tag is irrelevant for a tag push
v_extra="${v_extra}.${KIND}.${NAME}"
else
v_extra="${v_extra}.${KIND}.${NAME}.${count}"
fi

# If HEAD_REF is not set, we're not in CI but in a local clone. Use the
# implicit HEAD and include --dirty to test for uncommitted changes.
v_tweak="+$(git describe --always ${HEAD_REF:---dirty})"
fi
fi

VERSION="${v_maj}.${v_min}.${v_patch}${v_extra}${v_tweak}"
echo $VERSION

if [ -n "$1" ]; then
# Write the version components to a file in Zephyr-compatible format,
# removing leading separators from EXTRAVERSION and VERSION_TWEAK.
cat > $1 << EOF
# This file is auto-generated by get_core_version.sh. Do not edit.
# Generated from version string: ${VERSION}

VERSION_MAJOR = ${v_maj}
VERSION_MINOR = ${v_min}
PATCHLEVEL = ${v_patch}
EXTRAVERSION = ${v_extra#-}
VERSION_TWEAK = ${v_tweak#+}
EOF
fi
2 changes: 2 additions & 0 deletions extra/package_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ for board in $EXCLUDED_BOARDS ; do
# remove (even commented) lines for excluded boards
sed -i "/^\(\s*#\s*\)\?${board}\./d" $TEMP_BOARDS
done
# remove any per-board version lines
sed -i '/^\S*\.version=/d' $TEMP_BOARDS
# remove multiple empty lines
sed -i '/^$/N;/^\n$/D' $TEMP_BOARDS

Expand Down
3 changes: 3 additions & 0 deletions loader/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
config PINCTRL
select PINCTRL_NON_STATIC

config USB_CONFIGURATION_STRING_DESC
default "$(APP_VERSION_EXTENDED_STRING)"

source "Kconfig.zephyr"

config LLEXT_HEAP_REGION
Expand Down
Binary file modified loader/blobs/c33_bl.bin
Binary file not shown.
8 changes: 8 additions & 0 deletions loader/fixups.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <cmsis_core.h>
#include <zephyr/init.h>
#include <zephyr/drivers/led.h>

#ifndef CONFIG_CPP
void __cxa_pure_virtual() {
Expand Down Expand Up @@ -189,6 +190,13 @@ int maybe_flash_bootloader(void) {
printk("Failed to write flash area, rc %d\n", rc);
return rc;
}
struct led_dt_spec ledb = LED_DT_SPEC_GET(DT_NODELABEL(led3));
while (1) {
led_on_dt(&ledb);
k_msleep(100);
led_off_dt(&ledb);
k_msleep(100);
}
}
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions loader/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ CONFIG_RTC_UPDATE=y
CONFIG_RTC_CALIBRATION=y

CONFIG_DEVICE_DEPS=y

CONFIG_USB_CONFIGURATION_STRING_DESC_ENABLE=y
Loading
Loading