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

View File

@ -140,17 +140,24 @@ pub fn load_bitstream<File: Read + Seek>(
file: &mut File,
) -> Result<(), PlLoadingError> {
let size = locate_bitstream(file)?;
let mut buffer: alloc::vec::Vec<u8> = alloc::vec::Vec::with_capacity(size);
unsafe {
buffer.set_len(buffer.capacity());
}
file.read_exact(&mut buffer)?;
// 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)?;
devcfg.program(&buffer).map_err(|e| {
core::ptr::drop_in_place(ptr);
e
})?;
core::ptr::drop_in_place(ptr);
Ok(())
}
}
pub fn load_bitstream_from_sd() -> Result<(), PlLoadingError> {
let sdio0 = sdio::Sdio::sdio0(true);