-1

I want to build a Linux for my Altera DE2-115 that connects with the serial port. Now I see kernel panic from the serial port when I try and run it:

 0.000000] Linux version 4.8.0+ (developer@developer-Latitude-E7450) (gcc version 6.2.0 (Sourcery CodeBench Lite 207
[    0.000000] bootconsole [early0] enabled
[    0.000000] early_console initialized at 0xe8001400
[    0.000000] On node 0 totalpages: 32768
[    0.000000] free_area_init_node: node 0, pgdat c05d88f0, node_mem_map c0699740
[    0.000000]   Normal zone: 288 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 32768 pages, LIFO batch:7
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32480
[    0.000000] Kernel command line: debug console=ttyAL0,115200
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Sorting __ex_table...
[    0.000000] allocated 131072 bytes of page_ext
[    0.000000] Memory: 122900K/131072K available (4215K kernel code, 166K rwdata, 1456K rodata, 164K init, 740K bss, 81)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:64 nr_irqs:64 0
[    0.000000] Kernel panic - not syncing: 1 timer is found, it needs 2 timers in system
[    0.000000] 
[    0.000000] ---[ end Kernel panic - not syncing: 1 timer is found, it needs 2 timers in system
[    0.000000] 
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15
[    0.000000] Kernel panic - not syncing: Oops
[    0.000000] ---[ end Kernel panic - not syncing: Oops
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    0.000000] ea = c0003de4, ra = c028ac84, cause = 15

There were many steps and I will try and rebuild with two timers but can you tell me how I should do it? What information more is needed? I changed a lot in make menuconfig but now I proved that it can get started and seen with through the serial port. I used a .sof from a friend who had a very stripped down version of uClinux and it was also old. It only had root access and I try and make one where you can log in. The dts file is as follows.

/*
 * This devicetree is generated by sopc2dts version unknown on Mon Mar 13 18:52:55 CET 2017
 * Sopc2dts is written by Walter Goossens <waltergoossens@home.nl>
 * in cooperation with the nios2 community <nios2-dev@lists.rocketboards.org>
 */
/dts-v1/;

/ {
    model = "ALTR,qsys";
    compatible = "ALTR,qsys";
    #address-cells = <1>;
    #size-cells = <1>;

    cpus {
        #address-cells = <1>;
        #size-cells = <0>;

        cpu: cpu@0x0 {
            device_type = "cpu";
            compatible = "altr,nios2-16.1", "altr,nios2-1.1";
            reg = <0x00000000>;
            interrupt-controller;
            #interrupt-cells = <1>;
            altr,exception-addr = <3221225504>; /* embeddedsw.dts.params.altr,exception-addr type NUMBER */
            altr,fast-tlb-miss-addr = <3355447296>; /* embeddedsw.dts.params.altr,fast-tlb-miss-addr type NUMBER */
            altr,has-initda = <1>;  /* embeddedsw.dts.params.altr,has-initda type NUMBER */
            altr,has-mmu = <1>; /* embeddedsw.dts.params.altr,has-mmu type NUMBER */
            altr,has-mul = <1>; /* embeddedsw.dts.params.altr,has-mul type NUMBER */
            altr,implementation = "fast";   /* embeddedsw.dts.params.altr,implementation type STRING */
            altr,pid-num-bits = <8>;    /* embeddedsw.dts.params.altr,pid-num-bits type NUMBER */
            altr,reset-addr = <3221225472>; /* embeddedsw.dts.params.altr,reset-addr type NUMBER */
            altr,tlb-num-entries = <256>;   /* embeddedsw.dts.params.altr,tlb-num-entries type NUMBER */
            altr,tlb-num-ways = <16>;   /* embeddedsw.dts.params.altr,tlb-num-ways type NUMBER */
            altr,tlb-ptr-sz = <8>;  /* embeddedsw.dts.params.altr,tlb-ptr-sz type NUMBER */
            clock-frequency = <50000000>;   /* embeddedsw.dts.params.clock-frequency type NUMBER */
            dcache-line-size = <32>;    /* embeddedsw.dts.params.dcache-line-size type NUMBER */
            dcache-size = <2048>;   /* embeddedsw.dts.params.dcache-size type NUMBER */
            icache-line-size = <32>;    /* embeddedsw.dts.params.icache-line-size type NUMBER */
            icache-size = <4096>;   /* embeddedsw.dts.params.icache-size type NUMBER */
        }; //end cpu@0x0 (cpu)
    }; //end cpus

    memory {
        device_type = "memory";
        reg = <0x08001000 0x00000400>,
            <0x00000000 0x08000000>;
    }; //end memory

    sopc0: sopc@0 {
        device_type = "soc";
        ranges;
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "ALTR,avalon", "simple-bus";
        bus-frequency = <50000000>;

        jtag: serial@0x8001440 {
            compatible = "altr,juart-16.1", "altr,juart-1.0";
            reg = <0x08001440 0x00000008>;
            interrupt-parent = <&cpu>;
            interrupts = <1>;
        }; //end serial@0x8001440 (jtag)

        timer: timer@0x8001420 {
            compatible = "altr,timer-16.1", "altr,timer-1.0";
            reg = <0x08001420 0x00000020>;
            interrupt-parent = <&cpu>;
            interrupts = <0>;
            clock-frequency = <50000000>;   /* embeddedsw.dts.params.clock-frequency type NUMBER */
        }; //end timer@0x8001420 (timer)

        uart: serial@0x8001400 {
            compatible = "altr,uart-16.1", "altr,uart-1.0";
            reg = <0x08001400 0x00000020>;
            interrupt-parent = <&cpu>;
            interrupts = <2>;
            clock-frequency = <50000000>;   /* embeddedsw.dts.params.clock-frequency type NUMBER */
            current-speed = <115200>;   /* embeddedsw.dts.params.current-speed type NUMBER */
        }; //end serial@0x8001400 (uart)
    }; //end sopc@0 (sopc0)

    chosen {
        bootargs = "debug console=ttyAL0,115200";
    }; //end chosen
}; //end /
Niklas R.
  • 22,209
  • 67
  • 202
  • 380
  • 1
    Can you regenerate FPGA bitstream? – osgx Mar 14 '17 at 14:35
  • 1
    "I used a .sof from a friend who had a very stripped down version of uClinux and it was also old." - so this bitstream. And in http://sdrv.ms/11cMAUy I see sof bitstream but can't find which file is for qsys project and nios settings. – osgx Mar 14 '17 at 14:55
  • 2
    Try kernel before 3.19: it may work with single timer. Check https://rocketboards.org/foswiki/view/Documentation/NiosIILinuxUserManual and updated answer – osgx Mar 14 '17 at 17:00
  • @osgx Thanks a lot! I'm making a new build now with 3.18 from `git clone https://github.com/altera-opensource/linux-socfpga.git`. It's also interesting to learn qsys but I'm not that good at hardware. My goal is to run uClinux with user roles like different users and a login prompt. It will be exciting. – Niklas R. Mar 14 '17 at 17:06

1 Answers1

1

You don't run Linux on the "Altera DE2-115" board, you run it on the hardware implemented in the FPGA (as Cyclone IV E chip "EP4CE115" used in the board is not a SoC and have no any "hard cores" of some ARM Cortex-A9 or like). It is impossible to fully answer the question without details of the hardware you have implemented, as FPGAs allow to implement anything (which fits into the FPGA used).

Your kernel and your nios 2 implementation are not compatible. Can you regenerate FPGA bitstream, do you have quartus / qsys project with the nios 2 and its settings?

You should check how many timers are implemented in your nios, as your kernel requires two of them, which is visible at first "panic":

 [    0.000000] Kernel panic - not syncing: 1 timer is found, it needs 2 timers in system

This requirement is arch-specific for the nios2, it is from time initializer code: http://lxr.free-electrons.com/source/arch/nios2/kernel/time.c?v=4.8#L341

341 void __init time_init(void)

343         struct device_node *np;
344         int count = 0;
345 
346         for_each_compatible_node(np, NULL,  ALTR_TIMER_COMPATIBLE)
347                 count++;
348 
349         if (count < 2)
350                 panic("%d timer is found, it needs 2 timers in system\n", count); 

Rebuilding of the linux kernel 4.8 will not help, as this code is always unconditionally compiled into it: http://lxr.free-electrons.com/source/arch/nios2/kernel/Makefile?v=4.8 20 obj-y += time.o

And your build of the kernel correct or almost correct, as it boots.

What you should do - provide needed timers in your soft core by reconfiguring qsys project (add second timer, connect it like the first one, but on different address and new interrupt id; other parameters should be as required by altera's linux). Then rebuild bitstream with quartus (it is long). And also register new timer in the device tree with correct offsets/irq id, then relink kernel with devicetree and reupload both FPGA bitstream and linux image to FPGA / Flash.

The requirements of two timers for 3.19+ kernels are listed at https://rocketboards.org/foswiki/view/Documentation/NiosIILinuxUserManual (commit http://lkml.iu.edu/hypermail/linux/kernel/1507.0/01501.html?)

Kernel v3.19 and above Few things need to be noted if using kernel 3.19 and above:

  • Toolchain: Sourcery CondeBench Lite 2014.05-47 and above
  • Hardware: 2 timers in nios2 system
  • DTS: Small letter for altr prefix in dts file, eg: altr,has-mmu; compatible = "altr,juart-1.0";

Or you can try some kernel older than 3.19, which may work with single timer.

osgx
  • 80,853
  • 42
  • 303
  • 470
  • Yes. Thank you for the answer. I use the qsys project from [here](http://sdrv.ms/11cMAUy). The code for two timers must have been added after linux 2.6 because that project runs with linux 2.6 and only one timer IIUC. Your answer is very good and I'm going to award you a bounty because you provided very valuable information and saved me lots of time. Now I know that I must change it in qsys and add one timer so that there are two timers. – Niklas R. Mar 14 '17 at 14:47
  • 1
    Dj, I can't open the project (from huge archives and have no qsys) and I also have no sources of 2.6.* linux kernels for nios2 (in the days of 2.6.* series kernels were named using 3 numbers, like 2.6.32, not two like in 3.* and 4.* series). Which version you had? Are there 2.6.* for nios2 online in the internet? – osgx Mar 14 '17 at 14:51
  • Yes, `nios2-linux-linux-2.6-20120802.tgz` that seems like 2.6 linux online from [this web page](http://alterawiki.com/wiki/InstallNios2Linux). – Niklas R. Mar 14 '17 at 14:54
  • 1
    Dj Dac, this file name is still doesn't name 2.6 kernel version correctly. But http://alterawiki.com/wiki/InstallNios2Linux names 2.6.30 – osgx Mar 14 '17 at 14:54
  • I think that project very pretty good because it did almost what I intend to do - start linux with the DE2-115. The archive is "only" 23.2 MB and one mustn't get the VM files. Do you think that I could manage and add one timer and then get it going? Or am I oversimplified a very complicated procedure? – Niklas R. Mar 14 '17 at 14:57
  • 1
    Project archive is sdrv.ms/11cMAUy - DE2_115_uClinux.zip 23.2 MB - 3/19/2013 by Mehdi Hafezi (and video youtube.com/watch?v=RxlyezOf0Rs). But I can't download this from the *best-selling* ... ... cloud of the .. ... How linux get info about timers, is there any devicetree? – osgx Mar 14 '17 at 15:45
  • Yes, I compiled a devicetree from Mehdi's project and linked the devicetree in `make menuconfig` getting a clean 4.8 build IIUC. I'm updating the question with the `dts` file now. – Niklas R. Mar 14 '17 at 16:05
  • 1
    So, you need to add another timer with qsys, add right connections, select correct address, regenerate bitstream. Then - add it to devicetree and recompile recent Linux. – osgx Mar 14 '17 at 16:08
  • That's very good if it is that easy. Maybe it's easier said than done. But it seems feasible for me. Mehdi also permitted me to use his design for my project. – Niklas R. Mar 14 '17 at 16:09
  • 1
    And the comment from linked "time.c" why two timers are used: "*The first timer instance will use as a clockevent. If there are two or more instances, the second one gets used as clocksource and all others are unused.*". I think you may use same frequency in second timer as it was in the first. – osgx Mar 14 '17 at 17:11
  • I use 1000 MHz for the first timer. I try rebuilding with v3.18 getting this build error `multiple definition of __clz_tab'` that seems to have something to do with libc or glibc. Maybe I must recompile more sources after doing checkout between versions. I didn't recompile everything. – Niklas R. Mar 15 '17 at 07:23
  • 1
    Dj, You don't use 1000 MHz when your FPGA is clocked at 50 MHz (as `` in qsys.qsys). And `` section of qsys.qsys defines period 1 ms for the timer (period=1, periodUnits=MSEC, systemFrequency=50000000). When you switch kernel version you must do full clean (!) & full reconfigure. – osgx Mar 15 '17 at 12:03
  • I meant 1000 Hz. Pardon my mistake. I'm starting over because the image didn't output anything when I loaded it. – Niklas R. Mar 15 '17 at 12:41
  • Thanks for the help. I got the build running on my FPGA now. I had to make some change that I didn't understand. You may plaese have a look if you know in my new question http://stackoverflow.com/questions/43113030/uclinux-with-altera-de2-115-cross-compiled-with-ubuntu-16-04 – Niklas R. Mar 30 '17 at 09:14
  • The beginning of your answer reads a bit like "you can't run Linux on an FPGA with no hard cores" which is indeed not the case. – Dmitry Grigoryev Jan 16 '18 at 11:21
  • @DmitryGrigoryev, I mean that linux is not running on the Board, it is running on some cores: either hard or soft. And soft cores for linux are rather huge (with some mmu and even small cache). Feel free to edit style in beginning of my answer - it is still read by less than 100 visitors. – osgx Jan 16 '18 at 15:45
  • I have changed the first paragraph to my liking, feel free to roll back if you like your old text better. – Dmitry Grigoryev Jan 17 '18 at 09:18