Skip to content

Commit

Permalink
Merge pull request #429 from LedgerHQ/xch/ram-reloc
Browse files Browse the repository at this point in the history
Launcher: Fix missing RAM relocation emulation on NanoX, NanoSP and Stax
  • Loading branch information
xchapron-ledger authored Oct 26, 2023
2 parents 5ac7327 + ccf17cc commit 2348e2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.3] - 2023-10-26

### Fixed
- Launcher: Fix missing RAM relocation emulation on NanoX, NanoSP and Stax

## [0.3.2] - 2023-09-28

### Fixed
Expand Down
13 changes: 12 additions & 1 deletion src/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "svc.h"

#define LOAD_ADDR ((void *)0x40000000)
#define LINK_RAM_ADDR (0xda7a0000)
#define LOAD_RAM_ADDR (0x50000000)
#define MAX_APP 16
#define MAIN_APP_NAME "main"

Expand Down Expand Up @@ -299,6 +301,11 @@ static void *load_app(char *name)
data_addr = get_lower_page_aligned_addr(app->elf.stack_addr);
data_size = get_upper_page_aligned_size(
app->elf.stack_size + app->elf.stack_addr - (unsigned long)data_addr);
if (app->elf.stack_addr == LINK_RAM_ADDR) {
// Emulate RAM relocation
data_addr = (void *)LOAD_RAM_ADDR;
data_size = get_upper_page_aligned_size(app->elf.stack_size);
}

/* load code
* map an extra page in case the _install_params are mapped in the beginning
Expand Down Expand Up @@ -547,7 +554,11 @@ static int run_app(char *name, unsigned long *parameters)
/* thumb mode */
f = (void *)((unsigned long)p | 1);
stack_end = app->elf.stack_addr;
stack_start = app->elf.stack_addr + app->elf.stack_size;
if (app->elf.stack_addr == LINK_RAM_ADDR) {
// Emulate RAM relocation
stack_end = LOAD_RAM_ADDR;
}
stack_start = stack_end + app->elf.stack_size;

asm volatile("mov r0, %2\n"
"mov r9, %1\n"
Expand Down

0 comments on commit 2348e2f

Please sign in to comment.