File tree 8 files changed +90
-9
lines changed
8 files changed +90
-9
lines changed Original file line number Diff line number Diff line change 13
13
// limitations under the License.
14
14
15
15
#include "spi_mem.h"
16
+ #include "bitbox02_pins.h"
16
17
#include "util.h"
18
+ #include <hal_delay.h>
19
+ #include <spi_lite.h>
17
20
#include <stdbool.h>
18
21
#include <stdint.h>
19
22
#include <stdlib.h>
20
- #ifndef TESTING
21
- #include "bitbox02_pins.h"
22
- #include <hal_delay.h>
23
- #include <spi_lite.h>
24
- #endif
25
23
26
24
#define SECTOR_MASK 0xFFFFF000
27
25
#define MEMORY_LIMIT (SPI_MEM_MEMORY_SIZE - 1)
35
33
36
34
static void _spi_mem_cs_low (void )
37
35
{
38
- #ifndef TESTING
39
36
gpio_set_pin_level (PIN_MEM_CS , 0 );
40
- #endif
41
37
}
42
38
43
39
static void _spi_mem_cs_high (void )
44
40
{
45
- #ifndef TESTING
46
41
gpio_set_pin_level (PIN_MEM_CS , 1 );
47
- #endif
48
42
}
49
43
50
44
static 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] = &[
105
105
"memory_setup" ,
106
106
"menu_create" ,
107
107
"mock_memory_factoryreset" ,
108
+ "spi_mem_full_erase" ,
108
109
"printf" ,
109
110
"progress_create" ,
110
111
"progress_set" ,
Original file line number Diff line number Diff line change 17
17
#include <memory/bitbox02_smarteeprom.h>
18
18
#include <memory/memory.h>
19
19
#include <memory/smarteeprom.h>
20
+ #include <memory/spi_mem.h>
20
21
#include <random.h>
21
22
#include <reset.h>
22
23
#include <screen.h>
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ pub fn mock_memory() {
60
60
61
61
bitbox02_sys:: smarteeprom_bb02_config ( ) ;
62
62
bitbox02_sys:: bitbox02_smarteeprom_init ( ) ;
63
+ bitbox02_sys:: spi_mem_full_erase ( ) ;
63
64
}
64
65
}
65
66
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ set(IGNORE_SOURCES
30
30
"src/memory/nvmctrl.c"
31
31
"src/memory/smarteeprom.c"
32
32
"src/memory/mpu.c"
33
+ "src/memory/spi_mem.c"
33
34
)
34
35
35
36
# Exclude some files which depends on the hardware.
@@ -61,6 +62,7 @@ add_library(bitbox_objects-simulator
61
62
${ETHEREUM-SOURCES }
62
63
framework /mock_cipher.c
63
64
framework /mock_memory.c
65
+ framework /mock_spi_mem.c
64
66
framework /mock_screen.c
65
67
framework /mock_smarteeprom.c
66
68
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
30
30
"src/memory/nvmctrl.c"
31
31
"src/memory/smarteeprom.c"
32
32
"src/memory/mpu.c"
33
+ "src/memory/spi_mem.c"
33
34
)
34
35
35
36
# Exclude some files which depends on the hardware.
@@ -63,6 +64,7 @@ add_library(bitbox_objects
63
64
framework /mock_screen.c
64
65
framework /mock_screen_stack.c
65
66
framework /mock_memory.c
67
+ framework /mock_spi_mem.c
66
68
framework /mock_qtouch.c
67
69
framework /mock_gestures.c
68
70
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