Intel SoC FPGAのGSRDユーザランド構築

先に紹介したUbuntu Mate 18.04 踊るデスクトップ上で、Intel SoC FPGA用のユーザランドを構築するメモ。組込の開発ではたいていガイド通りにはいかないので、柔軟に対応していく必要がある。

総合ガイド

Wikihttps://rocketboards.org/foswiki/Documentation/GSRDCompilingLinux
参考:https://service.macnica.co.jp/library/126489

Ubuntu Mateの準備

踊るデスクトップ機能は封印。MATE Tweak => ウィンドウ => Marco (Adaptive compositor)
Wikiではホームにワークディレクトリを作っているが、仮想マシンを柔軟に使っていく私の流儀では/opt/alteraに100GB程度の仮想HDDをマウントし、そこに全てを入れる。つまり、ワークディレクトリは/opt/altera/angstrom-buildとなる。

開発に必要なパッケージ

Wikiでは「phablet-tools」も入れているが、repoコマンドかその依存物をあてにしたものであり、不要なはず。他にも不要なものはあるが、パッケージが存在しているものは入れておく。

sudo apt instlal sed wget cvs subversion git-core coreutils unzip texi2html  texinfo libsdl1.2-dev docbook-utils gawk python-pysqlite2 diffstat help2man  make gcc build-essential g++ desktop-file-utils chrpath libgl1-mesa-dev  libglu1-mesa-dev mercurial autoconf automake groff libtool xterm lib32z1 lib32ncurses5 lib32stdc++6 
ユーザランド構築

以下、ユーザ権限で操作している。Wikiから変えたところはコメントしている。

## ワークディレクトリを/opt/altera/angstrom-buildとする。
mkdir /opt/altera/angstrom-build
cd /opt/altera/angstrom-build
wget http://releases.rocketboards.org/release/2019.04/src/altera.xml
wget http://commondatastorage.googleapis.com/git-repo-downloads/repo
chmod 777 repo
export PATH=$PATH:/opt/altera/angstrom-build

## repo init -u git://github.com/Angstrom-distribution/angstrom-manifest -b angstrom-v2018.06-sumo
## git ls-remote git://github.com/Angstrom-distribution/angstrom-manifest で確認したところ、
## 「angstrom-v2018.12-thud」という新しいブランチがあったので、そちらを指定する。
repo init -u git://github.com/Angstrom-distribution/angstrom-manifest -b angstrom-v2018.12-thud

mkdir -p .repo/local_manifests
mv altera.xml .repo/local_manifests/
repo sync

MACHINE=cyclone5 . ./setup-environment  ## <= cyclone5に変更した。

sed -i '/meta-altera/a \ \ ${TOPDIR}\/layers\/meta-altera-refdes \\' conf/bblayers.conf # This is to add the meta-altera-refdes layer to conf/bblayers.conf
sed -i '/meta-atmel/d' conf/bblayers.conf # this has conflicting packages
sed -i '/meta-freescale/d' conf/bblayers.conf # this has conflicting packages
echo "DISTRO_FEATURES_remove = \" wayland \"" >> conf/local.conf # broke builds prior to this not needed for GSRD
echo "DISTRO_FEATURES_remove = \" alsa \"" >> conf/local.conf # breaking builds prior to this not needed for GSRD

## 下記ファイルはもはや元から存在しない
# rm layers/meta-altera-refdes/recipes-devtools/socfpga-test/socfpga-test_1.0.bb # developmental unit tests stub for older kernels

export KERNEL_PROVIDER=linux-altera-ltsi
export KERNEL_TAG=refs/tags/ACDS19.1_REL_GSRD_PR
export KBRANCH=socfpga-4.14.73-ltsi
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE KBRANCH KERNEL_TAG UBOOT_TAG KERNEL_PROVIDER"

## meta-altera-refdes/recipes-alteraにある.bbファイルのメンテ不足でbitbakeができない。
## .bbファイル内で、「REFDES_BRANCH ?= "master"」などと、存在するbranch名を指定するか、
## もしくは、ベンチマーク用でおそらく不要なので削除する。以下では削除。
rm -rf /opt/altera/angstrom-build/layers/meta-altera-refdes/recipes-altera/*
  # [備考] もし削除したフィアルを復旧したければ、
  # pushd layers/meta-altera-refdes
  # git checkout .
  # popd

## ベーキング
bitbake gsrd-console-image 

あとはベーキング完了待ち。長いのは初回だけだが、気長に2時間〜約半日放置する。 待ち時間はホスト/ネットの環境次第。うまくいけば、
 deploy/glibc/images/cyclone5/
に各種イメージファイルが生成される。

Kernelの構築

bitbakeでKernelを作ることもできるが、新しいtoolchainを使ってKernelを構築する。理由:MicroSDイメージに含まれているKernelについては新しいtoolchainで構築されている。

###
###  toolchainを展開
###
mkdir /opt/altera/toolchain
cd /opt/altera/toolchain
wget https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
tar axf gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
## シンボリックリンクを作っておく。
ln -s gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin

###
### Kernel構築
###
cd /opt/altera
git clone https://github.com/altera-opensource/linux-socfpga
cd linux-socfpga
git checkout socfpga-4.14.73-ltsi
vi Makefile
  ## 下記2行を冒頭付近に追加
  # ARCH = arm
  # CROSS_COMPILE = /opt/altera/toolchain/bin/arm-linux-gnueabihf-
make socfpga_defconfig   ## Cyclone5 SoC デバイス向けのconfig
make -j3 zImage    ## -j オプションはCPUスレッド数-1が目安