Starting with the algorithm:
We start with C source code, just a line by line instruction set about some specific topic. Our topic is a charge comparison algorithm that takes in data (CSV files, time & amplitude) from a directory, loops through 3 passes and returns a PSD value (above a certain threshold results in a neutron, below that threshold is a gamma ray). This function can be performed much quicker, with a large number of files in our CSV directory, by programmable logic on an FPGA development board.
In order to create an executable program, our C program must be compiled.
A compiler is a computer program that transforms source code written in a programming language (C in our case) into another computer language with the latter having a binary called object code. The compiler we use is software called 'Make' a build automation tool that automatically builds executable programs from source code by reading Makefiles.
LOADING PYTHON ONTO THE ZEDBOARD (CROSS-COMPILING)
In addition, if a compiled program can run on a computer whose CPU or operating system is different from the one which the compiler runs, the compiler is known as a cross-compiler. In order to get Python running on the board, I had to cross-compile Python (done on my host-machine, so that it could be used on the ARM processor of the Zedboard). The Makefile and source code for cross-compiling Python on a Zynq processor can be found here (but keep reading first):
https://github.com/imrickysu/
Follow the detailed instructions from my blog Things We Should All Know (Petalinux) for creating a petalinux project and configuring it if you need help (I will go through them quickly here but less detailed):
1. Create a petalinux-project:
- petalinux-create --type project --template zynq --name <Project Name>
- petalinux-config --get-hw-description=<path to hw description>
- Select U-boot configuration --> netboot offset
- Change the offset to 0x200000
- The offset needs to be changed because it controls where the data is stored/retrieved on the Zedboard itself. Basically, the image is stored on the SD card (which has 4 GB storage and should be using less than 20MB). It is then transferred to memory (typically starting at address 0x0000 0000), then is unpacked and loaded at the location 'loadaddr'. If the compressed image is large enough, then it has data at loadaddr so when the image is unpacked, part of it is overwritten by the uncompressed image and gets compromised. Changing the loadaddr to a larger number prevents this from happening.
- petalinux-config -c kernel
- deselect networking
2. Navigate to petalinux project directory: Create app:
petalinux-create -t apps -n python-2.7.3 --enable
3. Copy all files in this github directory to: <petalinux-project-directory>/
components/apps/python-2.7.3
***Note: The Makefile from the link is not correct. There is a PATCH_URL on line 11 that leads to a broken link:
The correct path is:
However, not only can you simply change the PATCH_URL in the Makefile, you have to continue on and let the build FAIL once. There will be an error in Step 3 (next step) do not worry we will fix it).
3. Build the whole image:
petalinux-build
4. If any errors occur (there will be) during the build process, the log of the build process can be checked in: build/build.log
4a. The build log will tell you that there was only garbage found in the patch (literally that's what it says).
[ALL ] patch: **** Only garbage was found in the patch input.
4b. To fix, copy the Python-2.7.3-xcompile.patch from https://github.com/sjkingo/ python-arm-xcompile/blob/ master/files/Python-2.7.3- xcompile.patch (the same path as above in step 2) to the directory (this will replace the old patch file, which is a dead html file because the link to he original path is broken):
<petalinux-project-directory>/build/linux/rootfs/apps/python-2.7.3
4c. The file size will change from 94.5 KB to 11.1 KB, and you are ready to build again.
4d. Run the command petalinux-build -c rootfs/ inside your petalinux project directory once more.
5. Before packaging the bitstream and copying the files to an SD Card there is one more step for python.
5a. Navigate to <petalinux-project-directory/build/linux/rootfs/targetroot/home/root/ and create a file called '.profile' using gedit or VIM. Inside the file, copy the line
export LD_LIBRARY_PATH=$LD_LIBRARY_ PATH:/usr/local/lib
5b. Save the file and quit.
5c. Type the command (n petalinux proj directory) petalinux-build -x package
8. Continue on the steps in Things We Should All Know (Petalinux)
- petalinux-package
- Copy files onto SD Card
9. Connect to a PuTTy terminal and press enter, type root for UN and root for PW.
10. Python will load just by typing "python" in the command line. The focus now is to load the libraries needed for the PSD algorithm. Because of no internet connectivity and the fact that Petalinux is relatively bare-bones (no yum, apt-get, install), we need to load the libraries into the correct directories before packaging the Petalinux image so that the OS comes pre-loaded with numpy, scipy, etc. In order to do this, we may need to edit the Makefile that comes from the github files.
No comments:
Post a Comment