aboutsummaryrefslogtreecommitdiff
path: root/board/build.rs
blob: 1f4e207217f0f69f1656f239b8a42f78ce7ab9af (plain)
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
use std::{collections::HashSet, env};

fn extract_features() -> HashSet<String> {
    env::vars()
        .map(|(k, _)| k)
        .flat_map(|feat| feat.strip_prefix("CARGO_FEATURE_").map(str::to_lowercase))
        .collect()
}

/// Creates a runtime for a particular family, adjusting whether the image is expected to be boot
/// based on provided features.
fn create_runtime(
    family: imxrt_rt::Family,
    flash_size: usize,
    features: &HashSet<String>,
) -> imxrt_rt::RuntimeBuilder {
    if features.contains("nonboot") | features.contains("secondary") {
        let mut bldr = imxrt_rt::RuntimeBuilder::in_flash(family, flash_size, 256 * 1024);
        bldr.boot_header(features.contains("secondary"));
        bldr
    } else if features.contains("ram") {
        imxrt_rt::RuntimeBuilder::from_ram(family)
    } else {
        imxrt_rt::RuntimeBuilder::from_flexspi(family, flash_size)
    }
}

/// Configures the runtime for a variety of boards.
///
/// Note that some automated tests may check these runtimes. Feel free to change
/// values and observe how they might affect the tests.
fn main() {
    let features = extract_features();
    for feature in features.iter() {
        match feature.as_str() {
            "teensy4" => {
                imxrt_rt::RuntimeBuilder::from_flexspi(imxrt_rt::Family::Imxrt1060, 1984 * 1024)
                    .flexram_banks(imxrt_rt::FlexRamBanks {
                        ocram: 0,
                        dtcm: 12,
                        itcm: 4,
                    })
                    .heap_size(1024)
                    .text(imxrt_rt::Memory::Flash)
                    .rodata(imxrt_rt::Memory::Dtcm)
                    .data(imxrt_rt::Memory::Dtcm)
                    .bss(imxrt_rt::Memory::Dtcm)
                    .uninit(imxrt_rt::Memory::Dtcm)
                    .stack(imxrt_rt::Memory::Ocram)
                    .stack_size_env_override("THIS_WONT_BE_CONSIDERED")
                    .stack_size_env_override("BOARD_STACK")
                    .heap_size_env_override("BOARD_HEAP")
                    .build()
                    .unwrap()
            }
            "imxrt1010evk" if features.contains("ram") => {
                imxrt_rt::RuntimeBuilder::from_ram(imxrt_rt::Family::Imxrt1010)
                    .heap_size(1024)
                    .build()
                    .unwrap();
            }
            "imxrt1010evk" => imxrt_rt::RuntimeBuilder::from_flexspi(
                imxrt_rt::Family::Imxrt1010,
                16 * 1024 * 1024,
            )
            .heap_size(1024)
            .rodata(imxrt_rt::Memory::Flash)
            .stack_size_env_override("BOARD_STACK")
            .heap_size_env_override("BOARD_HEAP")
            .build()
            .unwrap(),
            "imxrt1170evk_cm7" => {
                create_runtime(imxrt_rt::Family::Imxrt1170, 256 * 1024, &features)
                    .rodata(imxrt_rt::Memory::Dtcm)
                    .stack_size_env_override("BOARD_STACK")
                    .heap_size_env_override("BOARD_HEAP")
                    .flexram_ecc(imxrt_rt::FlexRamEcc::Enable)
                    .mecc64(imxrt_rt::Mecc64::Enable)
                    .build()
                    .unwrap()
            }
            _ => continue,
        }
        break;
    }
}