#+title: PolarFire SoC FPGA
#+author: Penguin
#+date: 06/19/23
#+OPTIONS: ^:nil
* About the Board

#+attr_html: :width 50%
#+attr_html: :height 50%
[[./doc/img/PolarFire-Board.png]]

* Installing Libero (via portage)
* Installing Libero (MANUAL)
** Prerequisites

** Installation Process
#+begin_src bash
sudo mkdir -p /opt/Microchip
sudo chown $USER:$USER /opt/Microchip
unzip
#+end_src

Installer Directions:
- Install Directory: /opt/Microchip/Libero_SoC_v2023.1
- Common Directory: /opt/Microchip/common
- Install Set: Everything

** Post-Install
#+begin_src bash
sudo /opt/Microchip/Libero_SoC_v2023.1/Logs/req_to_install.sh
#+end_src

*** Installing FlashPro Drivers
You need to have the FlashPro device to install these, so ignore this if you don't have a FlashPro device.

**** FlashPro 5
#+begin_src bash
sudo /opt/Microchip/Libero_SoC_v2023.1/Libero/bin/udev_install
#+end_src

**** FlashPro 6
#+begin_src bash
sudo /opt/Microchip/Libero_SoC_v2023.1/Libero/bin/fp6_env_install
#+end_src

*** Installing Your License
You can register for a Microchip and request a year-long evaluation license here: https://www.microchipdirect.com/login?redirectTo=%2Ffpga-software-products

You'll want to get the *LIB-PL-MACID-F-EVAL* license, which is a floating linux license. If you're on windows, just get whatever license works for you.

#+begin_src bash
mkdir -p /opt/Microchip/Libero_SoC_v2023.1/license
cp /path/to/license /opt/Microchip/Libero_SoC_v2023/license
#+end_src

*** Installing the Licensing Daemon
# TODO: Replace these ubuntu instructions with gentoo instructions
#+begin_src bash
# install lsb-core
sudo apt install lsb-core
sudo cp scripts/libero-license.service /etc/systemd/user
#+end_src

* Install Yocto Ecosystem
** Prerequisites
#+begin_src bash
sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
     build-essential chrpath socat libsdl1.2-dev xterm bmap-utils python3-distutils repo
#+end_src

** Create the Yocto Workspace
#+begin_src bash
mkdir yocto-dev && cd yocto-dev
repo init -u https://github.com/polarfire-soc/polarfire-soc-yocto-manifests.git -b main -m default.xml
#+end_src

** Update the repo workspace
#+begin_src bash
repo sync
repo rebase
#+end_src

** Setup the Bitbake environment
#+begin_src bash
. ./meta-polarfire-soc-yocto-bsp/polarfire-soc_yocto_setup.sh
#+end_src

** Optimize your build environment
Yocto builds take a very long time. We can optimize this.

#+begin_src bash
mkdir -p ${HOME}/.local/share/yocto/downloads
mkdir -p ${HOME}/.local/share/yocto/sstate-cache
mkdir -p ${HOME}/.local/share/yocto/persistent
cd <project_root>/build/conf/


echo '
BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}"
PARALLEL_MAKE ?= "-j ${@oe.utils.cpu_count() - 1}"
DL_DIR = "${HOME}/.local/share/yocto/downloads"
SSTATE_DIR = "${HOME}/.local/share/yocto/sstate-cache"
PERSISTENT_DIR=${HOME/.local/share/yocto/persistent
SOURCE_MIRROR_URL ?= "file://${HOME}/.local/share/yocto/downloads"
INHERIT += "own-mirrors"
BB_GENERATE_MIRROR_TARBALLS = "1"
# uncomment to test sources
# BB_NO_NETWORK = "1"

# remove static deps
STATICLIBCONF = "--disable-static"
DISABLE_STATIC:pn-openssl = ""
DISABLE_STATIC:pn-openssl-native = ""
DISABLE_STATIC:pn-nativesdk-openssl = ""
DISABLE_STATIC:pn-libtalloc = ""
EXTRA_OECONF += "${STATICLIBCONF}"
' >> local.conf
#+end_src

** Build the Disk Image
#+begin_src bash
cd $PROOT
bitbake mpfs-dev-cli
#+end_src




* References
**** [[https://github.com/polarfire-soc/meta-polarfire-soc-yocto-bsp][PolarFire Yocto Github]]

* Creating a Bootable Yocto Linux Image
We have two options: Create a new workspace, or we can use this repo as a workspace because this repo is my working workspace.
** Create a workspace (OPTIONAL)
#+begin_src
mkdir yocto-dev && cd yocto-dev
repo init -u https://github.com/polarfire-soc/polarfire-soc-yocto-manifests.git -b main -m default.xml
#+end_src

** Update the repo workspace
#+begin_src bash
repo sync
repo rebase
#+end_src

** Set up the Bitbake environment
#+begin_src bash
. ./meta-polarfire-soc-yocto-bsp/polarfire-soc_yocto_setup.sh
#+end_src

** Building Board Disk Image

*** Building a Linux Image with a root file system (RootFS)
#+begin_src bash
MACHINE=icicle-kit-es bitbake mpfs-dev-cli
#+end_src

*** Building a RAM-based Root Filestystem
#+begin_src bash
MACHINE=icicle-kit-es bitbake -R conf/initramfs.conf mpfs-initramfs-image
#+end_src

*** Building a Linux Image for an external QSPI flash memory

*** Flashing an SD Card
#+begin_src bash
zcat build/tmp-glibc/deploy/images/icicle-kit-es/mpfs-dev-cli-icicle-kit-es.wic.gz | sudo dd of=/dev/sdX bs=4096 iflag=fullblock oflag=direct conv=fsync status=progress
#+end_src
* References
**** [[https://github.com/polarfire-soc/meta-polarfire-soc-yocto-bsp][PolarFire SoC Yocto]]

****
