blob: 9f4cf47a50d98d04c3667071611ae535ddaa7b44 [file] [log] [blame]
David Browne2acfae2020-01-21 16:45:01 -07001// Copyright (c) 2017-2019 Linaro LTD
2//
3// SPDX-License-Identifier: Apache-2.0
4
David Brownf52272c2017-07-12 09:56:16 -06005mod area;
David Brown63902772017-07-12 09:47:49 -06006pub mod c;
David Brownf52272c2017-07-12 09:56:16 -06007
8// The API needs to be public, even though it isn't intended to be called by Rust code, but the
9// functions are exported to C code.
David Brown63902772017-07-12 09:47:49 -060010pub mod api;
David Brownf52272c2017-07-12 09:56:16 -060011
David Brown65de6d12019-01-02 11:38:38 -070012pub use crate::area::{AreaDesc, FlashId};
David Brown8a4e23b2021-06-11 10:29:01 -060013
14/// For testing the ram load feature, we need to emulate a block of RAM and be able to pass that
15/// down to the C code. The call down to boot_go should go through this object so that the buffer
16/// itself is managed properly.
17pub struct RamBlock {
18 ram: Vec<u8>,
19 offset: u32, // 32-bit offset.
20}
21
22impl RamBlock {
23 pub fn new(size: u32, offset: u32) -> RamBlock {
24 RamBlock {
25 ram: vec![0; size as usize],
26 offset: offset,
27 }
28 }
29
30 /// Borrow the RAM buffer, with 'offset' being the beginning of the buffer.
31 pub fn borrow(&self) -> &[u8] {
32 &self.ram
33 }
34
35 pub fn invoke<F, R>(&self, act: F) -> R
36 where F: FnOnce() -> R
37 {
38 api::set_ram_info(api::BootsimRamInfo {
39 start: self.offset,
40 size: self.ram.len() as u32,
41 base: &self.ram[0] as *const u8 as usize - self.offset as usize,
42 });
43 let result = act();
44 api::clear_ram_info();
45 result
46 }
47}