From 04437e876c10f4b142b42dbd5d18796581827713 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 1 Sep 2020 14:32:28 +0800 Subject: [PATCH] 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. --- src/libconfig/src/load_pl.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/libconfig/src/load_pl.rs b/src/libconfig/src/load_pl.rs index 8eaceae..6bbc5f8 100644 --- a/src/libconfig/src/load_pl.rs +++ b/src/libconfig/src/load_pl.rs @@ -140,16 +140,23 @@ pub fn load_bitstream( file: &mut File, ) -> Result<(), PlLoadingError> { let size = locate_bitstream(file)?; - let mut buffer: alloc::vec::Vec = alloc::vec::Vec::with_capacity(size); 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> {