# Building FSBL for a board (working procedure)

FSBL is a static, checked-in binary at board/tezuka/<board>/bitstream/fsbl.elf
-- no Buildroot package or maia-hdl Makefile step rebuilds it automatically
from the .xsa. It must be rebuilt manually whenever a board's .xsa changes
(DDR/MIO config, pinout) and the result checked in.

## Working method: xsct + create_fsbl_project.tcl

maia-hdl/projects/tezuka/create_fsbl_project.tcl already does this correctly
via Xilinx's hsi/app tooling (generates a full BSP including
xparameters_ps.h, which does NOT ship inside the .xsa zip itself -- see
"Broken manual method" below for why a plain `unzip` approach fails).

```bash
source /home/hp-z2-dev/prog/maia-sdr/sourceme.first   # also puts xsct on PATH
cd /home/hp-z2-dev/prog/maia-sdr/maia-hdl/projects/tezuka
xsct create_fsbl_project.tcl <board>
```

Produces build/sdk/fsbl/Release/fsbl.elf. Copy it to
board/tezuka/<board>/bitstream/fsbl.elf in this repo.

**Gotcha**: the script always uses `setws ./build/sdk` and `app create -name
fsbl` -- a fixed, non-board-namespaced workspace/app name. If build/sdk/
already holds an FSBL project (from a previous board, or a stale run), the
`app create` call fails with "A project with given name already exists in
the workspace" and does NOT touch the pre-existing fsbl.elf -- so it's easy
to mistake a stale, wrong-board fsbl.elf for a fresh one. Always check the
timestamp, or just `rm -rf build/sdk` (it's untracked build output) before
running, to guarantee a clean build.

## Broken manual method (do not use as-is)

The unzip-based approach below looks plausible but is missing a required
generated header:

```bash
git clone --depth 1 https://github.com/Xilinx/embeddedsw.git
mkdir fsbl_build
unzip -j your_hardware.xsa "*ps7_init.*" -d fsbl_build/
cp embeddedsw/lib/sw_apps/zynq_fsbl/src/* fsbl_build/
cd fsbl_build
export CROSS_COMPILE=arm-none-eabi-
make
```

This fails with `fatal error: xparameters_ps.h: No such file or directory`.
That header (PS7 peripheral base addresses etc.) is generated by Xilinx's
hsi/BSP tooling from the .hwh hardware-handoff file -- it's not present in
the .xsa zip, and the FSBL Makefile's BSP_DIR/BOARD layout
(`../misc/$(BOARD)/ps7_init.c`) also doesn't match a flat `fsbl_build/`
directory copied out of context. Use the xsct method above instead.
