1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 21:22:10 +00:00

core/boardloader: use SRAM as SD card read buffer

because DMA can't access the CCMRAM
This commit is contained in:
Pavol Rusnak 2020-02-25 17:59:16 +01:00
parent 939e9e8ea2
commit c896f02eb3
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -45,6 +45,10 @@ static const uint8_t * const BOARDLOADER_KEYS[] = {
#endif
};
// we use SRAM as SD card read buffer (because DMA can't access the CCMRAM)
extern uint32_t sram_start[];
#define sdcard_buf sram_start
static uint32_t check_sdcard(void) {
if (sectrue != sdcard_power_on()) {
return 0;
@ -56,12 +60,10 @@ static uint32_t check_sdcard(void) {
return 0;
}
uint32_t buf[IMAGE_HEADER_SIZE / sizeof(uint32_t)];
memzero(buf, sizeof(buf));
memzero(sdcard_buf, IMAGE_HEADER_SIZE);
const secbool read_status =
sdcard_read_blocks(buf, 0, IMAGE_HEADER_SIZE / SDCARD_BLOCK_SIZE);
sdcard_read_blocks(sdcard_buf, 0, IMAGE_HEADER_SIZE / SDCARD_BLOCK_SIZE);
sdcard_power_off();
@ -69,7 +71,7 @@ static uint32_t check_sdcard(void) {
if ((sectrue == read_status) &&
(sectrue ==
load_image_header((const uint8_t *)buf, BOOTLOADER_IMAGE_MAGIC,
load_image_header((const uint8_t *)sdcard_buf, BOOTLOADER_IMAGE_MAGIC,
BOOTLOADER_IMAGE_MAXSIZE, BOARDLOADER_KEY_M,
BOARDLOADER_KEY_N, BOARDLOADER_KEYS, &hdr))) {
return hdr.codelen;
@ -142,13 +144,14 @@ static secbool copy_sdcard(void) {
ensure(sdcard_power_on(), NULL);
uint32_t buf[SDCARD_BLOCK_SIZE / sizeof(uint32_t)];
memzero(sdcard_buf, SDCARD_BLOCK_SIZE);
for (int i = 0; i < (IMAGE_HEADER_SIZE + codelen) / SDCARD_BLOCK_SIZE; i++) {
ensure(sdcard_read_blocks(buf, i, 1), NULL);
ensure(sdcard_read_blocks(sdcard_buf, i, 1), NULL);
for (int j = 0; j < SDCARD_BLOCK_SIZE / sizeof(uint32_t); j++) {
ensure(flash_write_word(FLASH_SECTOR_BOOTLOADER,
i * SDCARD_BLOCK_SIZE + j * sizeof(uint32_t),
buf[j]),
sdcard_buf[j]),
NULL);
}
}