-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
88 lines (70 loc) · 2.63 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
let mut feature_count = 0;
if cfg!(feature = "flash-256") {
feature_count += 1;
}
if cfg!(feature = "flash-512") {
feature_count += 1;
}
if cfg!(feature = "ram-136") {
feature_count += 1;
}
if cfg!(feature = "ram-200") {
feature_count += 1;
}
if !cfg!(feature = "disable-linker-script") {
if feature_count != 2 {
panic!("\n\nMust select exactly two packages (one flash, one ram) for linker script generation!\nChoices: 'ram-136'/'ram-200' and 'flash-256'/'flash-512'\nAlternatively, pick the mcu-feature that matches your MCU, for example 'mcu-LPC54608J512ET180 '\n\n");
}
let flash_features: Vec<u32> = [
(256, cfg!(feature = "flash-256")),
(512, cfg!(feature = "flash-512")),
]
.iter()
.filter(|(_, f)| *f)
.map(|(f, _)| *f)
.collect();
if flash_features.len() != 1 {
panic!("\n\nMust select exactly one flash size for linker script generation!\n\
Choices: 'flash-256' or 'flash-512'\n \
Alternatively, pick the mcu-feature that matches your MCU, for example 'mcu-LPC54608J512ET180'\n\n");
}
let flash_size = flash_features[0];
let ram_features: Vec<u32> = [
(96, cfg!(feature = "ram-136")),
(160, cfg!(feature = "ram-200")),
]
.iter()
.filter(|(_, f)| *f)
.map(|(f, _)| *f)
.collect();
if ram_features.len() != 1 {
panic!("\n\nMust select exactly one ram size for linker script generation!\n\
Choices: 'ram-136' or 'ram-200'\n \
Alternatively, pick the mcu-feature that matches your MCU, for example 'mcu-LPC54608J512ET180'\n\n");
}
let ram_size = ram_features[0];
let linker = format!(
r#"MEMORY
{{
FLASH : ORIGIN = 0x0, LENGTH = {}K /* PROGRAM_FLASH */
RAM : ORIGIN = 0x20000000, LENGTH = {}K /* alias SRAM_UPPER alias RAM */
SRAMX : ORIGIN = 0x4000000, LENGTH = 32K /* alias RAM2 */
USB_RAM : ORIGIN = 0x40100000, LENGTH = 8K /* alias RAM3 */
}}"#,
flash_size, ram_size
);
File::create(out.join("memory.x"))
.unwrap()
.write_all(linker.as_bytes())
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
}
println!("cargo:rerun-if-changed=build.rs");
}