Skip to content
Merged
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
103 changes: 103 additions & 0 deletions .github/ci/qboot/package-tool-smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env sh
set -eu

repo_root=$(CDPATH= cd "$(dirname "$0")/../../.." && pwd)
tool_path=${repo_root}/tools/package_tool.py
work_dir=$(mktemp -d)

cleanup()
{
rm -rf "$work_dir"
}
trap cleanup EXIT HUP INT TERM

if [ ! -f "$tool_path" ]; then
printf 'Package tool not found: %s\n' "$tool_path" >&2
exit 1
fi

raw_file=${work_dir}/raw.bin
pkg_file=${work_dir}/package.bin
output_file=${work_dir}/output.rbl
log_file=${work_dir}/package-tool.log

printf 'qboot raw firmware smoke input\n' > "$raw_file"
printf 'qboot prepared package smoke input\n' > "$pkg_file"

PYTHONDONTWRITEBYTECODE=1 python3 "$tool_path" \
--pkg "$pkg_file" \
--raw "$raw_file" \
--output "$output_file" \
--crypt xor \
--cmprs gzip \
--algo2 crc \
--part app \
--version v1.00-ci \
--product QBOOT-CI \
> "$log_file"

python3 - "$raw_file" "$pkg_file" "$output_file" <<'PY'
import struct
import sys
import zlib

raw_path, pkg_path, output_path = sys.argv[1:]
header_format = "<4sHHI16s24s24sIIIII"
header_size = struct.calcsize(header_format)

with open(raw_path, "rb") as raw_stream:
raw_data = raw_stream.read()
with open(pkg_path, "rb") as pkg_stream:
pkg_data = pkg_stream.read()
with open(output_path, "rb") as output_stream:
output_data = output_stream.read()

if len(output_data) != header_size + len(pkg_data):
raise SystemExit("Unexpected RBL output size")

fields = struct.unpack(header_format, output_data[:header_size])
(
magic,
algo,
algo2,
timestamp,
part_name,
fw_version,
product_code,
pkg_crc,
raw_crc,
raw_size,
pkg_size,
header_crc,
) = fields

if magic != b"RBL\x00":
raise SystemExit("Invalid RBL magic")
if algo != (1 | (1 << 8)):
raise SystemExit("Unexpected algorithm flags")
if algo2 != 1:
raise SystemExit("Unexpected verification algorithm")
if timestamp <= 0:
raise SystemExit("Invalid package timestamp")
if part_name.split(b"\x00", 1)[0] != b"app":
raise SystemExit("Unexpected partition name")
if fw_version.split(b"\x00", 1)[0] != b"v1.00-ci":
raise SystemExit("Unexpected firmware version")
if product_code.split(b"\x00", 1)[0] != b"QBOOT-CI":
raise SystemExit("Unexpected product code")
if pkg_crc != (zlib.crc32(pkg_data) & 0xFFFFFFFF):
raise SystemExit("Package CRC mismatch")
if raw_crc != (zlib.crc32(raw_data) & 0xFFFFFFFF):
raise SystemExit("Raw firmware CRC mismatch")
if raw_size != len(raw_data):
raise SystemExit("Raw firmware size mismatch")
if pkg_size != len(pkg_data):
raise SystemExit("Package size mismatch")
if header_crc != (zlib.crc32(output_data[:header_size - 4]) & 0xFFFFFFFF):
raise SystemExit("Header CRC mismatch")
if output_data[header_size:] != pkg_data:
raise SystemExit("Package payload mismatch")
PY

cat "$log_file"
printf 'PACKAGE_TOOL_SMOKE_PASS\n'
66 changes: 66 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Quality checks

on:
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: read

jobs:
package-tool-smoke:
name: Package tool smoke
runs-on: ubuntu-22.04
timeout-minutes: 15

steps:
- name: Checkout QBoot
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0

- name: Run package tool smoke test
run: sh .github/ci/qboot/package-tool-smoke.sh

- name: Verify workspace is clean
run: |
workspace_status=$(git status --porcelain)
if [ -n "$workspace_status" ]; then
printf 'Workspace changed during package tool smoke test:\n%s\n' "$workspace_status" >&2
exit 1
fi

cppcheck:
name: Cppcheck report
runs-on: ubuntu-22.04
timeout-minutes: 30

steps:
- name: Checkout QBoot
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0

- name: Install cppcheck
run: sudo apt-get update && sudo apt-get install -y cppcheck

- name: Run cppcheck analysis
run: |
cppcheck \
--enable=warning,style,performance,portability \
--inconclusive \
--std=c11 \
--force \
--quiet \
--suppress=missingInclude \
--suppress=missingIncludeSystem \
-Iinc \
src algorithm platform \
2> cppcheck.txt

- name: Upload cppcheck report
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: cppcheck-report
path: cppcheck.txt
if-no-files-found: error
retention-days: 14
Loading