4

I found in QEMU NIOS IP https://wiki.qemu.org/Documentation/Platforms/Nios2 I have downloaded intel tool chain from their website : https://www.intel.com/content/www/us/en/programmable/products/boards_and_kits/dev-kits/altera/kit-niosii-2s60.html I have few questions:

  1. Is the NIOS2 in QEMU IP matching intel’s NIOS IP ?
  2. What is the toolchain you use to compile and run it in QEMU ? Is it same tool-chain as provided by intel’s website ?
  3. How to general Firmware code and run it on NIOS over QEMU. In the Wiki it says: qemu-system-nios2 -M 10m50-ghrd -kernel -dtb -nographic
  4. How to generate dtb file for it?
  5. Do we need to take products created by the quartos/EDS for the running of the QEMU, other from the compiled binary? (DTB - board specification?)
  6. Do we need to run it with specific QEMU parameters/arguments ?
  7. Do you have code examples for NIOS using its peripherals?

Basically, I didn’t find any documentations/examples about how to use the NIOS2 in QEMU. Can you help with some additional info ? Even some basic “hello would” (compile and run in QEMU) would be great…

yehudahs
  • 2,488
  • 8
  • 34
  • 54
  • I thought I'd try this to debug something, but it's hard to find the toolchain from the old links. Here is some information: https://rocketboards.org/foswiki/Documentation/NiosIILinuxUserManual but sourcery codebench lite doesn't appear to be available in the usa right now – fuzzyTew Apr 02 '21 at 12:55
  • https://rocketboards.org/foswiki/Documentation/AlteraMAX1010M50RevCDevelopmentKitLinuxSetup appears to link to a linux image file for 10m50-ghrd, haven't tried it. the direct link is https://rocketboards.org/foswiki/pub/Documentation/AlteraMAX1010M50RevCDevelopmentKitLinuxSetup/vmlinux_rootfs.pof – fuzzyTew Apr 02 '21 at 12:59
  • That same link (2nd I pasted) also describes where the associated .dtb file is. it's in tag ACDS15.0_REL_GSRD_RC2 of https://github.com/altera-opensource/linux-socfpga at `arch/nios2/boot/dts/10m50_devboard.dts`. I'm guessing that github doesn't show that tag because the tag is so incredibly old. – fuzzyTew Apr 02 '21 at 13:13
  • This git repository luckily shows the commit hash of that tag: https://github.com/svjayasw/env22mar-viascript-/blob/184f560e58cb6b5bb4bb01416679592eec3e08f1/dunfell/bin/bin/linux-infra/portal-release/15.05.03/15.05.03_rc1_tag.sh . The commit is not on any branch or tag any more, but is still on github, and the associated .dts file is at https://github.com/altera-opensource/linux-socfpga/blob/d37310fa5250c484c508a519aac929cc0329c81a/arch/nios2/boot/dts/3c120_devboard.dts . – fuzzyTew Apr 02 '21 at 13:32
  • nope, my last comment doesn't seem accurate. that's 3c120 rather than 10m50 . thinking the commit hash is wrong. – fuzzyTew Apr 02 '21 at 13:40
  • This tool shows a tvmlinux.hex file inside the pof file: https://github.com/tomverbeure/aha363/blob/master/tools/pof_tool.py – fuzzyTew Apr 02 '21 at 13:54
  • I found nios2 toolchains listed at https://toolchains.bootlin.com/releases_nios2.html . Direct link: https://toolchains.bootlin.com/downloads/releases/toolchains/nios2/tarballs/nios2--glibc--stable-2020.08-1.tar.bz2 – fuzzyTew Apr 02 '21 at 14:01
  • This at least succeeds. All I see is a qemu prompt. There's no root filesystem yet: `wget https://toolchains.bootlin.com/downloads/releases/toolchains/nios2/tarballs/nios2--glibc--stable-2020.08-1.tar.bz2; tar -jxvf nios2--glibc--stable-2020.08-1.tar.bz2; git clone https://github.com/altera-opensource/linux-socfpga.git; cd linux-socfpga; make ARCH=nios2 CROSS_COMPILE=$(pwd)/../nios2--glibc--stable-2020.08-1/bin/nios2-linux- 10m50_defconfig 10m50_devboard.dtb vmlinux -j5; qemu-system-nios2 -M 10m50-ghrd -kernel vmlinux -dtb arch/nios2/boot/dts/10m50_devboard.dtb` – fuzzyTew Apr 02 '21 at 14:17
  • Here's something that's supposed to work: https://docs.zephyrproject.org/1.13.0/boards/nios2/qemu_nios2/doc/board.html – fuzzyTew Apr 02 '21 at 16:10
  • Adding `-append "earlycon=uart8250,mmio32,0x18001600,115200n8 console=ttyS0"` to get serial output, on the qemu command line, is mentioned at https://patchwork.kernel.org/project/qemu-devel/patch/62733dfe-5ccc-4d84-cc6e-92c100a1447e@roeck-us.net/ – fuzzyTew Apr 02 '21 at 16:40

1 Answers1

2

UPDATE: the most up-to-date answer to this question may be to analyse the linux console nios test at https://gitlab.com/qemu-project/qemu/-/blob/master/tests/acceptance/boot_linux_console.py#L1029 (or of course contact a maintainer). The kernel image from advent calendar 2018 day 14 runs great. It looks like it can all be done with buildroot.

My comments started bearing fruit, so I'll try to put a partial answer together. I haven't gotten this to work yet, but maybe this can be helpful to others who might work farther.

NOTE: If you just want to run a single nios2 binary, you can pass it straight to qemu-nios2. qemu-system-nios2 is for running linux.

  1. I believe the qemu behavior is functionality rather than intellectual property. It would be a bug if it mismatched. I do not know whether it does. Mentioning IP here, please remember that open source projects are generally run by a handful of vulnerable caring devs who usually have no legal team if ownership of intellectual property is challenged. If there's an issue, it would be polite to refer the concerning party to https://eff.org/ who often legally represents such things.
  2. I expect that any nios2 toolchain works. Here's a toolchain from a quick internet search that led me to bootlin.com. Appears to include instructions on how to duplicate it from source.
  3. See 4
  4. Here is what I have so far for firmware generation:
# set up a toolchain (note: this old step is redundant with buildroot, lower down, which also installs a toolchain and even builds a kernel if asked)
wget https://toolchains.bootlin.com/downloads/releases/toolchains/nios2/tarballs/nios2--glibc--stable-2020.08-1.tar.bz2
tar -jxvf nios2--glibc--stable-2020.08-1.tar.bz2

# get kernel sources (pass --depth 1 to speed up)
git clone https://github.com/altera-opensource/linux-socfpga.git

# build kernel and device tree
cd linux-socfpga
make ARCH=nios2 CROSS_COMPILE=$(pwd)/../nios2--glibc--stable-2020.08-1/bin/nios2-linux- 10m50_defconfig 10m50_devboard.dtb vmlinux -j5
cd ..

# kernel is now at linux-socfpga/vmlinux
# device tree is now at linux-socfpga/arch/nios2/boot/dts/10m50_devboard.dtb

# set up buildroot to build a root image
git clone https://github.com/buildroot/buildroot.git
cd buildroot

# configure for qemu nios2
make qemu_nios2_10m50_defconfig 

# build root image
PERL_MM_OPT= LDFLAGS= CPPFLAGS= LD_LIBRARY_PATH= make
cd ..

# rootfs images are now in buildroot/output/images/
  1. I'm afraid I'm just a visitor and I don't know who quartos/eds are or what compiled binary you are referring to.
  2. The qemu command line appears to be qemu-system-nios2 -M <machine> -kernel <kernel file> -dtb <dtb file> <rootfs image file>. The example machine is 10m50-ghrd which we built the kernel for above, and this may be the only one.
  3. not yet! i'll try to update this answer if i get farther. feel free to edit it if you get farther.
fuzzyTew
  • 3,511
  • 29
  • 24