File tree Expand file tree Collapse file tree 8 files changed +90
-9
lines changed Expand file tree Collapse file tree 8 files changed +90
-9
lines changed Original file line number Diff line number Diff line change 1313// limitations under the License.
1414
1515#include "spi_mem.h"
16+ #include "bitbox02_pins.h"
1617#include "util.h"
18+ #include <hal_delay.h>
19+ #include <spi_lite.h>
1720#include <stdbool.h>
1821#include <stdint.h>
1922#include <stdlib.h>
20- #ifndef TESTING
21- #include "bitbox02_pins.h"
22- #include <hal_delay.h>
23- #include <spi_lite.h>
24- #endif
2523
2624#define SECTOR_MASK 0xFFFFF000
2725#define MEMORY_LIMIT (SPI_MEM_MEMORY_SIZE - 1)
3533
3634static void _spi_mem_cs_low (void )
3735{
38- #ifndef TESTING
3936 gpio_set_pin_level (PIN_MEM_CS , 0 );
40- #endif
4137}
4238
4339static void _spi_mem_cs_high (void )
4440{
45- #ifndef TESTING
4641 gpio_set_pin_level (PIN_MEM_CS , 1 );
47- #endif
4842}
4943
5044static uint8_t _spi_mem_read_sr (void )
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ const ALLOWLIST_FNS: &[&str] = &[
105105 "memory_setup" ,
106106 "menu_create" ,
107107 "mock_memory_factoryreset" ,
108+ "spi_mem_full_erase" ,
108109 "printf" ,
109110 "progress_create" ,
110111 "progress_set" ,
Original file line number Diff line number Diff line change 1717#include <memory/bitbox02_smarteeprom.h>
1818#include <memory/memory.h>
1919#include <memory/smarteeprom.h>
20+ #include <memory/spi_mem.h>
2021#include <random.h>
2122#include <reset.h>
2223#include <screen.h>
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ pub fn mock_memory() {
6060
6161 bitbox02_sys:: smarteeprom_bb02_config ( ) ;
6262 bitbox02_sys:: bitbox02_smarteeprom_init ( ) ;
63+ bitbox02_sys:: spi_mem_full_erase ( ) ;
6364 }
6465}
6566
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ set(IGNORE_SOURCES
3030 "src/memory/nvmctrl.c"
3131 "src/memory/smarteeprom.c"
3232 "src/memory/mpu.c"
33+ "src/memory/spi_mem.c"
3334 )
3435
3536# Exclude some files which depends on the hardware.
@@ -61,6 +62,7 @@ add_library(bitbox_objects-simulator
6162 ${ETHEREUM-SOURCES }
6263 framework /mock_cipher.c
6364 framework /mock_memory.c
65+ framework /mock_spi_mem.c
6466 framework /mock_screen.c
6567 framework /mock_smarteeprom.c
6668 framework /mock_securechip.c
Original file line number Diff line number Diff line change 1+ // Copyright 2025 Shift Crypto AG
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ #include <memory/spi_mem.h>
16+ #include <stdlib.h>
17+ #include <string.h>
18+
19+ __extension__ static uint8_t _memory [] = {[0 ... SPI_MEM_MEMORY_SIZE ] = 0xFF };
20+
21+ void spi_mem_full_erase (void )
22+ {
23+ memset (_memory , 0xFF , sizeof (_memory ));
24+ }
25+
26+ bool spi_mem_write (uint32_t address , const uint8_t * input , size_t size )
27+ {
28+ memcpy (& _memory [address ], input , size );
29+ return true;
30+ }
31+
32+ uint8_t * spi_mem_read (uint32_t address , size_t size )
33+ {
34+ uint8_t * result = (uint8_t * )malloc (size );
35+ if (!result ) {
36+ return NULL ;
37+ }
38+ memcpy (result , & _memory [address ], size );
39+ return result ;
40+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ set(IGNORE_SOURCES
3030 "src/memory/nvmctrl.c"
3131 "src/memory/smarteeprom.c"
3232 "src/memory/mpu.c"
33+ "src/memory/spi_mem.c"
3334 )
3435
3536# Exclude some files which depends on the hardware.
@@ -63,6 +64,7 @@ add_library(bitbox_objects
6364 framework /mock_screen.c
6465 framework /mock_screen_stack.c
6566 framework /mock_memory.c
67+ framework /mock_spi_mem.c
6668 framework /mock_qtouch.c
6769 framework /mock_gestures.c
6870 framework /mock_component.c
Original file line number Diff line number Diff line change 1+ // Copyright 2025 Shift Crypto AG
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ #include <memory/spi_mem.h>
16+ #include <stdlib.h>
17+ #include <string.h>
18+
19+ __extension__ static uint8_t _memory [] = {[0 ... SPI_MEM_MEMORY_SIZE ] = 0xFF };
20+
21+ void spi_mem_full_erase (void )
22+ {
23+ memset (_memory , 0xFF , sizeof (_memory ));
24+ }
25+
26+ bool spi_mem_write (uint32_t address , const uint8_t * input , size_t size )
27+ {
28+ memcpy (& _memory [address ], input , size );
29+ return true;
30+ }
31+
32+ uint8_t * spi_mem_read (uint32_t address , size_t size )
33+ {
34+ uint8_t * result = (uint8_t * )malloc (size );
35+ if (!result ) {
36+ return NULL ;
37+ }
38+ memcpy (result , & _memory [address ], size );
39+ return result ;
40+ }
You can’t perform that action at this time.
0 commit comments