Skip to content

mlapaj/linux_tang_primer_138k

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,325,425 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intro

Linux for Andes AE350. I'm a luckily owner of TANG MEGA NEO 138k board. This is FPGA evaluation board with GOWIN GW5AST FPGA Chip. This chip contain RISC-V Hard core provided by Andes. Unfortunately, looks like Andes A25 chip has bug in atomic operations (Wrote mail to Gowin. I do not have any confirmation from Gowin/Andes). Basically, before doing atomic operation, memory on which atomic operation will be performed, must be fetched to cache.

Code is based on Linux v6.13 tag

Warning: I'm not taking any responsibility for this SW.

What is working ?

Kernel boot

What is not working ?

Most probably network, i saw some dynamic part of code used together with atomic operations Warning: all other compiled programs are affected. I've trried to run busybox and it uses lot of atomic ops so it hangs

Next steps

This is not a real fix. It is rather a bypass for testing basic stuff. I made this for fun and as a hobby. I wanted to check if linux will work. If the CPU bug cannot be fixed in other way, we should consider to modify toolchains to put additional memory read Unfortunately, i do not have much time for doing it.

Config

Used configuration is here I have also added DTB (generated by u-boot with my modifications) dtb file

Howto

You need to have u-boot compiled and opensbi compiled.

Everything is loaded to memory. Boot flow:

  • Small program which enables cache start
  • Opensbi is loaded. OpenSBI is initializing supervisor and jumps to U-Boot
  • U-Boot starts and initializes rest of stuff
  • In U-Boot we are booting linux (providing DTB and initrd)

Script used to boot is here

Example output

RISC-V # unzip 0x4000000 0x1000000;booti 0x1000000 0x6000000 0x200000
Uncompressed size: 30191104 = 0x1CCAE00
Moving Image from 0x1000000 to 0x400000, end=0x211d000
Wrong Ramdisk Image Format
Ramdisk image is corrupt or invalid
RISC-V # unzip 0x4000000 0x1000000;booti 0x1000000 0x6000000:0x1B0400 0x200000
Uncompressed size: 30191104 = 0x1CCAE00
Moving Image from 0x1000000 to 0x400000, end=0x211d000
## Flattened Device Tree blob at 00200000
   Booting using the fdt blob at 0x200000
Working FDT set to 200000
   Loading Ramdisk to 3ed37000, end 3eee7400 ... OK
   Using Device Tree in place at 00200000, end 00205263
Working FDT set to 200000

Starting kernel ...

[    0.000000] Linux version 6.13.0 (cod3r@Precision-3620) (riscv32-unknown-linux-gnu-gcc () 14.2.0, GNU ld (GNU Binutils) 2.43.1) #11 Mon Feb  3 23:03:10 CET 2025
[    0.000000] OF: fdt: Ignoring memory range 0x0 - 0x400000
[    0.000000] Machine model: andestech,a25
[    0.000000] SBI specification v2.0 detected
[    0.000000] SBI implementation ID=0x1 Version=0x10006
[    0.000000] SBI TIME extension detected
[    0.000000] SBI IPI extension detected
[    0.000000] SBI RFENCE extension detected
[    0.000000] SBI DBCN extension detected
[    0.000000] efi: UEFI not found.
[    0.000000] OF: reserved mem: 0x00040000..0x0005ffff (128 KiB) nomap non-reusable mmode_resv0@40000
[    0.000000] OF: reserved mem: 0x00000000..0x0003ffff (256 KiB) nomap non-reusable mmode_resv1@0
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000400000-0x000000003fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000400000-0x000000003fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000400000-0x000000003fffffff]
[    0.000000] On node 0, zone Normal: 1024 pages in unavailable ranges
[    0.000000] Falling back to deprecated "riscv,isa"
[    0.000000] riscv: base ISA extensions acdfim
[    0.000000] riscv: ELF capabilities acdfim
[    0.000000] Ticket spinlock: enabled
[    0.000000] Kernel command line: console=ttyS0,9600n8 debug loglevel=7
[    0.000000] printk: log buffer data + meta data: 131072 + 409600 = 540672 bytes
[    0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes, linear)
[    0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 261120
[    0.000000] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.000000] Virtual kernel memory layout:
[    0.000000]       fixmap : 0x9c800000 - 0x9d000000   (8192 kB)
[    0.000000]       pci io : 0x9d000000 - 0x9e000000   (  16 MB)
[    0.000000]      vmemmap : 0x9e000000 - 0xa0000000   (  32 MB)
[    0.000000]      vmalloc : 0xa0000000 - 0xc0000000   ( 512 MB)
[    0.000000]       lowmem : 0xc0000000 - 0xffc00000   (1020 MB)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] RCU Tasks Trace: Setting shift to 0 and lim to 1 rcu_task_cb_adjust=1 rcu_task_cpu_ids=1.
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] riscv-intc: 32 local interrupts mapped
[    0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0xb881274fa3, max_idle_ns: 440795210636 ns
[    0.000008] sched_clock: 64 bits at 800MHz, resolution 1ns, wraps every 4398046511103ns
[    0.000880] Console: colour dummy device 80x25
[    0.001271] Calibrating delay loop (skipped), value calculated using timer frequency.. 1600.00 BogoMIPS (lpj=3200000)
[    0.001378] pid_max: default: 32768 minimum: 301
[    0.001641] LSM: initializing lsm=capability
[    0.003093] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[    0.003308] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[    0.028423] ASID allocator using 9 bits (512 entries)
[    0.030650] EFI services will not be available.
[    0.030955] Memory: 999268K/1044480K available (9106K kernel code, 8902K rwdata, 4096K rodata, 4196K init, 327K bss, 43628K reserved, 0K cma-reserved)
[    0.035001] devtmpfs: initialized
[    0.041590] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.041951] futex hash table entries: 256 (order: 0, 7168 bytes, linear)
[    0.043244] pinctrl core: initialized pinctrl subsystem
[    0.046446] DMI not present or invalid.
[    0.048740] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.052259] DMA: preallocated 128 KiB GFP_KERNEL pool for atomic allocations
[    0.052948] audit: initializing netlink subsys (disabled)
[    0.059407] thermal_sys: Registered thermal governor 'step_wise'
[    0.059541] cpuidle: using governor menu
[    0.060701] audit: type=2000 audit(0.052:1): state=initialized audit_enabled=0 res=1
[    0.083562] cpu0: Ratio of byte access time to unaligned word access is 1.01, unaligned accesses are fast
[    0.107091] HugeTLB: registered 4.00 MiB page size, pre-allocated 0 pages
[    0.107155] HugeTLB: 0 KiB vmemmap can be freed for a 4.00 MiB page
[    0.119770] iommu: Default domain type: Translated
[    0.119837] iommu: DMA domain TLB invalidation policy: strict mode
[    0.122495] SCSI subsystem initialized
[    0.125995] usbcore: registered new interface driver usbfs
[    0.126218] usbcore: registered new interface driver hub
[    0.126475] usbcore: registered new device driver usb
[    0.130802] Advanced Linux Sound Architecture Driver Initialized.
[    0.135376] vgaarb: loaded
[    0.137907] clocksource: Switched to clocksource riscv_clocksource
[    0.262587] NET: Registered PF_INET protocol family
[    0.265489] IP idents hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.269766] tcp_listen_portaddr_hash hash table entries: 512 (order: 1, 10240 bytes, linear)
[    0.270327] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.270501] TCP established hash table entries: 8192 (order: 3, 32768 bytes, linear)
[    0.271168] TCP bind hash table entries: 8192 (order: 6, 327680 bytes, linear)
[    0.276530] TCP: Hash tables configured (established 8192 bind 8192)
[    0.278351] UDP hash table entries: 512 (order: 3, 40960 bytes, linear)
[    0.279241] UDP-Lite hash table entries: 512 (order: 3, 40960 bytes, linear)
[    0.281126] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.286526] RPC: Registered named UNIX socket transport module.
[    0.286602] RPC: Registered udp transport module.
[    0.286614] RPC: Registered tcp transport module.
[    0.286627] RPC: Registered tcp-with-tls transport module.
[    0.286639] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.286708] PCI: CLS 0 bytes, default 64
[    0.293479] Unpacking initramfs...
[    0.306750] workingset: timestamp_bits=14 max_order=18 bucket_order=4
[    0.315374] NFS: Registering the id_resolver key type
[    0.315748] Key type id_resolver registered
[    0.315802] Key type id_legacy registered
[    0.316181] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.316240] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.318329] 9p: Installing v9fs 9p2000 file system support
[    0.320034] NET: Registered PF_ALG protocol family
[    0.320832] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 247)
[    0.326776] io scheduler mq-deadline registered
[    0.326857] io scheduler kyber registered
[    0.327237] io scheduler bfq registered
[    0.330472] riscv-plic: interrupt-controller@e4000000: mapped 71 interrupts with 1 handlers for 2 contexts.
[    0.487248] Freeing initrd memory: 1728K
[    1.171974] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    1.190324] printk: legacy console [ttyS0] disabled
[    1.192910] f0300000.serial: ttyS0 at MMIO 0xf0300020 (irq = 1, base_baud = 6250000) is a 16550A
[    1.193215] printk: legacy console [ttyS0] enabled
[    2.234296] loop: module loaded
[    2.248939] e1000e: Intel(R) PRO/1000 Network Driver
[    2.256836] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[    2.270228] usbcore: registered new interface driver uas
[    2.278999] usbcore: registered new interface driver usb-storage
[    2.290786] mousedev: PS/2 mouse device common for all mice
[    2.303125] sdhci: Secure Digital Host Controller Interface driver
[    2.312845] sdhci: Copyright(c) Pierre Ossman
[    2.319960] Synopsys Designware Multimedia Card Interface Driver
[    2.330467] sdhci-pltfm: SDHCI platform and OF driver helper
[    2.340646] usbcore: registered new interface driver usbhid
[    2.349431] usbhid: USB HID core driver
[    2.356834] riscv-pmu-sbi: SBI PMU extension is available
[    2.365447] riscv-pmu-sbi: 16 firmware and 6 hardware counters
[    2.374513] riscv-pmu-sbi: Perf sampling/filtering is not supported as sscof extension is not available
[    2.396336] NET: Registered PF_INET6 protocol family
[    2.412728] Segment Routing with IPv6
[    2.419075] In-situ OAM (IOAM) with IPv6
[    2.425750] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    2.437840] NET: Registered PF_PACKET protocol family
[    2.446777] 9pnet: Installing 9P2000 support
[    2.454320] Key type dns_resolver registered
[    2.493836] debug_vm_pgtable: [debug_vm_pgtable         ]: Validating architecture page table helpers
[    2.512670] clk: Disabling unused clocks
[    2.519047] PM: genpd: Disabling unused power domains
[    2.526974] ALSA device list:
[    2.531724]   No soundcards found.
[    2.609336] Freeing unused kernel image (initmem) memory: 4196K
[    2.619251] Run /init as init process

Other issues

While investigating Linux boot procedure i have used J-Link. Unfortunately my J-Link is not capable of translating virtual addresses to physical memory. After linux configures pagetables, J-Link is showing up wrong data. To fix this, i have used openocd together with J-Link Link to openocd script

Other

Link to old readme

About

Linux kernel source tree

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C 98.3%
  • Assembly 0.7%
  • Shell 0.4%
  • Python 0.2%
  • Makefile 0.2%
  • Perl 0.1%
  • Other 0.1%