Skip to content

Commit

Permalink
Dockerfile: bump Rust toolchain to 1.78
Browse files Browse the repository at this point in the history
This reduces the fw binary size by 4176 bytes as compared to the
v9.18.0 release.

Also bump LLVM 18 - it is unrelated but I did it anyway as the Rust
release notes also mentioned that they moved to LLVM 18.

The workflow.rs change is due to this deprecation warning:

```
warning: creating a shared reference to mutable static is discouraged
   --> bitbox02-rust-c/src/workflow.rs:103:11
    |
103 |     match &CONFIRM_STATE {
    |           ^^^^^^^^^^^^^^ shared reference to mutable static
    |
    = note: for more information, see issue #114447 <rust-lang/rust#114447>
    = note: this will be a hard error in the 2024 edition
    = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
    = note: `#[warn(static_mut_refs)]` on by default
help: use `addr_of!` instead to create a raw pointer
    |
103 |     match addr_of!(CONFIRM_STATE) {
```

The C code changes are clang-format changes.
  • Loading branch information
benma committed May 13, 2024
1 parent 13c527d commit d8040da
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .ci/check-style
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
# Exit on pipe fail
set -o pipefail

CLANGFORMAT=${CLANGFORMAT:-clang-format-15}
CLANGFORMAT=${CLANGFORMAT:-clang-format-18}

command -v git >/dev/null 2>&1 || { echo >&2 "git is missing"; exit 1; }
command -v xargs >/dev/null 2>&1 || { echo >&2 "xargs is missing"; exit 1; }
Expand Down
2 changes: 1 addition & 1 deletion .ci/check-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
# Exit on pipe fail
set -o pipefail

CLANGTIDY=${CLANGTIDY:-clang-tidy-15}
CLANGTIDY=${CLANGTIDY:-clang-tidy-18}

command -v git >/dev/null 2>&1 || { echo >&2 "git is missing"; exit 1; }
command -v xargs >/dev/null 2>&1 || { echo >&2 "xargs is missing"; exit 1; }
Expand Down
2 changes: 1 addition & 1 deletion .ci/run-container-ci
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
set -e
set -x

CONTAINER=shiftcrypto/firmware_v2:37
CONTAINER=shiftcrypto/firmware_v2:38

if [ "$1" == "pull" ] ; then
docker pull "$CONTAINER"
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get upgrade -y && apt-get install -y wget nano rsync curl gnupg2 jq unzip bzip2

# for clang-*-15, see https://apt.llvm.org/
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" >> /etc/apt/sources.list && \
echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" >> /etc/apt/sources.list && \
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -

# Install gcc8-arm-none-eabi
Expand All @@ -37,7 +37,7 @@ RUN mkdir ~/Downloads &&\
# Tools for building
RUN apt-get update && apt-get install -y \
build-essential \
llvm-15 \
llvm-18 \
gcc-10 \
binutils \
valgrind \
Expand Down Expand Up @@ -68,8 +68,8 @@ RUN update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
clang-format-15 \
clang-tidy-15
clang-format-18 \
clang-tidy-18

RUN python3 -m pip install --upgrade pip

Expand Down
2 changes: 1 addition & 1 deletion scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
# Exit on pipe fail
set -o pipefail

CLANGFORMAT=${CLANGFORMAT:-clang-format-15}
CLANGFORMAT=${CLANGFORMAT:-clang-format-18}
CLANGFORMAT_FLAGS=${CLANGFORMAT_FLAGS:--i}
VERBOSE=${VERBOSE:-NO}

Expand Down
3 changes: 1 addition & 2 deletions src/factorysetup.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,5 @@ int main(void)
}
}

while (1)
;
while (1);
}
6 changes: 2 additions & 4 deletions src/memory/nvmctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
void nvmctrl_exec_cmd(uint16_t cmd)
{
/* Wait until the NVM is ready to accept a new command. */
while (NVMCTRL->STATUS.bit.READY == 0)
;
while (NVMCTRL->STATUS.bit.READY == 0);
NVMCTRL->ADDR.reg = (uint32_t)NVMCTRL_USER;
NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | cmd;
while (NVMCTRL->STATUS.bit.READY == 0)
;
while (NVMCTRL->STATUS.bit.READY == 0);
}
24 changes: 8 additions & 16 deletions src/memory/smarteeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ void smarteeprom_disable(void)
nvmctrl_exec_cmd(NVMCTRL_CTRLB_CMD_PBC); // Clear page buffer
*((uint32_t*)NVMCTRL_FUSES_SEEPSZ_ADDR) = config_word;
nvmctrl_exec_cmd(NVMCTRL_CTRLB_CMD_WQW); // Write a 128-bit word
while (!NVMCTRL->STATUS.bit.READY)
;
while (NVMCTRL->SEESTAT.bit.BUSY)
;
while (!NVMCTRL->STATUS.bit.READY);
while (NVMCTRL->SEESTAT.bit.BUSY);
}

void smarteeprom_setup(void)
Expand Down Expand Up @@ -88,10 +86,8 @@ void smarteeprom_setup(void)
nvmctrl_exec_cmd(NVMCTRL_CTRLB_CMD_PBC); // Clear page buffer
*((uint32_t*)NVMCTRL_FUSES_SEEPSZ_ADDR) = config_word;
nvmctrl_exec_cmd(NVMCTRL_CTRLB_CMD_WQW); // Write a 128-bit word
while (!NVMCTRL->STATUS.bit.READY)
;
while (NVMCTRL->SEESTAT.bit.BUSY)
;
while (!NVMCTRL->STATUS.bit.READY);
while (NVMCTRL->SEESTAT.bit.BUSY);
}

void smarteeprom_bb02_config(void)
Expand Down Expand Up @@ -122,8 +118,7 @@ void smarteeprom_read(size_t address, size_t bytes, uint8_t* out_buffer)
}

volatile uint8_t* eeprom = (uint8_t*)SEEPROM_ADDR + address;
while (NVMCTRL->SEESTAT.bit.BUSY)
;
while (NVMCTRL->SEESTAT.bit.BUSY);
for (size_t i = 0; i < bytes; ++i) {
out_buffer[i] = *eeprom;
eeprom++;
Expand All @@ -136,8 +131,7 @@ void smarteeprom_write(size_t address, size_t bytes, const uint8_t* buffer)
Abort("NULL input buffer in smarteeprom_write.");
}
volatile uint8_t* eeprom = (uint8_t*)SEEPROM_ADDR + address;
while (NVMCTRL->SEESTAT.bit.BUSY)
;
while (NVMCTRL->SEESTAT.bit.BUSY);
/*
* Buffered write of multiple bytes.
* Note that crossing a 32B page will still result in a partial flush
Expand All @@ -149,10 +143,8 @@ void smarteeprom_write(size_t address, size_t bytes, const uint8_t* buffer)
}
/* Now, flush the write we have issued. */
nvmctrl_exec_cmd(NVMCTRL_CTRLB_CMD_SEEFLUSH);
while (NVMCTRL->SEESTAT.bit.LOAD != 0)
;
while (NVMCTRL->SEESTAT.bit.BUSY != 0)
;
while (NVMCTRL->SEESTAT.bit.LOAD != 0);
while (NVMCTRL->SEESTAT.bit.BUSY != 0);
/*
* Read back the buffer.
* Check that it matches what we've just written.
Expand Down
15 changes: 5 additions & 10 deletions src/pukcc/pukcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,14 @@ static void pukcc_self_test(void)
{
static bool self_test_run = false;
if (!self_test_run) {
while ((PUKCCSR & BIT_PUKCCSR_CLRRAM_BUSY) != 0)
;
while ((PUKCCSR & BIT_PUKCCSR_CLRRAM_BUSY) != 0);
memset(&PUKCLParam, 0, sizeof(PUKCL_PARAM));
pvPUKCLParam = &PUKCLParam;
vPUKCL_Process(SelfTest, pvPUKCLParam);
while (PUKCL(u2Status) != PUKCL_OK)
;
while (pvPUKCLParam->P.PUKCL_SelfTest.u4Version != PUKCL_VERSION)
;
while (pvPUKCLParam->P.PUKCL_SelfTest.u4CheckNum1 != 0x6E70DDD2)
;
while (pvPUKCLParam->P.PUKCL_SelfTest.u4CheckNum2 != 0x25C8D64F)
;
while (PUKCL(u2Status) != PUKCL_OK);
while (pvPUKCLParam->P.PUKCL_SelfTest.u4Version != PUKCL_VERSION);
while (pvPUKCLParam->P.PUKCL_SelfTest.u4CheckNum1 != 0x6E70DDD2);
while (pvPUKCLParam->P.PUKCL_SelfTest.u4CheckNum2 != 0x25C8D64F);
self_test_run = true;
}
}
Expand Down
30 changes: 6 additions & 24 deletions src/qtouch/qtouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,35 +174,17 @@ qtm_touch_key_control_t qtlib_key_set1 = {
/**********************************************************/
/**************** Binding Layer Module ******************/
/**********************************************************/
#define LIB_MODULES_INIT_LIST \
{ \
(module_init_t) & qtm_ptc_init_acquisition_module, null \
}
#define LIB_MODULES_INIT_LIST {(module_init_t) & qtm_ptc_init_acquisition_module, null}

#define LIB_MODULES_PROC_LIST \
{ \
(module_proc_t) & qtm_key_sensors_process, null \
}
#define LIB_MODULES_PROC_LIST {(module_proc_t) & qtm_key_sensors_process, null}

#define LIB_INIT_DATA_MODELS_LIST \
{ \
(void*)&qtlib_acq_set1, null \
}
#define LIB_INIT_DATA_MODELS_LIST {(void*)&qtlib_acq_set1, null}

#define LIB_DATA_MODELS_PROC_LIST \
{ \
(void*)&qtlib_key_set1, null \
}
#define LIB_DATA_MODELS_PROC_LIST {(void*)&qtlib_key_set1, null}

#define LIB_MODULES_ACQ_ENGINES_LIST \
{ \
(module_acq_t) & qtm_ptc_start_measurement_seq, null \
}
#define LIB_MODULES_ACQ_ENGINES_LIST {(module_acq_t) & qtm_ptc_start_measurement_seq, null}

#define LIB_MODULES_ACQ_ENGINES_LIST_DM \
{ \
(void*)&qtlib_acq_set1, null \
}
#define LIB_MODULES_ACQ_ENGINES_LIST_DM {(void*)&qtlib_acq_set1, null}

/* QTM run time options */
module_init_t library_modules_init[] = LIB_MODULES_INIT_LIST;
Expand Down
136 changes: 64 additions & 72 deletions src/qtouch/qtouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,47 +86,63 @@ extern "C" {
* Gain , Digital Gain), filter level}
*/
// Slider 1 buttons
#define NODE_0_PARAMS \
{ \
X_NONE, Y_LINE(26), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \
}
#define NODE_1_PARAMS \
{ \
X_NONE, Y_LINE(27), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \
}
#define NODE_2_PARAMS \
{ \
X_NONE, Y_LINE(28), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \
}
#define NODE_3_PARAMS \
{ \
X_NONE, Y_LINE(29), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \
}
#define NODE_0_PARAMS \
{X_NONE, \
Y_LINE(26), \
0, \
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), \
FILTER_LEVEL_512}
#define NODE_1_PARAMS \
{X_NONE, \
Y_LINE(27), \
0, \
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), \
FILTER_LEVEL_512}
#define NODE_2_PARAMS \
{X_NONE, \
Y_LINE(28), \
0, \
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), \
FILTER_LEVEL_512}
#define NODE_3_PARAMS \
{X_NONE, \
Y_LINE(29), \
0, \
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), \
FILTER_LEVEL_512}
// Slider 0 buttons
#define NODE_4_PARAMS \
{ \
X_NONE, Y_LINE(30), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \
}
#define NODE_5_PARAMS \
{ \
X_NONE, Y_LINE(31), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \
}
#define NODE_6_PARAMS \
{ \
X_NONE, Y_LINE(20), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \
}
#define NODE_7_PARAMS \
{ \
X_NONE, Y_LINE(21), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \
}
#define NODE_4_PARAMS \
{X_NONE, \
Y_LINE(30), \
0, \
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), \
FILTER_LEVEL_512}
#define NODE_5_PARAMS \
{X_NONE, \
Y_LINE(31), \
0, \
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), \
FILTER_LEVEL_512}
#define NODE_6_PARAMS \
{X_NONE, \
Y_LINE(20), \
0, \
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), \
FILTER_LEVEL_512}
#define NODE_7_PARAMS \
{X_NONE, \
Y_LINE(21), \
0, \
NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \
NODE_GAIN(GAIN_4, GAIN_4), \
FILTER_LEVEL_512}

/**********************************************************/
/***************** Key Params ******************/
Expand All @@ -141,38 +157,14 @@ extern "C" {
* {Sensor Threshold, Sensor Hysterisis, Sensor AKS}
*/
// 0..3 higher Slider left to right 4..7 lower Slider right to left
#define KEY_0_PARAMS \
{ \
16, HYST_50, NO_AKS_GROUP \
}
#define KEY_1_PARAMS \
{ \
16, HYST_50, NO_AKS_GROUP \
}
#define KEY_2_PARAMS \
{ \
16, HYST_50, NO_AKS_GROUP \
}
#define KEY_3_PARAMS \
{ \
16, HYST_50, NO_AKS_GROUP \
}
#define KEY_4_PARAMS \
{ \
16, HYST_50, NO_AKS_GROUP \
}
#define KEY_5_PARAMS \
{ \
16, HYST_50, NO_AKS_GROUP \
}
#define KEY_6_PARAMS \
{ \
16, HYST_50, NO_AKS_GROUP \
}
#define KEY_7_PARAMS \
{ \
16, HYST_50, NO_AKS_GROUP \
}
#define KEY_0_PARAMS {16, HYST_50, NO_AKS_GROUP}
#define KEY_1_PARAMS {16, HYST_50, NO_AKS_GROUP}
#define KEY_2_PARAMS {16, HYST_50, NO_AKS_GROUP}
#define KEY_3_PARAMS {16, HYST_50, NO_AKS_GROUP}
#define KEY_4_PARAMS {16, HYST_50, NO_AKS_GROUP}
#define KEY_5_PARAMS {16, HYST_50, NO_AKS_GROUP}
#define KEY_6_PARAMS {16, HYST_50, NO_AKS_GROUP}
#define KEY_7_PARAMS {16, HYST_50, NO_AKS_GROUP}

/* De-bounce counter for additional measurements to confirm touch detection
* Range: 0 to 255.
Expand Down
4 changes: 2 additions & 2 deletions src/rust/bitbox02-rust-c/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub unsafe extern "C" fn rust_workflow_unlock_poll(result_out: &mut bool) -> boo
/// Returns true if there was a result.
#[no_mangle]
pub unsafe extern "C" fn rust_workflow_confirm_poll(result_out: &mut bool) -> bool {
match &CONFIRM_STATE {
TaskState::ResultAvailable(result) => {
match CONFIRM_STATE {
TaskState::ResultAvailable(ref result) => {
CONFIRM_TITLE = None;
CONFIRM_BODY = None;
CONFIRM_PARAMS = None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,10 @@ async fn hash_struct(
child_formatted_path.push("".into());
for (index, member) in typ.members.iter().enumerate() {
*child_path.last_mut().unwrap() = index as u32;
*child_formatted_path.last_mut().unwrap() = member.name.clone();
child_formatted_path
.last_mut()
.unwrap()
.clone_from(&member.name);
let member_type = member.r#type.as_ref().ok_or(Error::InvalidInput)?;
encode_member(
&mut hasher,
Expand Down
2 changes: 1 addition & 1 deletion src/rust/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.76.0
1.78.0
Loading

0 comments on commit d8040da

Please sign in to comment.