Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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 .github/workflows/auto-tag-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ jobs:
VERSION=$(cat version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
echo $VERSION
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${AUTH_TOKEN}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/git/refs -d '{"ref":"refs/tags/v'${VERSION}'","sha":"'${COMMIT}'"}'
echo "Tag v${VERSION} created successfully."
76 changes: 68 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,98 @@ jobs:
matrix:
firmware: [Main]
target: [Release]
coin_support: ["BTC_ONLY", "MULTI_COIN"] # Builds both BTC_ONLY and MULTI_COIN variants
uses: ./.github/workflows/containerized-build.yml
with:
firmware: ${{ matrix.firmware }}
target: ${{ matrix.target }}
coin_support_variant: ${{ matrix.coin_support }}
secrets: inherit

create-release:
needs: build-firmwares
needs: build-firmwares # Depends on all firmwares being built
runs-on: ubuntu-latest
if: ${{ github.ref_type }} == 'tag'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./
path: ./ # Downloads all artifacts to the current directory

- name: Publish a release
env:
TAG_NAME: ${{ github.ref_name }}
auth_token: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
run: |
chkmain=$(sha256sum Main-Release-outputs/Cypherock-Main.bin | cut -f -1 -d ' ')
# Calculate SHA256 hash for the MULTI_COIN firmware
# The path assumes download-artifact placed it in Main-Release-MULTI_COIN-outputs/build/
chkmain_multicoin=$(sha256sum Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin | cut -f -1 -d ' ')

# Calculate SHA256 hash for the BTC_ONLY firmware
# The path assumes download-artifact placed it in Main-Release-BTC_ONLY-outputs/build/
# The filename is Cypherock-Main-btc.bin due to the CMakeLists.txt modification
chkmain_btc_only=$(sha256sum Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin | cut -f -1 -d ' ')

APP_VERSION=$(cat version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
HW_VERSION=$(cat version.txt | grep hardware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
echo ${APP_VERSION}:${HW_VERSION}
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/releases -d '{"tag_name":"'${TAG_NAME}'","target_commitish":"main","name":"'${TAG_NAME}'","body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain}'","draft":true,"prerelease":false,"generate_release_notes":true}' > output.txt

echo "Application version: ${APP_VERSION}"
echo "Hardware version: ${HW_VERSION}"

# Create the release with both firmware hashes in the body
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${auth_token}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${REPOSITORY}/releases \
-d '{
"tag_name":"'${TAG_NAME}'",
"target_commitish":"main",
"name":"'${TAG_NAME}'",
"body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain_multicoin}' \r\n**Cypherock-Main-btc.bin** : '${chkmain_btc_only}'",
"draft":true,
"prerelease":false,
"generate_release_notes":true
}' > output.txt

# Extract upload_url for subsequent asset uploads
echo "upload_url=$(cat output.txt | grep "\"upload_url\":" | cut -f 4-4 -d '"' | cut -f 1-1 -d '{')" >> $GITHUB_ENV

- name: Upload assets
env:
auth_token: ${{ secrets.GITHUB_TOKEN }}
upload_url: ${{ env.upload_url }} # Use the extracted upload_url
run: |
content_type=$(file -b --mime-type Main-Release-outputs/Cypherock-Main.bin)
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main.bin --data-binary @Main-Release-outputs/Cypherock-Main.bin
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=version.txt --data-binary @version.txt
# Upload the MULTI_COIN firmware binary
content_type_multicoin=$(file -b --mime-type Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin)
curl -X POST \
-H "Content-Type: ${content_type_multicoin}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${auth_token}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${upload_url}?name=Cypherock-Main.bin" \
--data-binary @Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin

# Upload the BTC_ONLY firmware binary
content_type_btc_only=$(file -b --mime-type Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin)
curl -X POST \
-H "Content-Type: ${content_type_btc_only}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${auth_token}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${upload_url}?name=Cypherock-Main-btc.bin" \
--data-binary @Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin

# Upload version.txt
content_type_version=$(file -b --mime-type version.txt)
curl -X POST \
-H "Content-Type: ${content_type_version}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${auth_token}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${upload_url}?name=version.txt" \
--data-binary @version.txt
1 change: 1 addition & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,4 @@ jobs:
cat test_results.txt
# Unity prints "OK" if all tests pass, "FAIL" if tests fail; return 1 to indicate failure
if [ ! "$(tail -n 1 test_results.txt)" = "OK" ]; then exit 1; fi

77 changes: 64 additions & 13 deletions .github/workflows/containerized-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,81 @@ on:
target:
required: true
type: string
coin_support_variant:
required: true
type: string
workflow_dispatch:
inputs:
firmware:
required: true
type: string
default: 'Main'
target:
required: true
type: string
default: 'Release'
coin_support_variant:
required: true
type: string
default: 'MULTI_COIN'

jobs:
build:
runs-on: ubuntu-latest
container:
image: cypherock/x1-firmware-builder:v0.0.0

steps:
- name: Build Firmware (${{ inputs.firmware }} - ${{ inputs.target }})
- name: Set VERSION_TAG
id: set_version_tag
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
export VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')
echo "VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref_type }}" == "branch" ]]; then
export VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')
echo "VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')" >> $GITHUB_OUTPUT
else
# reftype is repository; use default branch
export VERSION_TAG=main
echo "VERSION_TAG=main" >> $GITHUB_OUTPUT
fi
git clone --branch ${VERSION_TAG} --depth 1 https://github.com/${{ github.repository }}.git --recurse-submodules
mkdir build && cd x1_wallet_firmware && mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE="${{ inputs.target }}" -DFIRMWARE_TYPE="${{ inputs.firmware }}" -DCMAKE_BUILD_PLATFORM="Device" -G "Ninja" ..
ninja && cd ../..
cp x1_wallet_firmware/build/Cypherock-*.* ./build/
- name: Archive Build Artifacts

- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ steps.set_version_tag.outputs.VERSION_TAG }}
submodules: recursive

- name: Build Firmware (${{ inputs.firmware }} - ${{ inputs.target }} - ${{ inputs.coin_support_variant }})
run: |
cd x1_wallet_firmware

BTC_ONLY_FLAG="OFF"
if [[ "${{ inputs.coin_support_variant }}" == "BTC_ONLY" ]]; then
BTC_ONLY_FLAG="ON"
fi

BUILD_DIR="build_${{ inputs.coin_support_variant }}"
mkdir -p "${BUILD_DIR}"

cmake -B "${BUILD_DIR}" \
-DDEV_SWITCH=OFF \
-DUNIT_TESTS_SWITCH:BOOL=OFF \
-DBTC_ONLY:BOOL="${BTC_ONLY_FLAG}" \
-DSIGN_BINARY=OFF \
-DCMAKE_BUILD_TYPE:STRING="${{ inputs.target }}" \
-DFIRMWARE_TYPE="${{ inputs.firmware }}" \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF \
-DCMAKE_BUILD_PLATFORM:STRING="Device" \
-G "Ninja" .

ninja -C "${BUILD_DIR}"

cd ..

mkdir -p build

cp x1_wallet_firmware/"${BUILD_DIR}"/Cypherock-*.* ./build/

- name: Archive Build Artifacts (${{ inputs.coin_support_variant }})
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.firmware }}-${{ inputs.target }}-outputs
path: build
name: ${{ inputs.firmware }}-${{ inputs.target }}-${{ inputs.coin_support_variant }}-outputs
path: build
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: aws s3 cp ./doxygen/html s3://docs-x1.cypherock.com --recursive
run: aws s3 cp ./doxygen/html s3://docs-x1.cypherock.com --recursive
2 changes: 1 addition & 1 deletion .github/workflows/version-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
version0=$(git show ${SHA_BASE}:version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print $1*2**24 + $2*2**16 + $3*2**8 + $4 }')
version1=$(git show ${SHA_HEAD}:version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print $1*2**24 + $2*2**16 + $3*2**8 + $4 }')
echo $version0:$version1
if [[ $version0 > $version1 ]]; then echo -e "Version downgrade detected\nfrom $version0 to $version1\n"; exit 1; fi
if [[ $version0 > $version1 ]]; then echo -e "Version downgrade detected\nfrom $version0 to $version1\n"; exit 1; fi
106 changes: 79 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,28 @@ set(CMAKE_MESSAGE_LOG_LEVEL debug)
if("${CMAKE_BUILD_PLATFORM}" STREQUAL "Device")
message("Device platform selected")
set(CMAKE_TOOLCHAIN_FILE utilities/cmake/arm-none-eabi-gcc.cmake)
set(PROJECT Cypherock-${FIRMWARE_TYPE})
set(PROJECT_NAME_BASE Cypherock-${FIRMWARE_TYPE})
elseif("${CMAKE_BUILD_PLATFORM}" STREQUAL "Simulator")
message("Simulator platform selected")
set(PROJECT Cypherock_Simulator)
set(PROJECT_NAME_BASE Cypherock_Simulator)
else()
message(WARNING "No platform specified defaulting to Simulator. Specify using -DCMAKE_BUILD_PLATFORM=<Type> Type can be Device or Simulator")
set(PROJECT Cypherock_Simulator)
message(WARNING "No platform specified, defaulting to Simulator. Specify using -DCMAKE_BUILD_PLATFORM=<Type>")
set(PROJECT_NAME_BASE Cypherock_Simulator)
endif()

project(${PROJECT})

# python is needed for compiling proto files using nanopb
# also for generating & appending firmware signature headers
find_package( Python3 REQUIRED COMPONENTS Interpreter )
execute_process(COMMAND sh utilities/proto/generate-protob.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY )

# Populate version.c
include(utilities/cmake/version.cmake)

file(GLOB_RECURSE PROTO_SRCS "generated/proto/*.*")
list(APPEND PROTO_SRCS "vendor/nanopb/pb_common.c" "vendor/nanopb/pb_decode.c" "vendor/nanopb/pb_encode.c" "vendor/nanopb/pb_common.h" "vendor/nanopb/pb_decode.h" "vendor/nanopb/pb_encode.h" "vendor/nanopb/pb.h")

list (APPEND MINI_GMP_SRCS "vendor/mini-gmp/mini-gmp-helpers.c" "vendor/mini-gmp/mini-gmp.c")
list (APPEND POSEIDON_SRCS "vendor/poseidon/sources/f251.c" "vendor/poseidon/sources/poseidon.c" "vendor/poseidon/sources/poseidon_rc.c")

# Define all build options
OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF)
OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF)
OPTION(BTC_ONLY "Build firmware for Bitcoin only" OFF)

Copy link
Collaborator

@muzaffarbhat07 muzaffarbhat07 Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of btc only, append -btc to project name. Take reference from odix pr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

# Append suffix to the project name if BTC_ONLY is enabled
set(PROJECT ${PROJECT_NAME_BASE})
if (BTC_ONLY)
set(PROJECT ${PROJECT}-btc)
endif()

# Define the project with its final calculated name
project(${PROJECT})

# Make static functions testable via unit-tests
IF(UNIT_TESTS_SWITCH)
Expand All @@ -39,21 +34,78 @@ ELSE()
add_compile_definitions( STATIC=static )
ENDIF(UNIT_TESTS_SWITCH)

# Set firmware type (Main or Initial)
if ("${FIRMWARE_TYPE}" STREQUAL "Main")
add_compile_definitions(X1WALLET_INITIAL=0 X1WALLET_MAIN=1)
elseif("${FIRMWARE_TYPE}" STREQUAL "Initial")
add_compile_definitions(X1WALLET_INITIAL=1 X1WALLET_MAIN=0)
endif()

# Set variant-specific definition (BTC_ONLY_BUILD)
if(BTC_ONLY)
add_compile_definitions(BTC_ONLY_BUILD=1)
endif()

# Set hash calculation definition based on build type
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
add_compile_definitions(FIRMWARE_HASH_CALC=1)
else()
add_compile_definitions(FIRMWARE_HASH_CALC=0)
endif()

# Enable support for dynamically allocated fields in nanopb
add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1)

find_package( Python3 REQUIRED COMPONENTS Interpreter )

# Conditionally generate protobuf files based on the BTC_ONLY option
IF(BTC_ONLY)
message(STATUS "Generating protobufs for BTC-only build")
execute_process(COMMAND bash utilities/proto/generate-protob.sh --btc-only
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY)
ELSE()
message(STATUS "Generating protobufs for full build")
execute_process(COMMAND bash utilities/proto/generate-protob.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY)
ENDIF()

# Populate version.c
include(utilities/cmake/version.cmake)

file(GLOB_RECURSE PROTO_SRCS "generated/proto/*.*")
list(APPEND PROTO_SRCS
"vendor/nanopb/pb_common.c"
"vendor/nanopb/pb_decode.c"
"vendor/nanopb/pb_encode.c"
"vendor/nanopb/pb_common.h"
"vendor/nanopb/pb_decode.h"
"vendor/nanopb/pb_encode.h"
"vendor/nanopb/pb.h"
)

list (APPEND MINI_GMP_SRCS
"vendor/mini-gmp/mini-gmp-helpers.c"
"vendor/mini-gmp/mini-gmp.c"
)
list (APPEND POSEIDON_SRCS
"vendor/poseidon/sources/f251.c"
"vendor/poseidon/sources/poseidon.c"
"vendor/poseidon/sources/poseidon_rc.c"
)

# This is where add_executable(${PROJECT} ...) is called
if("${CMAKE_BUILD_PLATFORM}" STREQUAL "Device")
include(utilities/cmake/firmware/firmware.cmake)
else()
else() # Simulator or default
include(utilities/cmake/simulator/simulator.cmake)
endif()

# Include nanopb source headers
target_include_directories( ${EXECUTABLE} PRIVATE vendor/nanopb generated/proto vendor/mini-gmp vendor/poseidon/sources)

# Enable support for dynamically allocated fields in nanopb
# Ref: vendor/nanopb/pb.h
add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1)
# This must come AFTER the add_executable call in the included files
target_include_directories( ${PROJECT} PRIVATE
vendor/nanopb
generated/proto
vendor/mini-gmp
vendor/poseidon/sources
)
Loading