forked from M-Labs/nac3
1
0
Fork 0

libconfig/load_pl: added alignment for devc buffer

According to the TRM, the buffer should be 64B aligned.
Without the alignment would cause failure for the DMA transaction.
It seems that the allocator would give some alignment, but to be more
correct we should specify that with the alloc interface.
This commit is contained in:
pca006132 2020-09-01 14:32:28 +08:00
parent 42f94487cf
commit 04437e876c
1 changed files with 15 additions and 8 deletions

View File

@ -140,16 +140,23 @@ pub fn load_bitstream<File: Read + Seek>(
file: &mut File, file: &mut File,
) -> Result<(), PlLoadingError> { ) -> Result<(), PlLoadingError> {
let size = locate_bitstream(file)?; let size = locate_bitstream(file)?;
let mut buffer: alloc::vec::Vec<u8> = alloc::vec::Vec::with_capacity(size);
unsafe { unsafe {
buffer.set_len(buffer.capacity()); // align to 64 bytes
let ptr = alloc::alloc::alloc(alloc::alloc::Layout::from_size_align(size, 64).unwrap());
let buffer = core::slice::from_raw_parts_mut(ptr, size);
file.read_exact(buffer).map_err(|e| {
core::ptr::drop_in_place(ptr);
e
})?;
let mut devcfg = devc::DevC::new();
devcfg.enable();
devcfg.program(&buffer).map_err(|e| {
core::ptr::drop_in_place(ptr);
e
})?;
core::ptr::drop_in_place(ptr);
Ok(())
} }
file.read_exact(&mut buffer)?;
let mut devcfg = devc::DevC::new();
devcfg.enable();
devcfg.program(&buffer)?;
Ok(())
} }
pub fn load_bitstream_from_sd() -> Result<(), PlLoadingError> { pub fn load_bitstream_from_sd() -> Result<(), PlLoadingError> {