Skip to content

Commit 83fb9bd

Browse files
authored
Merge pull request #1 from MabezDev/cleanup-and-multichip
Multi-chip framework & docs
2 parents 0749f4e + 649e7a5 commit 83fb9bd

File tree

11 files changed

+228
-242
lines changed

11 files changed

+228
-242
lines changed

.cargo/config.toml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11

22

3-
[target.riscv32imc-unknown-none-elf]
4-
## For flash loader
3+
[target.'cfg(any(target_arch = "xtensa", target_arch = "riscv32"))']
54
rustflags = [
6-
"-C", "link-arg=-Tld/esp32c3.x",
75
"-C", "link-arg=-Tld/loader.x",
86
"-C", "link-args=-Map=target/esp-loader.map",
97
"-C", "link-args=--nmagic",
10-
11-
# We don't know where the flash loader will be
12-
# placed in memory, so we need to create
13-
# position independent code (pic).
14-
# "-C", "relocation-model=pic", # no longer required after https://github.com/probe-rs/probe-rs/pull/822
15-
]
16-
17-
[build]
18-
target = "riscv32imc-unknown-none-elf"
8+
]

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ ufmt = { version = "0.1.0", optional = true }
1212
[features]
1313
log = ["ufmt"]
1414

15+
# targets
16+
esp32c3 = []
17+
1518
[profile.release]
1619
codegen-units = 1
1720
debug = false

README.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,49 @@
11
### esp flash loader
22

3-
A WIP probe-rs flash loader.
3+
A probe-rs flash loader for Espressif chips.
44

55
To build the flash loader:
66

77
```bash
8-
cargo build --release # builds the on chip flasher code
9-
target-gen elf target/riscv32imc-unknown-none-elf/release/esp-flashloader > output/esp32c3.yaml # dumps the elf to yaml format for probe-rs
8+
$ cargo build --release --feature $(CHIP_NAME) --target $(RUST_TARGET) # builds the flashing stub
9+
$ target-gen elf target/$(RUST_TARGET)/release/esp-flashloader output/esp32.yaml --update --name $(CHIP_NAME)-flashloader
1010
```
11+
12+
Example for the updating the `esp32c3` flash algorithm.
13+
14+
```bash
15+
$ cargo build --release --features esp32c3 --target riscv32imc-unknown-none-elf
16+
$ target-gen elf target/riscv32imc-unknown-none-elf/release/esp-flashloader output/esp32.yaml --update --name esp32c3-flashloader
17+
```
18+
19+
## Chip support
20+
21+
|name |supported|
22+
|-------|---------|
23+
|esp32c3| Y |
24+
25+
## Adding new chips
26+
27+
1. Add a feature for the chip inside `Cargo.toml`
28+
2. Add the ROM API linker script inside the `ld` directory.
29+
3. Inside the ROM API linker script, add a memory section detailing where the program will be loaded.
30+
```c
31+
MEMORY {
32+
/* Start 64k into the RAM region */
33+
IRAM : ORIGIN = 0x40390000, LENGTH = 0x40000
34+
}
35+
```
36+
It's important to note that the algorithm cannot be loaded at the start of RAM, because probe-rs has a header it loads prior to the algo hence the 64K offset.
37+
4. Add the following snippet to the bottom of the `main()` function inside `build.rs`, adapting it for the new chip name.
38+
```rust
39+
#[cfg(feature = "esp32c3")]
40+
{
41+
fs::copy("ld/esp32c3.x", out_dir.join("esp32c3.x")).unwrap();
42+
println!("cargo:rerun-if-changed=ld/esp32c3.x");
43+
println!("cargo:rustc-link-arg=-Tld/esp32c3.x");
44+
}
45+
```
46+
5. Follow the instructions above for building
47+
6. Use `target-gen` _without_ the `update` flag to generate a new yaml algorithm.
48+
7. merge the new flash algorithm into the the main `esp32.yaml`
49+
8. Upstream the new updates to probe-rs.

build.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ fn main() {
88
fs::copy("ld/loader.x", out_dir.join("loader.x")).unwrap();
99
println!("cargo:rerun-if-changed=ld/loader.x");
1010

11-
// TODO feature gate per chip?
12-
fs::copy("ld/esp32c3.x", out_dir.join("esp32c3.x")).unwrap();
13-
println!("cargo:rerun-if-changed=ld/rom.x");
14-
}
11+
#[cfg(feature = "esp32c3")]
12+
{
13+
fs::copy("ld/esp32c3.x", out_dir.join("esp32c3.x")).unwrap();
14+
println!("cargo:rerun-if-changed=ld/esp32c3.x");
15+
println!("cargo:rustc-link-arg=-Tld/esp32c3.x");
16+
}
17+
}

build.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.

ld/loader.x

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ SECTIONS {
2929

3030
. = ALIGN(4);
3131
} > IRAM
32+
33+
/* Description of the flash algorithm */
34+
DeviceData :
35+
{
36+
/* The device data content is only for external tools,
37+
* and usually not referenced by the code.
38+
*
39+
* The KEEP statement ensures it's not removed by accident.
40+
*/
41+
KEEP(*(DeviceData))
42+
} > IRAM
3243
}
3344

3445

output/esp32.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: esp32
3+
manufacturer: ~
4+
variants:
5+
- name: esp32c3
6+
part: ~
7+
cores:
8+
- name: main
9+
type: riscv
10+
core_access_options:
11+
Riscv: {}
12+
memory_map:
13+
- Nvm:
14+
range:
15+
start: 0
16+
end: 8388608
17+
is_boot_memory: true
18+
cores:
19+
- main
20+
- Ram:
21+
range:
22+
start: 1077411840
23+
end: 1077805056
24+
is_boot_memory: false
25+
cores:
26+
- main
27+
- Ram:
28+
range:
29+
start: 1070071808
30+
end: 1070137344
31+
is_boot_memory: false
32+
cores:
33+
- main
34+
flash_algorithms:
35+
- esp32c3-flashloader
36+
flash_algorithms:
37+
- name: esp32c3-flashloader
38+
description: A flash loader for the esp32c3.
39+
default: true
40+
instructions: QREGxjcFOUADRQUHGcEBRS2glwDH/+eAoHCBRZcAx//ngIAUlwDH/+eAwBEZ5QFFtwU5QAVGI4jFBrJAQQGCgDGBFwPH/2cAYw4XA8f/ZwBjDRN3NgABxxMFoAqCgK6GsoU2hhcDx/9nAIMMAUWCgAAAAAA=
41+
load_address: 1077477376
42+
pc_init: 0
43+
pc_uninit: 108
44+
pc_program_page: 82
45+
pc_erase_sector: 64
46+
pc_erase_all: 74
47+
data_section_offset: 116
48+
flash_properties:
49+
address_range:
50+
start: 0
51+
end: 67108864
52+
page_size: 2048
53+
erased_byte_value: 255
54+
program_page_timeout: 1000
55+
erase_sector_timeout: 2000
56+
sectors:
57+
- size: 4096
58+
address: 0
59+
cores:
60+
- main

output/esp32c3-v11.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.

output/esp32c3.base.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

output/esp32c3.yaml

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)