plops / build_pluto_firmware

generate fpga bitstream and linux image for adalm pluto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contents

filecompletenesscomment
pluto_tuiexperiment to visualize fft using unicode characters on terminal
captureacquire and trigger data on pluto, send packets via socket (2020 Nov)
capture220%revisit embedded program (2022 Sep), cmake works, i need to learn more about libiio and ASIC
gl_oscivisualize data that was acquired by capture with opengl
README.orgfirst attempt to build firmware and hdl on fedora 32 (2020 Nov)
README_popos.org80%second attempt (i think succesfull) to build firmware and hdl on ubuntu 22 (2022 Sep)
README_docs.org90%document how to convert libiio docs to dash format (for fast search)
README_sdrangel.org70%document how to compile sdsangel with pluto support
README_cross_comp_fedora.org50%document how to cross compile embedded C code for pluto (using only rootfs and toolchain)

Note on the history of this code

  • I think I gave up development in Nov 2020 when I realized that the local oscillators for TX and RX are different. This would make experiments with a radar quite complicated.
  • In Sep 2022 I learned of a new hardware revision that has two additional connectors for one more RX and one more TX channel. Perhaps those can be used to recover the oscillator drift, making radar experiments feasible again.

Old development log (from Nov 2020)

master	        Quartus 18.1	Vivado 2019.1	Release Notes	master
hdl_2019_r1	Quartus 18.1	Vivado 2018.3	Release Notes	2019_r1 (*)
hdl_2018_r2	Quartus 18.0	Vivado 2018.2	Release Notes	2018_r2
hdl_2018_r1	Quartus 17.1.1	Vivado 2017.4.1	Release Notes	2018_r1
hdl_2017_r1	Quartus 16.1	Vivado 2016.4	Release Notes	2017_r1
hdl_2016_r2	Quartus 16.0	Vivado 2016.2	Release Notes	2016_r2
hdl_2016_r1	Quartus 15.1	Vivado 2015.4.2	Release Notes	2016_r1
hdl_2015_r2	Quartus 15.0.2	Vivado 2015.2	Release Notes	2015_r2
hdl_2015_r1	Quartus 14.1	Vivado 2014.4.1	Release Notes	2015_r1
hdl_2014_r2	Quartus 14.0	Vivado 2014.2	Release Notes	2014_r2
hdl_2014_r1	Quartus 14.0	Vivado 2013.4	Release Notes	2014_r1
  • i need to get vivado 2018.3
  • to install:
[martin@localhost pluto]$ cat /etc/os-release
#NAME=Fedora
NAME=Ubuntu
#VERSION="32 (Thirty Two)"
VERSION="18.04.4 LTS (Bionic Beaver)" 
  • build fpga bitstream
git clone https://github.com/analogdevicesinc/hdl/
git checkout    remotes/origin/hdl_2019_r1

git clone --recursive https://github.com/analogdevicesinc/plutosdr-fw.git
#git clone https://github.com/analogdevicesinc/plutosdr-fw/
#git submodule update --init --recursive
#cd hdl
#git checkout    remotes/origin/hdl_2019_r1
#cd ../linux
#git checkout remotes/origin/2019_R1
dnf  install ccache dfu-util fakeroot help2man rsync cpio file \
             bison flex uboot-tools ncurses-compat-libs patch \
	     perl-ExtUtils-MakeMaker
  HOSTLD  scripts/dtc/dtc
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
comment out linux/scripts/dtc/dtc-lexer.l 
YYLTYPE yylloc;
  • make sure the current cwd is not in LD_LIBRARY_PATH
  • it seems like the current plutosdr-fw needs VIVADO_VERSION ?= 2019.1
  • someone else compiling pluto:

https://manual.hnap.de/building_the_fw/ https://hamnetdb.net/map.cgi https://hnap.de/assets/pdf/Masterthesis%20-%20Design%20of%20a%20Radio%20Communications%20Protocol%20for%20HAMNET%20Access%20in%20the%2070cm%20Amateur%20Radio%20Band.pdf

make -C buildroot ARCH=arm zynq_pluto_defconfig
make -C buildroot ARCH=arm menuconfig
/
headers_4_9 
2 # (external)
enter

Toolchain->gcc 7.x

# i also enabled tcpdump and gdb
# next time i might want to add strace as well (note: it's already included)

# overwrite original config
make -C buildroot savedefconfig
  • final size of plutosdr-fw is 7.9G
  • how to boot from a fresh build

https://wiki.analog.com/university/tools/pluto/devs/reboot

  • updating firmware according to usb standard (in case the normal firmware update fails)

https://wiki.analog.com/university/tools/pluto/users/firmware#dfu_update

  • before new firmware:
[root@localhost pluto_hdl]# ssh 192.168.2.1
root@192.168.2.1's password: 
Welcome to:
______ _       _        _________________
| ___ \ |     | |      /  ___|  _  \ ___ \
| |_/ / |_   _| |_ ___ \ `--.| | | | |_/ /
|  __/| | | | | __/ _ \ `--. \ | | |    /
| |   | | |_| | || (_) /\__/ / |/ /| |\ \
\_|   |_|\__,_|\__\___/\____/|___/ \_| \_|

v0.31
http://wiki.analog.com/university/tools/pluto
# uname -ab2/191127_
Linux pluto 4.14.0-42540-g387d584 #301 SMP PREEMPT Wed Jul 3 15:06:53 CEST 2019 armv7l GNU/Linux
# fw_printenv fit_config
fit_config=config@9

# index.html on mass storage

Model 	Analog Devices PlutoSDR Rev.B (Z7010-AD9364)
Serial 	104400b83991000b0d000f00bbd8642eff
Build 	v0.31
Linux 	Linux pluto 4.14.0-42540-g387d584 #301 SMP PREEMPT Wed Jul 3 15:06:53 CEST 2019 armv7l GNU-Linux;1 core(s)
U-Boot 	U-Boot PlutoSDR v0.20-PlutoSDR-00043-gefdb9e8 (Dec 18 2017 - 18:25:09 +0100)
FPGA 	2018_r2-20-g28df75
Root FS 	2019.02.2-388-gb31cc4
IIO 	Library version: 0.18 (git tag: v0.18)
Back to top

Standalone Applications:

Custom C/C++ applications can be created/compiled on a host with a Linaro GNU Compiler Collection (GCC) toolchain (with the appropriate flags), transferred over and run directly on the PlutoSDR.
GCC Compiler Target Triple 	arm-linux-gnueabihf
GCC version 	Linaro GCC 7.2-2017.11-rc1 7.2.1 20171011
Binutils version 	Linaro_Binutils- 2.29.1.20171214
SysRoot 	Old Sysroot for firmware v0.31 (please upgrade firmware to v0.32)
  • start to update firmware

https://wiki.analog.com/university/tools/pluto/users/firmware

  • Copy the pluto.frm file onto the mass storage device, and then eject it. LED1 will start blinking rapidly.
  • WAIT 4 minutes for firmware to update
  • i started at 21:31
  • it finished faster (21:33 or so)
v0.32-dirty
# uname -a
Linux pluto 4.19.0-g6edc6cd24b48-dirty #1 SMP PREEMPT Sat Oct 24 14:07:50 CEST 2020 armv7l GNU/Linux

  • persistent ssh host keys and root login

https://wiki.analog.com/university/tools/pluto/users/customizing#enabling_persistent_ssh_keys

# on host
cd ~/.ssh; ssh-keygen -f id_pluto
# into ~/.ssh/config:
Host pluto
     HostName 192.168.2.1
     User root
     IdentityFile ~/.ssh/id_pluto
# copy and paste: ssh-rsa AAAAB3
cat id_pluto.pub 

# on device
device_format_jffs2
mkdir /root/.ssh
echo "ssh-rsa AAAAB3... martin@localhost.localdomain" > /root/.ssh/authorized_keys
chmod og-rwx /root/.ssh
chmod og-rwx /root/.ssh/authorized_keys
device_persistent_keys
  • create key on pluto
dropbearkey -f id_pluto2 -t ecdsa -s 256
# Generating 256 bit ecdsa key, this may take a while...
# Public key portion is:
# ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBE5tGMUUZhn2hljzdcYE4uhJjWlYlwHtuYobpv/c8fFOmP1PyGcU+5mZyLJo6W1x7lt6DIJTVsOyTk4qwMCfbrY= root@pluto
# Fingerprint: sha1!! ea:f7:55:0d:f8:c0:2a:91:c5:5f:3d:0c:a6:2c:3e:bd:85:a5:c3:a3

# copy paste the public key into /root/.ssh/authorized_keys
device_persistent_keys
# copy private key to laptop and convert to openssh
sudo dnf install dropbear
dropbearconvert dropbear openssh id_pluto2.dropbear id_pluto2

  • install sdrangel
sudo dnf install qt5-devel fftw-devel opus-devel libusb-devel
# find libavcodec
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:/usr/local/lib64/pkgconfig/

git clone https://github.com/analogdevicesinc/libiio
git clone https://github.com/f4exb/cm256cc.git
cd cm256cc;git reset --hard c0e92b92aca3d1d36c990b642b937c64d363c559

git clone https://github.com/f4exb/serialDV.git
cd serialDV;git reset --hard "v1.1.4"

git clone https://github.com/f4exb/dsdcc.git
cd dsdcc
git reset --hard "v1.9.0"

git clone https://github.com/drowe67/codec2.git
cd codec2
git reset --hard 76a20416d715ee06f8b36a9953506876689a3bd2



git clone https://github.com/f4exb/sdrangel

# override ffmpeg version check in plugins/channelrx/CMakeLists.txt:
   message(STATUS "Include demoddatv")
    add_subdirectory(demoddatv)
      # if(WIN32)
      #   add_subdirectory(demoddatv)
      # else()
      #   if((AVUTIL_VERSION VERSION_GREATER "55.27.99") AND (AVCODEC_VERSION VERSION_GREATER "57.48.101"))
      #       message(STATUS "Include demoddatv")
      #       add_subdirectory(demoddatv)
      #   else()
      #       message(STATUS "FFmpeg too old to compile demoddatv; needs at least avutil: 55.27.100, avcodec/avformat: 57.48.101")
      #   endif()
      # endif()

# new intels always need peformance governor
dnf install kernel-tools
cpupower frequency-set -g performance

# increase fan speed during compilation
rmmod thinkpad_acpi
modprobe thinkpad_acpi fan_control=1
echo "level 7" > /proc/acpi/ibm/fan
cd /home/martin/src/plutosdr-fw/hdl/library/axi_ad9361
vivado 
# in tcl console
source axi_ad9361_ip.tcl 
  • this closes the vivado window
  • try line by line
cd /home/martin/src/plutosdr-fw/hdl/library/axi_ad9361
vivado
# in tcl console:
source ../scripts/adi_env.tcl
# check the main directory
puts $ad_hdl_dir
# => /home/martin/src/plutosdr-fw/hdl

# this still works:
source $ad_hdl_dir/library/scripts/adi_ip_xilinx.tcl

# here vivado closes:
adi_ip_create axi_ad9361

  • again, more manual:
cd /home/martin/src/plutosdr-fw/hdl/library/axi_ad9361
vivado
source ../scripts/adi_env.tcl
source $ad_hdl_dir/library/scripts/adi_ip_xilinx.tcl
version -short
# => 2018.3
puts $REQUIRED_VIVADO_VERSION
# => 2019.1
  • so apparently i have the wrong vivado version
  • override this check
cd /home/martin/src/plutosdr-fw/hdl/library/axi_ad9361
vivado
source ../scripts/adi_env.tcl
set IGNORE_VERSION_CHECK true
source $ad_hdl_dir/library/scripts/adi_ip_xilinx.tcl
adi_ip_create axi_ad9361


  • now it loads things but not all
  • try again with top level tcl
cd /home/martin/src/plutosdr-fw/hdl/library/axi_ad9361
vivado 
set IGNORE_VERSION_CHECK true
source axi_ad9361_ip.tcl 
  • this takes a few minutes (seems rather slow)
  • synthesis doesn’t really seem to succeed
[martin@localhost plutosdr-fw]$ git branch -a
master
[martin@localhost hdl]$ git branch -a
(HEAD detached at 847f0f22)
  master
  • lets try cross compiling
  • where are the headers?
[martin@localhost plutosdr-fw]$ find .|grep /iio.h$
./linux/include/config/iio.h
./linux/include/linux/iio/iio.h
./buildroot/output/build/libiio-0.21/iio.h
./buildroot/output/build/buildroot-config/br2/package/libad9361/iio.h
./buildroot/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include/iio.h (*)

  • i think ./buildroot/output/host/arm-buildroot-linux-gnueabihf/sysroot/ contains headers for the target
source ~/stage/build_pluto_firmware/set.sh
unset LD_LIBRARY_PATH
# try to enable ncurses on target, enable wide char support (for images)
make -C buildroot ARCH=arm menuconfig
make -C buildroot savedefconfig
make
  • it seems to download the fpga bitstream from github:
cp linux/arch/arm/boot/dts/zynq-pluto-sdr-revc.dtb build/zynq-pluto-sdr-revc.dtb
wget -T 3 -t 1 -N --directory-prefix build http://github.com/analogdevicesinc/plutosdr-fw/releases/download/v0.32/system_top.hdf
URL transformed to HTTPS due to an HSTS policy
--2020-10-25 09:29:41--  https://github.com/analogdevicesinc/plutosdr-fw/releases/download/v0.32/system_top.hdf

# final output
-rw-rw-r--. 1 martin martin  11281584 Oct 25 09:30 pluto.frm

arm-linux-gnueabihf-g++ -c -o vis_00_base.o vis_00_base.cpp -O2 -std=gnu++17 -Wall -Wextra -Werror -Wfatal-errors -ffunction-sections -fdata-sections -Wno-error=unused-variable -Wno-error=unused-parameter -Wno-error=double-promotion -pipe --sysroot=/home/martin/src/plutosdr-fw/buildroot/output/host/arm-buildroot-linux-gnueabihf/sysroot -I. -MM

vis_00_base.o: vis_00_base.cpp utils.h globals.h \
 libmems/iio_context_impl.h libmems/export.h libmems/iio_context.h \
 base/macros.h libmems/iio_device.h base/containers/flat_map.h \
 base/check.h base/base_export.h base/compiler_specific.h \
 build/build_config.h base/dcheck_is_on.h base/immediate_crash.h \
 base/containers/flat_tree.h base/ranges/algorithm.h \
 base/ranges/functional.h base/ranges/ranges.h base/template_util.h \
 base/stl_util.h base/optional.h libmems/iio_device_impl.h \
 libmems/iio_device_trigger_impl.h libmems/iio_device.h

  • try to download chromium zip from github (its 1.3G), 3.8GB extracted
  • it doesnt contain libmems
  • full dependencies (with the few headers i included so far)
vis_00_base.o: vis_00_base.cpp utils.h globals.h \
 libmems/iio_context_impl.h libmems/export.h libmems/iio_context.h \
 /mnt/chromium-master/base/macros.h libmems/iio_device.h \
 /mnt/chromium-master/base/containers/flat_map.h \
 /mnt/chromium-master/base/check.h \
 /mnt/chromium-master/base/base_export.h \
 /mnt/chromium-master/base/compiler_specific.h \
 /mnt/chromium-master/build/build_config.h \
 /mnt/chromium-master/base/dcheck_is_on.h \
 /mnt/chromium-master/base/immediate_crash.h \
 /mnt/chromium-master/base/containers/flat_tree.h \
 /mnt/chromium-master/base/ranges/algorithm.h \
 /mnt/chromium-master/base/ranges/functional.h \
 /mnt/chromium-master/base/ranges/ranges.h \
 /mnt/chromium-master/base/template_util.h \
 /mnt/chromium-master/base/stl_util.h \
 /mnt/chromium-master/base/optional.h \
 /mnt/chromium-master/base/files/file_path.h \
 /mnt/chromium-master/base/strings/string16.h \
 /mnt/chromium-master/base/strings/string_piece.h \
 /mnt/chromium-master/base/check_op.h \
 /mnt/chromium-master/base/strings/char_traits.h \
 /mnt/chromium-master/base/strings/string_piece_forward.h \
 libmems/iio_device_impl.h libmems/iio_device_trigger_impl.h \
 libmems/iio_device.h
  • pip install pyadi-iio
import adi
p = adi.Pluto()
p.rx_rf_bandwidth=4_000_000
p.rx_lo = 200_000_000
p.tx_lo = 200_000_000
p.disable_dds()
#p.tx_cyclic_buffer = True
p.gain_control_mode = "slow_attack"
data = p.rx()
  • this seems to give a good overview of the pluto devices

https://github.com/analogdevicesinc/pyadi-iio/blob/master/adi/ad936x.py

  • enable fftw-single and optimize for speed
cd /home/martin/src/plutosdr-fw/buildroot/output/build/ncurses-6.1
./configure --target=arm-buildroot-linux-gnueabihf --host=arm-buildroot-linux-gnueabihf --build=x86_64-pc-linux-gnu \
  --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --localstatedir=/var --program-prefix= --disable-gtk-doc \
  --disable-gtk-doc-html --disable-doc --disable-docs --disable-documentation --with-xmlto=no --with-fop=no \
  --disable-dependency-tracking --enable-ipv6 --disable-nls --disable-static --enable-shared --without-cxx \
  --without-cxx-binding --without-ada --without-tests --disable-big-core --without-profile --disable-rpath \
  --disable-rpath-hack --enable-echo --enable-const --enable-overwrite --enable-pc-files --disable-stripping \
  --with-pkg-config-libdir=/usr/lib/pkgconfig --without-progs --without-manpages --with-shared --without-normal \
  --without-gpm --without-debug

[martin@localhost ncurses-6.1]$ ./configure --help|grep char
  --enable-widec          compile with wide-char/UTF-8 code
  --with-ccharw-max=XXX   override size CCHARW_MAX
  --enable-signed-char    compile using signed Boolean's in term.h

  • it should have –enable-widec but i don’t see this here
  • look how BR2_PACKAGE_NCURSES_WCHAR propagates through buildroot

hdl

  • installed 2019.1 vivado. seems to build the hdl file
  • i can open pluto.xpr in vivado and look at the rtl schematic and the synthesis results (floor plan)

About

generate fpga bitstream and linux image for adalm pluto


Languages

Language:C++ 54.1%Language:Common Lisp 42.4%Language:Makefile 2.3%Language:Shell 0.5%Language:CMake 0.3%Language:Python 0.3%