Skip to content

Instantly share code, notes, and snippets.

@Samdal
Last active January 17, 2024 23:31
Show Gist options
  • Save Samdal/927e774812bb4cdaeb369391e186f43a to your computer and use it in GitHub Desktop.
Save Samdal/927e774812bb4cdaeb369391e186f43a to your computer and use it in GitHub Desktop.
generate nios2 build files
#!/usr/bin/env sh
# ------------------
# NOTE:
# you need to have certain binary files in your path
# see below, most of them are in your quartus/bin and nios2eds/bin and nios2eds/sdk2/bin
# for the compiler itself, it resides in nios2eds/bin/gnu/H-x86_64-pc-linux-gnu/bin/
# for me my path currently contains
# +- /opt/intelFPGA/21.1/nios2eds/bin
# +- /opt/intelFPGA/21.1/nios2eds/sdk2/bin
# +- /opt/intelFPGA/21.1/nios2eds/bin/gnu/H-x86_64-pc-linux-gnu/bin
# +- /opt/intelFPGA/21.1/quartus/bin
# +- /opt/intelFPGA/21.1/quartus/sopc_builder/bin
# +- /opt/intelFPGA/21.1/questa_fse/bin
# not sure if all of these are needed
#
# NOTE:
# you might also have to set your QUARTUS_ROOTDIR enviroment variable
#
# NOTE:
# there is a shell loader in nios2eds/nios2_command_shell.sh
# it might be worth using if you get some weird shell/enviorment errors
set -e
# check arguments
if [ -z "$1" ]
then
echo "you should provide the .sopcinfo file! 'make_build xxxx.sopcinfo'"
exit
fi
if [[ "$1" != *.sopcinfo ]]
then
echo "this script only accepts .sopcinfo file extensions!"
exit
fi
sopc="$1"
# bsp
echo "making bsp"
mkdir bsp
pushd bsp
nios2-bsp hal . "../$sopc"
make
popd
# software
echo "making software"
mkdir software
pushd software
echo -ne "int main()\n{\n\n}\n" > main.c
nios2-app-generate-makefile --bsp-dir=../bsp --src-dir=.
make
popd
# finish
echo "------------------"
echo "DONE!"
echo "Your software files are in './software'"
echo "you can build and upload by doing 'make download-elf' in that directory"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment