Skip to content

Commit 9684aba

Browse files
committed
i2c_ecc,random: remove duplicate definitions
These symbols are already defined in driver_init.c. The current GCC version doesn't complain, I discovered this when trying to build with an updated GCC (arm-gnu-toolchain-11.3.rel1-x86_64) and getting errors about these redefinitions. The reason that the current GCC version (GCC 8) didn't complain and the updated one (GCC 11) did complain is that the default for the -fcommon flag changed from on to off in GCC 10. See: - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85678 - https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html (-fcommon) clang-tidy also checked i2c_ecc.c because it was modified and reported these errors, which are also fixed in the commit: ``` /bitbox02-firmware/src/i2c_ecc.c:29:18: error: narrowing conversion from 'uint32_t' (aka 'unsigned int') to signed type 'int32_t' (aka 'int') is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] packet.len = rxlen; ^ /bitbox02-firmware/src/i2c_ecc.c:48:18: error: narrowing conversion from 'uint32_t' (aka 'unsigned int') to signed type 'int32_t' (aka 'int') is implementation-defined [bugprone-narrowing-conversions,-warnings-as-errors] packet.len = txlen; ```
1 parent ea03490 commit 9684aba

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ string(APPEND CMAKE_C_FLAGS " -Wno-cast-function-type")
320320
# Hardening
321321
string(APPEND CMAKE_C_FLAGS " -fstack-protector-all")
322322

323+
# Disallow duplicate definitions, which is the default since GCC
324+
# 10. It was not default in gcc-arm-none-eabi-8-2018-q4.
325+
string(APPEND CMAKE_C_FLAGS " -fno-common")
326+
323327
# For `struct timespec` and `strdup`
324328
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=600")
325329

src/i2c_ecc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919
#include "util.h"
2020
#include <string.h>
2121

22-
struct i2c_m_sync_desc I2C_0;
23-
2422
uint8_t i2c_ecc_read(uint8_t* rxdata, uint32_t rxlen)
2523
{
2624
struct _i2c_m_msg packet;
2725
uint8_t retries = I2C_ECC_RETRIES;
2826
int32_t r;
2927

3028
packet.addr = I2C_ECC_ADDR >> 1;
31-
packet.len = rxlen;
29+
packet.len = (int32_t)rxlen;
3230
packet.buffer = rxdata;
3331
packet.flags = I2C_M_SEVEN | I2C_M_RD | I2C_M_STOP;
3432

@@ -47,7 +45,7 @@ uint8_t i2c_ecc_write(uint8_t* txdata, uint32_t txlen)
4745
int32_t r;
4846

4947
packet.addr = I2C_ECC_ADDR >> 1;
50-
packet.len = txlen;
48+
packet.len = (int32_t)txlen;
5149
packet.buffer = txdata;
5250
packet.flags = I2C_M_SEVEN | I2C_M_STOP;
5351

src/random.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
#include "util.h"
2626
#include <wally_crypto.h>
2727

28-
#ifndef TESTING
29-
struct rand_sync_desc RAND_0;
30-
#endif
31-
3228
void random_32_bytes_mcu(uint8_t* buf)
3329
{
3430
if (buf == NULL) {

0 commit comments

Comments
 (0)