Similar topics

Recent Changes

Table of Contents

This page provides information about running Nios II Linux on Cyclone III FPGA Development Kit (3C120 board).

Please refer to NiosII Linux User Manual on how to download and compile Linux kernel and components.

Configure FPGA with a Nios II MMU design

You will need Altera tools to configure the FPGA on the 3C120 board. Download and install the tools from Altera .
Download the Nios II MMU design for 3C120 board from Nios II with Memory Management Unit (MMU) Design Example

The SOF file is available in qsys_ghrd_3c120 folder. Configure FPGA with the following command:
nios2-configure-sof ghrd_3c120.sof

To boot Nios II Linux from CFI flash

You will need Altera tools to program the CFI on the 3C120 board. Download and install the tools from Altera .
First, you need to convert the boot images to SREC format(.flash file) before you can use the nios2-flash-programmer to program to CFI flash.
You will also need to determine the location of boot images in the CFI flash address map. Based on the Nios II MMU hardware design, we will use the following address map with CFI base address at 0x0 and CPU reset address at 0x02800000. U-Boot is the first boot image and will need to be program to the CPU reset address.
Offset Content
0x00200000 DTB
0x00300000 Linux kernel
0x00800000 JFFS2 filesystem
0x02800000 U-Boot
To convert the following files to SREC format:
bin2flash --input=3c120_devboard.dtb --output=3c120_devboard.flash --location=0x00200000
bin2flash --input=vmImage --output=vmImage.flash --location=0x00300000
bin2flash --input=rootfs.jffs2 --output=rootfs.jffs2.flash --location=0x00800000
elf2flash --base=0x0 --end=0x03FFFFFF --boot=<Altera_ACDS_installation_path>/ip/altera/nios2_ip/altera_nios2/boot_loader_cfi.srec
--reset=0x02800000 --input=u-boot --output=u-boot.flash

To use the nios2-flash-programmer :
nios2-flash-programmer --base=<base_address> --mmu <flash_image>

To boot Nios II Linux : Start nios2-terminal and press CPU reset on board.
U-boot will run and load the Linux kernel from CFI flash by default and you can login as root.
$ nios2-terminal
nios2-terminal: connected to hardware target using JTAG UART on cable
nios2-terminal: "USB-Blaster [USB-0]", device 1, instance 0
nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)

U-Boot 2013.01.01-00007-gb96b3b6-dirty (Apr 19 2013 - 10:27:57)

CPU : Nios-II
SYSID : 00000000, Thu Jun 07 03:02:00 2012
BOARD : 3C120
*** Warning - bad CRC, using default environment

Net:   ALTERA_TSE-0
Hit any key to stop autoboot:  0
## Booting kernel from Legacy Image at d6000000 …
   Image Name:   Linux-3.7.0-01482-gd7ff3e2
   Image Type:   NIOS II Linux Kernel Image (gzip compressed)
   Data Size:    1478109 Bytes = 1.4 MiB
   Load Address: d0000000
   Entry Point:  d0000000
   Verifying Checksum … OK
## Flattened Device Tree blob at d5000000
   Booting using the fdt blob at 0xd5000000
   Uncompressing Kernel Image … OK
Linux version 3.7.0-01482-gd7ff3e2 (kailng@localhost.localdomain) (gcc version 4
.7.2 (Sourcery CodeBench Lite 2012.09-115) ) #2 Mon Apr 22 10:50:20 MYT 2013
bootconsole [early0] enabled
early_console initialized at 0xe8004d50
On node 0 totalpages: 32768
free_area_init_node: node 0, pgdat d0305d3c, node_mem_map d03221c0
  DMA zone: 256 pages used for memmap
  DMA zone: 0 pages reserved
  DMA zone: 32512 pages, LIFO batch:7
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32512
Kernel command line: console=ttyJ0,115200 root=/dev/mtdblock0 rootfstype=jffs2 r
w
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory available: 126700k/3198k RAM (2410k kernel code, 788k data)
NR_IRQS:64
Calibrating delay loop... 61.56 BogoMIPS (lpj=123136)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
NET: Registered protocol family 16
bio: create slab <bio-0> at 0
Switching to clocksource timer
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP: reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
jffs2: version 2.2. (NAND) c 2001-2006 Red Hat, Inc.
msgmni has been set to 247
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
ttyAL0 at MMIO 0x8004c80 (irq = 10) is a Altera UART
ttyJ0 at MMIO 0x8004d50 (irq = 1) is a Altera JTAG UART
console [ttyJ0] enabled, bootconsole disabled
console [ttyJ0] enabled, bootconsole disabled
loop: module loaded
0.flash: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000001 Chi
p ID 0x002301
Amd/Fujitsu Extended Query Table at 0x0040
  Amd/Fujitsu Extended Query version 1.3.
number of CFI chips: 1
1 ofpart partitions found on MTD device 0.flash
Creating 1 MTD partitions on "0.flash":
0x000000800000-0x000002600000 : "JFFS2 Filesystem"
libphy: altera_tse-mdio: probed
eth0: Altera TSE MAC at 0xe8004000 irq 2/3
mousedev: PS/2 mouse device common for all mice
TCP: cubic registered
NET: Registered protocol family 17
VFS: Mounted root (jffs2 filesystem) on device 31:0.
Freeing unused kernel memory: 96k freed (0xd025c000 - 0xd0274000)
Starting logging: OK
Initializing random number generator... done.
Starting network...

Welcome to Nios II
nios2 login:

Note:
  • During booting , if you see the warning “Magic bitmask 0x1985 not found”,erase the CFI flash and reprogram.

To setup NFS root filesystem

You will need to setup a NFS server on a Linux machine. The following steps are for CentOS 6.
Download and install NFS utilities.
yum install nfs-utils nfs-utils-lib

Run startup scripts for NFS server.
chkconfig nfs on
service rpcbind start
service nfs start

Edit /etc/exports file.
vi  /etc/exports

Add the following lines to the file.
/home/nios2/nfs 137.57.118.0/255.255.255.0(rw,no_root_squash,sync)

Note:
  • The example above will allow access for all IP addresses from 137.57.118.0 to 137.57.118.255. Please check your network configuration.
  • /home/nios2/nfs is the location of the NFS root filesystem, you may use a different path if needed.
  • You will need add 'sudo' or change to root to run some of the commands above.
Export the shared filesystem.
exportfs -a

Extract the files from <Buildroot_top_directory>/output/images/rootfs.tar into /home/nios2/nfs.
sudo tar xvf rootfs.tar -C /home/nios2/nfs

Note:
  • Make sure the extracted files are under root user. Use ls -la to confirm.
To enable NFS root filesystem for Nios II Linux, turn on the option in Linux kernel configuration. In Linux kernel top directory, type:
make menuconfig

Include the option : File systems → Network File Systems → Root file system on NFS. Make to generate the vmImage and program the vmImage to CFI flash. Refer " To boot Nios II Linux from CFI flash" section. After CPU resets, when U-Boot starts, hit any key to stop autoboot. Load the Linux kernel and DTB from CFI to SDRAM.
run cfiload 

If you are using DHCP server , change the following boot environment settings:
setenv serverip <NFS server IPaddress>
setenv rootpath <NFS filesystem root path>
Setenv ethaddr <board MAC address>
Example:
setenv serverip 137.57.118.48
setenv rootpath /home/nios2/nfs
Setenv ethaddr 22:33:44:55:66:77

To boot Linux kernel with NFS filesystem through DHCP:
run nfsdhcpboot
NIOS2 # run nfsdhcpboot
## Booting kernel from Legacy Image at d6000000 …
   Image Name:   Linux-3.7.0-01482-gd7ff3e2
   Image Type:   NIOS II Linux Kernel Image (gzip compressed)
   Data Size:    1478109 Bytes = 1.4 MiB
   Load Address: d0000000
   Entry Point:  d0000000
   Verifying Checksum … OK
## Flattened Device Tree blob at d5000000
   Booting using the fdt blob at 0xd5000000
   Uncompressing Kernel Image … OK
Linux version 3.7.0-01482-gd7ff3e2 (kailng@localhost.localdomain) (gcc version 4
.7.2 (Sourcery CodeBench Lite 2012.09-115) ) #2 Mon Apr 22 10:50:20 MYT 2013
bootconsole [early0] enabled
early_console initialized at 0xe8004d50
On node 0 totalpages: 32768
free_area_init_node: node 0, pgdat d0305d3c, node_mem_map d03221c0
  DMA zone: 256 pages used for memmap
  DMA zone: 0 pages reserved
  DMA zone: 32512 pages, LIFO batch:7
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32512
Kernel command line: console=ttyJ0,115200 root=/dev/nfs rw nfsroot=137.57.118.48
:/home/nios2/nfs,tcp ip=dhcp
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory available: 126700k/3198k RAM (2410k kernel code, 788k data)
NR_IRQS:64
Calibrating delay loop... 61.56 BogoMIPS (lpj=123136)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
NET: Registered protocol family 16
bio: create slab <bio-0> at 0
Switching to clocksource timer
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP: reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
jffs2: version 2.2. (NAND) c 2001-2006 Red Hat, Inc.
msgmni has been set to 247
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
ttyAL0 at MMIO 0x8004c80 (irq = 10) is a Altera UART
ttyJ0 at MMIO 0x8004d50 (irq = 1) is a Altera JTAG UART
console [ttyJ0] enabled, bootconsole disabled
console [ttyJ0] enabled, bootconsole disabled
loop: module loaded
0.flash: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000001 Chi
p ID 0x002301
Amd/Fujitsu Extended Query Table at 0x0040
  Amd/Fujitsu Extended Query version 1.3.
number of CFI chips: 1
1 ofpart partitions found on MTD device 0.flash
Creating 1 MTD partitions on "0.flash":
0x000000800000-0x000002600000 : "JFFS2 Filesystem"
libphy: altera_tse-mdio: probed
eth0: Altera TSE MAC at 0xe8004000 irq 2/3
mousedev: PS/2 mouse device common for all mice
TCP: cubic registered
NET: Registered protocol family 17
Sending DHCP requests …, OK
IP-Config: Got DHCP answer from 0.0.0.0, my address is 137.57.118.52
IP-Config: Complete:
     device=eth0, addr=137.57.118.52, mask=255.255.255.0, gw=137.57.118.254
     host=137.57.118.52, domain=altera.com, nis-domain=(none)
     bootserver=0.0.0.0, rootserver=137.57.118.48, rootpath=
     nameserver0=137.57.137.2, nameserver1=137.57.116.2
, nameserver2=137.57.64.1
VFS: Mounted root (nfs filesystem) on device 0:8.
Freeing unused kernel memory: 96k freed (0xd025c000 - 0xd0274000)
Starting logging: OK
Initializing random number generator... done.
Starting network...
ip: RTNETLINK answers: File exists

Welcome to Nios II
nios2 login:

If you are using static IP , change the following boot environment settings:
setenv serverip <NFS server IPaddress>
setenv rootpath <NFS filesystem root path>
Setenv ethaddr <board MAC address>
Setenv ipaddr <Nios II IP address>
setenv gatewayip <gateway IP address>
Setenv netmask <netmask>

Example:
setenv serverip 137.57.118.48
setenv rootpath /home/nios2/nfs
Setenv ethaddr 22:33:44:55:66:77
Setenv ipaddr 137.57.118.100
setenv gatewayip 137.57.118.254
Setenv netmask 255.255.255.0

To boot Linux kernel with NFS filesystem through static IP:
run nfsstaticboot

To setup SSH connection

SSH allows secure Ethernet connection to Nios II Linux from remote PC. To enable SSH connection for Nios II Linux, turn on the option in Buildroot configuration to install OpenSSH in root filesystem. In Buildroot top directory, type:
make menuconfig

Select the option : Package Selection for the target → Networking applications → openssh.
Make to generate the rootfs.jffs2 and program the rootfs.jffs2 to CFI flash. Refer " To boot Nios II Linux from CFI flash" section.
Start nios2-terminal and press CPU reset on board. The OpenSSHserver runs on Nios II Linux from booting.
Starting network...
Generating RSA Key...
Generating public/private rsa1 key pair.
Your identification has been saved in /etc/ssh_host_key.
Your public key has been saved in /etc/ssh_host_key.pub.
The key fingerprint is:
ea:67:36:3e:7f:b8:e7:a0:8f:f6:3b:da:8f:a1:79:25
The key's randomart image is:
+--[RSA1 2048]----+
|                 |
|                 |
|                 |
|                 |
|        S        |
|       .  E .    |
|      .   o+     |
|     .  B*++o    |
|      .*BOOOo    |
+-----------------+
Generating RSA Key...
Generating public/private rsa key pair.
Your identification has been saved in /etc/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh_host_rsa_key.pub.
The key fingerprint is:
fb:46:29:65:2a:9b:a4:2a:cd:c8:c9:93:96:85:42:70
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|. E              |
|..               |
| .        o      |
|. .     S+ .     |
|.. .  o o.o      |
|++=  o +.o       |
|oOo . o  ..      |
|..o.     ..      |
+-----------------+
Generating DSA Key...
THIS CAN TAKE A MINUTE OR TWO DEPENDING ON YOUR PROCESSOR!

Generating public/private dsa key pair.
Your identification has been saved in /etc/ssh_host_dsa_key.
Your public key has been saved in /etc/ssh_host_dsa_key.pub.
The key fingerprint is:
7e:e9:14:19:a2:f0:c0:2a:31:72:e3:72:5d:65:4f:9c
The key's randomart image is:
+--[ DSA 1024]----+
|        o...     |
|   .   o oE      |
|+ o + . . o      |
|.= + = . . o     |
|o + . o S o      |
| +     .   o     |
|        . +      |
|         +       |
|          .      |
+-----------------+
Generating ECDSA Key...
THIS CAN TAKE A MINUTE OR TWO DEPENDING ON YOUR PROCESSOR!

Generating public/private ecdsa key pair.
Your identification has been saved in /etc/ssh_host_ecdsa_key.
Your public key has been saved in /etc/ssh_host_ecdsa_key.pub.
The key fingerprint is:
a0:c0:05:30:a1:eb:72:95:33:d6:01:03:96:46:c7:db
The key's randomart image is:
+--[ECDSA  256]---+
|++===            |
|.+oo.o           |
|..o  oo          |
| . ..+Eo         |
|.   B . S        |
|.  o o           |
|...              |
|..               |
|                 |
+-----------------+
Starting sshd: OK

Welcome to Nios II
nios2 login:

Configure the Ethernet connection of Nios II Linux. In this example, DHCP is used.
ifconfig eth0 up
udhcpc eth0

To check Nios II Linux IP address
ifconfig eth0 

Download and install any SSH client on your PC , eg. http://www.putty.org/
In the SSH client, use the Nios II Linux IP address and port 22 to connect to Nios II Linux.
Note:
  • If prompted for password, you may need to reset password for Nios II Linux : passwd root

To boot Nios II Linux with rootfs in RAM

This section talks about how to combine root file system into a single kernel image, where Nios II Linux will boot rootfs in RAM instead of CFI flash.
In Linux environment, go to Buildroot top directory and configure Buildroot for Nios II:
make menuconfig 

Select the option : File systems images → cpio the root filesystem and rebuild Buildroot:
make 

Next, go to Linux top directory and configure Linux kernel for Nios II:
make menuconfig 

Select the option : General setup → Initial RAM filesystem and RAM disk (initramfs/initrd) support.
Next, enter the path "../buildroot/output/images/rootfs.cpio" under General setup → Initramfs source file(s).
Save and exit.

To build:
make vmImage

Output file name : vmImage
Output directory : <Linux_kernel_top_directory>/arch/nios2/boot

You will need Altera tools to program the CFI on the 3C120 board. Download and install the tools from Altera.
First, you need to convert the boot images to SREC format(.flash file) before you can use the nios2-flash-programmer to program to CFI flash.
You will also need to determine the location of boot images in the CFI flash address map. Based on the Nios II MMU hardware design, we will use the following address map with CFI base address at 0x0 and CPU reset address at 0x02800000. U-Boot is the first boot image and will need to be program to the CPU reset address.
Offset Content
0x00200000 DTB
0x00300000 Linux kernel with build in root file system
0x02800000 U-Boot
To convert the following files to SREC format:
bin2flash --input=3c120_devboard.dtb --output=3c120_devboard.flash --location=0x00200000
bin2flash --input=vmImage --output=vmImage.flash --location=0x00300000
elf2flash --base=0x0 --end=0x03FFFFFF --boot=<Altera_ACDS_installation_path>/ip/altera/nios2_ip/altera_nios2/boot_loader_cfi.srec
--reset=0x02800000 --input=u-boot --output=u-boot.flash

To use the nios2-flash-programmer :
nios2-flash-programmer --base=<base_address> --mmu <flash_image>

To boot Nios II Linux : Start nios2-terminal and press CPU reset on board.
After CPU resets, when U-Boot starts, hit any key to stop autoboot. Execute these commands in U-boot command prompt:
setenv bootfilesize <*vmImage file size>
saveenv
run cfiload
bootm $loadaddr - $fdtaddr

Note:
  • vmImage file size is always in hexadecimal format
  • Execute first 2 commands for first time only
Nios II Linux will then boot and you can login as "root".
U-Boot 2013.01.01-00007-gb96b3b6-dirty (Apr 19 2013 - 10:27: 0
NIOS2 # bootm $loadaddr - $fdtaddr
## Booting kernel from Legacy Image at d6000000 …
   Image Name:   Linux-3.7.0-01482-gd7ff3e2
   Image Type:   NIOS II Linux Kernel Image (gzip compressed)
   Data Size:    3380641 Bytes = 3.2 MiB
   Load Address: d0000000
   Entry Point:  d0000000
   Verifying Checksum … OK
## Flattened Device Tree blob at d5000000
   Booting using the fdt blob at 0xd5000000
   Uncompressing Kernel Image … OK
Linux version 3.7.0-01482-gd7ff3e2 (alterian@localhost.localdomain) (gcc version
 4.7.2 (Sourcery CodeBench Lite 2012.09-115) ) #3 Thu May 2 10:36:14 MYT 2013
bootconsole [early0] enabled
early_console initialized at 0xe8004d50
On node 0 totalpages: 32768
free_area_init_node: node 0, pgdat d076bd60, node_mem_map d07881c0
  DMA zone: 256 pages used for memmap
  DMA zone: 0 pages reserved
  DMA zone: 32512 pages, LIFO batch:7
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32512
Kernel command line: console=ttyJ0,115200
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory available: 122196k/7702k RAM (2410k kernel code, 5292k data)
NR_IRQS:64
Calibrating delay loop... 61.56 BogoMIPS (lpj=123136)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
NET: Registered protocol family 16
bio: create slab <bio-0> at 0
Switching to clocksource timer
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP: reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
jffs2: version 2.2. (NAND) c 2001-2006 Red Hat, Inc.
msgmni has been set to 238
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
ttyAL0 at MMIO 0x8004c80 (irq = 10) is a Altera UART
ttyJ0 at MMIO 0x8004d50 (irq = 1) is a Altera JTAG UART
console [ttyJ0] enabled, bootconsole disabled
console [ttyJ0] enabled, bootconsole disabled
loop: module loaded
0.flash: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000001 Chi
p ID 0x002301
Amd/Fujitsu Extended Query Table at 0x0040
  Amd/Fujitsu Extended Query version 1.3.
number of CFI chips: 1
1 ofpart partitions found on MTD device 0.flash
Creating 1 MTD partitions on "0.flash":
0x000000800000-0x000002600000 : "JFFS2 Filesystem"
libphy: altera_tse-mdio: probed
eth0: Altera TSE MAC at 0xe8004000 irq 2/3
mousedev: PS/2 mouse device common for all mice
TCP: cubic registered
NET: Registered protocol family 17
Freeing unused kernel memory: 4604k freed (0xd025c000 - 0xd06db000)
Starting logging: OK
Initializing random number generator... done.
Starting network...

Welcome to Nios II
nios2 login:

To boot Nios II Linux from RAM

This flow allows Nios II Linux to boot from RAM without flashing kernel image and DTB to flash.
It doesn't require U-boot hence is useful for debugging or development phase.

Follow these steps in " Building Nios II Linux kernel" section to build your kernel image.

In Linux top directory, launch menuconfig:
make menuconfig

Select the option : Platform options → Compile and link device tree into kernel image.

Enter the path : Platform options → Device tree source file.
Note:
  • Example path: arch/nios2/boot/dts/3c120_devboard.dts
Save and exit menuconfig.

To build:
make vmImage 

Output file name : vmIinux
Output directory : <Linux_kernel_top_directory>

Download kernel image, launch Nios II terminal and boot kernel.
nios2-download -g vmlinux && nios2-terminal

Login as user "root" in Nios II kernel console.
$ nios2-download -g vmlinux && nios2-terminal
Using cable "USB-Blaster [USB-0]", device 1, instance 0x00
Pausing target processor: OK
Initializing CPU cache (if present)
OK
Downloaded 7598KB in 131.5s (57.7KB/s)
Verified OK in 1.2s (6331.6KB/s)
Starting processor at address 0xD0000000
nios2-terminal: connected to hardware target using JTAG UART on cable
nios2-terminal: "USB-Blaster [USB-0]", device 1, instance 0
nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)

U-Boot 2013.01.01-00007-gb96b3b6-dirty (Apr 19 2013 - 10:27:57)Linux version 3.7
.0-01482-gd7ff3e2 (alterian@localhost.localdomain) (gcc version 4.7.2 (Sourcery
CodeBench Lite 2012.09-115) ) #4 Thu May 2 15:39:54 MYT 2013
bootconsole [early0] enabled
early_console initialized at 0xe8004d50
On node 0 totalpages: 32768
free_area_init_node: node 0, pgdat d076bd60, node_mem_map d07881c0
  DMA zone: 256 pages used for memmap
  DMA zone: 0 pages reserved
  DMA zone: 32512 pages, LIFO batch:7
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32512
Kernel command line: debug console=ttyJ0,115200
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory available: 122200k/7702k RAM (2410k kernel code, 5292k data)
NR_IRQS:64
Calibrating delay loop... 61.56 BogoMIPS (lpj=123136)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
NET: Registered protocol family 16
bio: create slab <bio-0> at 0
Switching to clocksource timer
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP: reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
jffs2: version 2.2. (NAND) c 2001-2006 Red Hat, Inc.
msgmni has been set to 238
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
ttyAL0 at MMIO 0x8004c80 (irq = 10) is a Altera UART
ttyJ0 at MMIO 0x8004d50 (irq = 1) is a Altera JTAG UART
console [ttyJ0] enabled, bootconsole disabled
console [ttyJ0] enabled, bootconsole disabled
loop: module loaded
0.flash: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000001 Chi
p ID 0x002301
Amd/Fujitsu Extended Query Table at 0x0040
  Amd/Fujitsu Extended Query version 1.3.
number of CFI chips: 1
1 ofpart partitions found on MTD device 0.flash
Creating 1 MTD partitions on "0.flash":
0x000000800000-0x000002600000 : "JFFS2 Filesystem"
libphy: altera_tse-mdio: probed
eth0: Altera TSE MAC at 0xe8004000 irq 2/3
mousedev: PS/2 mouse device common for all mice
TCP: cubic registered
NET: Registered protocol family 17
Freeing unused kernel memory: 4604k freed (0xd025c000 - 0xd06db000)
Starting logging: OK
Initializing random number generator... done.
Starting network...

Welcome to Nios II
nios2 login: root
#

How to debug kernel/drivers with GDB

This section talks about how to debug kernel and drivers with GDB command line.
User will use Linux environment to load Linux kernel object file into target board and start GDB while host PC acts as server and connect to it.

First, launch menuconfig in Nios II Linux kernel directory:
make menuconfig

Select the option : Kernel hacking → Compile-time checks and compiler options → Compile the kernel with debug info.
Then re-make the kernel image.
make vmImage

Output file name : vmIinux
Output directory : <Linux_kernel_top_directory>

For Host, open Nios II Command Shell and executes below command to define host port number:
nios2-gdb-server –-tcpport <port number> 

Host will open the service and wait for GDB connection.
$ nios2-gdb-server --tcpport 1234
Using cable "USB-Blaster [USB-0]", device 1, instance 0x00
Processor is already paused
Listening on port 1234 for connection from GDB: 60s

In Linux environment, open terminal and execute below command:
nios2-linux-gnu-gdb vmlinux

This will loads kernel and starts GDB enviroment:
[alterian@localhost linux-nios2]$ nios2-linux-gnu-gdb vmlinux
GNU gdb (Sourcery CodeBench Lite 2012.09-115) 7.4.50.20120716-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=nios2-linux-gnu".
For bug reporting instructions, please see:
<https://support.codesourcery.com/GNUToolchain/>...
Reading symbols from /home/alterian/nios2-linux/linux-nios2/vmlinux...done.

Inside GDB server, connect to host with its IP address and port number:
target remote <host IP>:<port number>

Now you can start to debug any statically compiled kernel code or drivers.
(gdb) target remote 137.57.118.36:1234
Remote debugging using 137.57.118.36:1234
0xd7fd481c in ?? ()
(gdb) 

Note:
  • GDB commands reference
  • GDB supports script files. User can put a file .gdbinit in the source directory containing the line target remote <host IP>:<port number>. This command will be automatically executed whenever GDB starts in this directory.
Debug with Data Display Debugger - GUI for GDB (Optional)

GNU DDD is a graphical front-end user interface for GDB command-line debuggers.

To install:
yum install ddd

Note:
  • Additional repo files might be needed for ddd installation. User can refer here for RHEL EPEL Repo.
To run:
ddd -debugger nios2-linux-gnu-gdb vmlinux

Inside DDD gui, connect to host with its IP address and port number:
target remote <host IP>:<port number>

Once connected, you may start to debug with GUI.

How to build hello world app, TFTP to root filesystem

This section will guide user to create a hello world app from scratch, compile code with GNU toolchain, then use TFTP to transfer file from Host (PC) into client (3C120 dev kit).

In Linux environment, create a hello.c file with codes as below:
#include <stdio.h>
int main(void)
{   
    printf("Hello from Linux\n");
    return 0; 
} 

Compile using Altera nios2-linux tool chain with debugging information for use by GDB:
nios2-linux-gnu-gcc -ggdb hello.c -o hello

Output file name: hello
Output directory: <same directory as hello.c>
Note:
  • Make sure that toolchain setup is done prior to compilation; you may refer to “ Setting up toolchain” section for more info.
Setup 3C120 board with a valid Ethernet connection and follow these steps in " To boot Nios II Linux from CFI flash" section to build your kernel image and boot linux kernel.
After boot into kernel, log in as root and execute below commands to setup Ethernet port:
ifconfig eth0 up
udhcpc eth0

Once the setup is done, you may start TFTP file transfer.
Welcome to Nios II
nios2 login: root
# ifconfig eth0 up
# udhcpc eth0
udhcpc (v1.22.0.git) started
Sending discover...
Sending discover...
Sending discover...
Sending discover...
Sending select for 192.168.106.175...
Lease of 192.168.106.175 obtained, lease time 86400
deleting routers
route: SIOCDELRT: No such process
adding dns 137.57.116.2
adding dns 137.57.137.2
adding dns 137.57.64.1
#

In your host PC, download TFTP from this link and install.
Set your Linux “shared folder” as TFTP directory then copy hello file into it.
Use below command to transfer your file.
# tftp -g <host IP address> -r hello

Change “hello” file mode to grant permission to run it in client.
# chmod 744 hello
# ./hello
Hello from Linux

Note:
  • User may need to disable PC firewall setting for TFTP software.

How to debug user application program

This section describes on GDB remote debug session with user space program through ethernet/tcp. We will use hello world app that was build in previous section " How to build hello world app, TFTP to root filesystem" as an example.

Copy "gdbserver" from toolchain directory (toolchain top directory/nios2-linux-gnu/libc/usr/lib/bin) and TFTP to target board.

In Nios II Linux, run below command to check target board ip address:
ifconfig eth0

Target board address is shown as 192.168.106.175.
# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 22:33:44:55:66:77
          inet addr:192.168.106.175  Bcast:192.168.106.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:117 errors:0 dropped:130 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6926 (6.7 KiB)  TX bytes:994 (994.0 B)
          Base address:0x4000

To run gdbserver on Nios II Linux, execute below command with target board ip address and an unused port:
./gdbserver -–remote-debug <target IP>:<port number> <ELF file> 

Nios II Linux will wait for connection from GDB debugger:
# ./gdbserver --remote-debug 192.168.106.175:1234 hello
Process hello created; pid = 730
Listening on port 1234

Then, run GDB to debug from your Linux host environment.
nios2-linux-gnu-gdb <ELF file>

In GDB console:
target remote <target IP>:<port number>

Note: Note:
  • GDB commands reference
  • GDB supports script files. User can put a file .gdbinit in the source directory containing the line target remote <target IP address>:<port number>. This command will be automatically executed whenever GDB starts in this directory.
Use DDD to debug (Optional)

GNU DDD is a graphical front-end user interface for GDB command-line debuggers.

To install:
yum install ddd

Run DDD from your Linux host environment:
ddd –debugger nios2-linux-gnu-gdb <ELF file>

In DDD console:
target remote <target IP>:<port number>

Note:
  • Additional repo files might be needed for ddd installation. User can refer here for RHEL EPEL Repo.

How to use TFTP on U-boot to transfer files

U-boot supports TFTP command to download Linux kernel and DTB images to SDRAM. You can then choose to directly boot the newly downloaded images or write them to CFI flash using U-boot commands. To use TFTP, the U-boot must setup the the network connection for the board.

In your host PC, download TFTP from this link and install.
Set your Linux “shared folder” as TFTP directory then copy hello Linux kernel and DTB images into it.

Let the 3C120 reset into U-boot.

The following U-boot commands will get an IP address for the 3C120 board through DHCP server, setup the IP address of your host PC and copy the Linux kernel and DTB images from TFTP server to SDRAM.
# dhcp
# setenv serverip <TFTP server IP address>
# run tftpload

The following U-boot commands setup the static IP for 3C120, setup the IP address of your host PC and copy the Linux kernel and DTB images from TFTP server to SDRAM.
# setenv ipaddr <static IP address>
# setenv serverip <TFTP server IP address>
# setenv gatewayip <Gateway IP address>
# run tftpload

You can boot the newly downloaded images in SDRAM with the U-boot command:
# run cfiboot

You can also choose to copy the new images from SDRAM to CFI flash:
# erase $cfibootaddr +<kernel image size>
# cp.b $loadaddr $cfibootaddr <kernel image size>
# erase $cfifdtaddr +<DTB image size>
# cp.b $fdtaddr $cfifdtaddr <DTB image size>

Note: You can get the image size from tftpload command output message.

U-boot config files

Download 3c120 board patch file from 0001-Add-3c120-dev-board-support.patch.

Go to U-boot top directory and apply the patch.
git am <0001-***>.patch

© 1999-2024 RocketBoards.org by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

Privacy Policy - Terms Of Use

This website is using cookies. More info. That's Fine