-
Notifications
You must be signed in to change notification settings - Fork 1
petalinux setup notes
These are some rough notes on how to compile and boot (peta)linux from an SD card on the Trenz SoC. Note that I am running this in Ubuntu 18.04.
These notes are based on installing and running petalinux 2018.3. Installing simply consists of downloading the petalinux-v2018.3-final-installer.run file from xilinx, and executing that file. This unpacked files and directories to the location the installer was run for me, although there may have been a choice to install to a specific location. Petalinux does not seem to require Vivado or any other Xilinx tools, although Vivado outputs are required to build.
This could be only a linux or ubuntu thing, but after installing, petalinux-config did not work, and the complaint was related to not finding bitbake. If you experience this error, it may be fixed with the following hack: if petalinux was installed to PETALINUX_ROOT
, then:
$ ln -s $PETALINUX_ROOT/components/yocto/source $PETALINUX_ROOT/components/yocto/source/arm`
Check your project directory's build/ directory for logs if you run into other errors.
One error to note: petalinux requires python2
to be the default python!
The petalinux project is already created!!! Just go to the ComPair-tracker-FPGA source root, and from there the project should be in src/petalinux/si-layer
But if you want to build a new project anyways:
From within the petalinux install directory, run source settings.sh
. Then
petalinux-create --type project --template zynq --name <PROJECT-NAME>
After exporting hardware from vivado, zynq.sdk/ will be created somewhere under the vivado project work directory. Now, from within the new petalinux project directory, configure petalinux to use that hardware:
petalinux-config --get-hw-description=<PATH-TO-zynq.sdk-DIRECTORY>
This will bring up some menus.
In the menu, got to Subsystem Hardware Settings -> Serial Settings, and make sure ps7_uart0 is set for primary stdin/stdout
The default setting has the filesystem in ram, so nothing is persistent. To use a filesystem on disk, from the root menu: Image Packaging Configuration -> Root filesystem type. Select "SD card". The device node of SD device should be /dev/mmcblk0p2
You can select different packages to build and include with linux. To select packages, run:
petalinux-config -c rootfs
Tips:
- Filesystem Packages -> misc to find packagegroup-core-buildessential (to install gcc and friends).
- Basic system utils can also be found in Filesystem Packages -> console -> utils.
-
bash
: Fileystem Packages -> base -> shell -> bash -
avahi
: Filesystem Packages -> network -> avahi
If you go nuts and select too many things it will take a long time to build petalinux.
NOTE: The following steps for customizing the kernel are not necessary, as we have stepped back from using uio!!!
Run
petalinux-config -c kernel
To setup fpga programming from linux
Go through the menu: Device Drivers -> Userspace I/O drivers. Then select:
- <*> Userspace I/O platform driver with generic IRQ handling
- <*> Userspace platform driver with generic irq and dynamic memory Then exit to build changes.
Modify the file $PROJECT_ROOT/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
...
Currently testing the following w/gpio to receive interrupts through uio:
/include/ "system-conf.dtsi"
/ {
chosen {
bootargs = "console=ttyPS0,115200 earlyprintk root=/dev/mmcblk0p2 rw rootwait uio_pdrv_genirq.of_id=generic-uio";
};
};
&axi_gpio_0 {
compatible = "generic-uio";
};
From the project directory, run petalinux-build
.
After building, images/linux directory should be created and populated. From the petalinux project root, run:
petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/system.bit --u-boot --force
This should create images/linux/BOOT.BIN
Follow the directions here to partition the SD card:
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841655/Prepare+Boot+Medium
This will create a boot partition, and a second, ext4 partition for the rootfs.
You only need to follow those instructions through executing the mkfs.ext4 -L root /dev/sdX2
command.
Now, insert the SD card into your computer and mount the boot partition. Copy images/linux/BOOT.BIN and /images/linux/image.ub to the boot partition.
Determine the device file for the second partition (MAKE SURE THAT YOU PICK THE CORRECT ONE AND DON'T ACCIDENTALLY WRITE OVER YOUR COMPUTER'S HARDDRIVE!!!). In my example command below, the device file is /dev/sde2, but yours will be different! Run a command like:
dd if=images/linux/rootfs.ext4 of=/dev/sde2
The rootfs filesystem created by petalinux is too tiny (as built, I was at ~300M), and limits the available space. To use the entire SD card, after running the above dd
command, run gparted
. Click on the partition the rootfs is on, and there should be a warning indicator on that partition's label. Then, in the menu: partition -> check. Then write the changes. This should expand filesystem to use the entire card.
If there are any modifications you want to make to the filesystem, mount it and move files over, or edit them. For example, I have an /etc/network/interfaces file that I put onto the rootfs to set the board's static ip (I'm sure there's a way to set this in petalinux, but this is the lazy option).
To boot from SD, the TE0703-05's DIP switch #4 must be flipped to ON. On checking my current board configuration, all 4 switches are actually on.
Stick in the SD card and power it on! You should plug in the USB cable and try and get a console. The default BAUD rate is 115200, so this is one way to log on, if ttyUSB3 is what shows up when you plug in the usb cable:
screen /dev/ttyUSB3 115200
There are no user accounts setup at this point, so login with root, which is setup with the default password root (I think... I'm remembering this from weeks ago)
Currently, all c-code targeting the arm is contained in a petalinux app named vatactrl
. It is possible to compile all of vatactrl
's executables without building anything else in petalinux with the following:
petalinux-build -c vatactrl -x compile
This will compile binaries that run on the arm ps, and will place them in the following obvious place:
$(PETALINUX_PROJECT_ROOT)/build/tmp/work/cortexa9hf-neon-xilinx-linux-gnueabi/vatactrl/1.0-r0/build/src
Here are some notes on modifications that I've made to the built petalinux system, which tends to be helpful
Setting up password-less ssh'ing onto the si-layer system is straightforward (put your pubkey on si-layer, in /home/root/.ssh/authorized_keys). Setting up passwordless ssh'ing from the si-layer system is different, since we build the system to use dropbear (lightweight ssh server/client).
First, use dropbearkey
to generate you ssh key on the si-layer:
dropbearkey -t rsa -f ~/.ssh/id_rsa
Now create your public key to share:
dropbearkey -y -f ~/.ssh/id_rsa | grep “^ssh-rsa ” >> ~/.ssh/id_rsa.pub
The id_rsa.pub file can then be placed on the machine's you want to ssh into from the si-layer in the usual way.
Now, when ssh'ing from the si-layer, you have to specify that you want to use the given ssh key:
ssh -i ~/.ssh/id_rsa USER@HOST
To avoid using the -i
option, either create an alias for ssh, or make a link in .ssh for id_rsa -> id_dropbear
Files under /etc/profile.d
get run when starting a login shell. This seems to be the way to setup session preferences, instead of using a .bashrc. For example, I have the following contents in a file /etc/profile.d/my_profile.sh
:
export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
alias ls='ls --color=auto'
alias ll='ls -l'
alias python='python3'
export PATH=$HOME/bin:$HOME/scripts:$PATH
In order to setup the board with a static IP, you need to edit /etc/network/interfaces. The next steps are written from memory, so they are probably more in the spirit of what to put in the interfaces file, than what is exactly needed.
To edit the file, you can either start up the board, and login via the uart interface. The other alternative is to mount the SD card while it is plugged in to your computer.
Let's assume the interface name is eth0
. It could be something else... you can check with the ip a
command what it actually is while logged in over uart.
Now, assume you want to use IP address 192.168.1.99. Then, include the following stanza in the interfaces file:
auto eth0
iface eth0 inet static
address 192.168.1.99
netmask 255.255.255.0
You may also need to specify a gateway or broadcast? I will update once I can see what was done
Once the export_hardware stage of make has completed, the binary can be updated without re-running petalinux-build. The BOOT.BIN and image.ub files on /dev/mmcblk0p1 need to be re-generated and copied over. After the export_hardware stage of make: source \settings.sh From the ComPair-tracker-FPGA/src/petalinux/si-layer/ directory run:
./import_hardware && petalinux-build -c u-boot && ./package_peta
This will re-create the ComPair-tracker-FPGA/src/petalinux/si-layer/images/linux/BOOT.BIN and ComPair-tracker-FPGA/src/petalinux/si-layer/images/linux/image.ub files needed.
For the scp and ssh steps, it is nice to have the ssh keys set up on the target's authorized_users list. To Move the files over to the running system, assuming the sdcard has been correctly mounted on the zynq, run:
./scp_uboot
To Reboot the target, run
echo reboot | ssh [email protected]
The single command to do all of this is:
./import_hardware && petalinux-build -c u-boot && ./package_peta && ./scp_uboot && echo reboot | ssh [email protected]