Closed nohahanon closed 11 months ago
I attempted to use the SD card containing the above files to boot sdcardboot, but it stopped as follows. Dtb file is not read.
litex> sdcardboot
Booting from SDCard in SD-Mode...
Booting from boot.json...
Copying Image to 0x40000000 (7726264 bytes)...
[########################################]
Copying rv32.dtb to 0x40ef0000 (2689 bytes)...
[ ]
I have identified that the processing is halted at the following line in ff.c within the Litex output:
if (FfDiskOps->disk_read(fs->pdrv, rbuff, sect, cc) != RES_OK) ABORT(fs, FR_DISK_ERR);
I commented out this section, and I was able to successfully move the file to RAM. However, the processing halted at the liftoff stage.
litex> sdcardboot
Booting from SDCard in SD-Mode...
Booting from boot.json...
Copying Image to 0x40000000 (7726264 bytes)...
[########################################]
Copying rv32.dtb to 0x40ef0000 (2689 bytes)...
[########################################]
Copying rootfs.cpio to 0x41000000 (5376512 bytes)...
[########################################]
Copying opensbi.bin to 0x40f00000 (263652 bytes)...
[########################################]
Executing booted program at 0x40f00000
--============= Liftoff! ===============--
Hi @nohahanon I have the same problem with booting via serial/sdcard boot.
The short answer: It's need to create a customized project for small memory boards.
Hello @avkghost ! Thank you for the advice! I see that there are errors in the generated device tree. I sent an inquiry email to Sipeed last week asking about how to create the Image and dtb. I'm currently waiting for a response from Sipeed (although my expectations are low).
And, I found a successful example of running Linux on the Tang Primer board. It seems that reducing the size of the Linux image is essential, so I will continue my research. https://www.luffca.com/ja/2022/10/linux-tang-primer/
I'm currently trying to modify the BusyBox configuration to see if I can create a smaller Linux image. I've outlined the specific steps below. It seems like I can create a smaller image by removing unnecessary commands, but I'm struggling to get it below 7.7MB. If anyone has any suggestions, I would appreciate it.
(get buildroot, extract and cd there)
$ sudo make BR2_EXTERNAL=../linux-on-litex-vexriscv/buildroot/ litex_vexriscv_defconfig
$ sudo make busybox-menuconfig
(select and delete commands.)
$ sudo make
Enabline RVC compressed instruction may help reaching it (need to be enable on both litex arguments and linux / busybody. Generaly, it reduce the kernel about 30 %
Hello,bro @nohahanon , I have also encountered such a problem. Has your problem been resolved so far?
Hello @Dolu1990 , I would like to ask if you have any good solutions for processing halted at the liftoff stage.I am looking forward to your reply .Thanks.
Hello, bro @peiceliu ,
linux-on-litex-vexriscv/buildroot/board/litex_vexriscv/linux.config
as follows, the size of the Image becomes approximately 5.9MB.(7.7MB->5.9MB)Thanks for your advice @nohahanon,after i change y to n,i still can not boot linux successfully. Should i change other files?Such as [litex/soc/cores/cpu/vexriscv_smp/core.py]. If you could give me appropriate advice to make linux to boot successfully on my fpga board, I would be very grateful.I am looking forward to your reply,bro.
Hello @nohahanon,
I've seen the link you provided, thanks! However, I had neither found a solution for the Linux kernel configuration, nor a solution for litex for a board configuration. So, the example contains information about Tang Primer which has a different FPGA (Anlogic instead of Gowin). In addition, the example shows that an author can create a multicore VexRiscv bitstream and program the FPGA with it.
As I investigated the readme from TangNano-20K-example I've found that the Linux kernel, device tree, and boot loader provided by Icenowy. I'm going to ask her for details about the kernel configuration.
So, I'm going to create a debug version of a VexRiscv to debug the booting process. First of all, it would help me to understand a configuration difference between my own and @Icenowy 's.
Update:
Thanks @avkghost !! I'm looking forward to it!
@avkghost The LiteX port is by me, but booting Linux is done by another person, Jisheng Zhang .
Hi @Icenowy.
Thanks for joining our discussion.
There are my experiments with litex-boards and linux-on-litex-vexriscv.
python -m litex_boards.targets.sipeed_tang_nano_20k --cpu-type vexriscv --cpu-variant linux --csr-csv csr.csv --uart-baudrate 3000000 --build
As I see, the script produces configuration with wrong addresses.
./make.py --board sipeed_tang_nano_20k --uart-baudrate 3000000 --build
It looks (almost?) similar to the device tree provided by TangNano-20K-example But when I was trying to boot this an Image with bootloader I got "Liftoff!". As I understand the configuration that I've built is different than your and I need some corrections in a generator flags or maybe create own configuration with corrected addresses.
Could you please answer a few questions? See below.
Thanks for the advice.
I would say running it in a simulation would give full visibility on what the CPU does, that's the way in generaly always go.
Else there is the possibility to use the JTAG debug, and since recently you can even use the official RISC-V debug spec, which support linux kernel debugging aswell :)
Update:
@nohahanon FYI
I've successfully run linux on a Tang Nano 20k with the kernel provided in a TangNano-20K-example repository.
I use the linux-on-litex-vexriscv with following parameters/flags:
./make.py --board sipeed_tang_nano_20k --with-rvc --uart-baudrate 3000000 --build
At the moment I'm going to experiment with a Linux kernel (reduce size and remove unneeded modules/subsystems).
@Icenowy Could Jisheng Zhang help us with a kernel configuration for the board?
Hello @avkghost , I tried the suggestions you provided but I was not able to successfully boot Linux on my sipeed_tang_primer_20k . Here is my log.Could you please provide me with more details about the issue?
~/Desktop/linux-on-litex-vexriscv$ ./make.py --board sipeed_tang_primer_20k --with-rvc --uart-baudrate 3000000 --build --load
~/Desktop/linux-on-litex-vexriscv$ litex_term --speed 3000000 --serial-boot --images=images/boot.json /dev/ttyUSB1
NOTE:I had replaced the files in the images folder with the boot.json and other files of tang_primeri_20k example.But my computer does not respond to this command /Desktop/linux-on-litex-vexriscv$ litex_term --speed 3000000 --serial-boot --images=images/boot.json /dev/ttyUSB1
and it stop here. How can i encounter this problem?Please provide any answer. Thank you!Hello @peiceliu, Have you tried accessing a litex bootloader console? Is it possible to write any command in the console? If yes, please use serialboot or reboot command.
Unfortunately, now I do not have the ability to test Tang Primer build. The power went out while I was flashing the board. It is currently not possible to write anything to FPGA memory or software SPI flash.
Hello @avkghost ,After the second command,I can not boot litex console.In addition,after the first command,my serial tool displayed messy code instead of boot log .
@peiceliu I've successfully loaded Tang Primer 20k with Linux. So, I restored my board under the windows (using Gowin programmer). The second problem was with a bitstream. I was not able to program it with openFPGALoader. In some cases, the upload was freezing while flashing. When the bitstream uploaded successfully and FPGA was re-booted it did not start a Litex BIOS.
There is a step-by-step solution that I used for my own board, please take a look below.
./make.py --board sipeed_tang_primer_20k --with-rvc --uart-baudrate 3000000 --build
litex_term --speed 3000000 --serial-boot --images=images/boot.json /dev/ttyUSB1
Maybe it would help you.
Thanks bro @avkghost,now i boot linux on my fpga board successfully.
@avkghost @peiceliu Big thanks for the great news and sharing it. If you've had success with the Primer 20k, I hope I can achieve the same results with the Nano 20k... However, when it comes to writing the fs file to the board using Gowin and booting with self-built Image, I encountered the same issue as before – the process stops. What steps should I take within the gowin project, including adding mem.init and such? The synthesis process stops due to errors.
[LITEX-TERM] Got unexpected response from device 'b'E''
Booting from SDCard in SD-Mode... Booting from boot.json... Copying Image to 0x40000000 (7726264 bytes)... [########################################] Copying rv32.dtb to 0x40ef0000 (2689 bytes)... [########################################] Copying rootfs.cpio to 0x41000000 (5376512 bytes)... [########################################] Copying opensbi.bin to 0x40f00000 (263652 bytes)... [########################################] Executing booted program at 0x40f00000
--============= Liftoff! ===============--`
@nohahanon As I wrote before, you are still using an incorrect memory map in a bootloader. Maybe you using the wrong address for opensbi/fw_jump for building and/or loading. The second possible problem I see is disabling verification during load into RAM. Your log file leds that rv32.dtb at 0x40ef0000, rootfs.cpio at 0x41000000, and placed at an unreachable memory region. On a Tang Nano 20k is possible to access the memory region from address 0x40000000 to 0x40800000 (default and your variant). All your code/data needs to be placed in this region. For example, the original kernel+root.cpio, opensbi.bin.tangnano20k, and device tree are placed below the memory limit (0x40800000).
All addresses below the memory limit are included in the original example. Please pay attention to the addresses provided below.
{
"Image": "0x40000000",
"sipeed_tang_nano_20k.dtb": "0x40780000",
"opensbi.bin.tangnano20k": "0x407c0000"
}
So, I also booted Tang Nano 20k from SDCard.
To reduce the memory footprint for the kernel try to use make tinyconfig
and then add the needed options.
For buildroot I recommend using uclibc instead of glibc to reduce the memory footprint.
@nohahanon Small update Below is my result of the kernel compilation and execution. I removed SMP, networking, and all compressions instead of GZIP. Enabled "Emit compressed instructions when building Linux" in the kernel config.
I had not used any additional scripts or ran make from buildroot. I've created a test build aiming to minimize the kernel.
Please pay attention to the addresses I used in boot.json. Unfortunately, the kernel did not boot properly. I've only created a kernel, not rootfs cpio and integrated it into the Image.
{
"Image": "0x40000000",
"sipeed_tang_nano_20k.dtb": "0x40780000",
"opensbi.bin.tangnano20k": "0x407c0000"
}
@Dolu1990 Could I ask you for help with kernel debugging? Maybe I removed something important from the kernel configuration or did something wrong. Thanks.
Big thanks, bro, I'll try.
@nohahanon Another small update I successfully booted up my own custom-built environment.
{
"Image": "0x40000000",
"root.cpio": "0x406ef000",
"sipeed_tang_nano_20k.dtb": "0x40780000",
"opensbi.bin.tangnano20k": "0x407c0000"
}
@avkghost
Thank you for your reply. I edited linux.config
like this and I successfully reduced the size to less than 8MB! In the comment two comments back, you were saying I removed SMP, networking, and all compressions instead of GZIP. Enabled "Emit compressed instructions when building Linux" in the kernel config.
, but did you mean that you edited the linux.config file like below?
In conclusion, I failed to boot linux using the following file. It stopped in the middle of the opensbi process.
By the way, you said root.cpio - extracted from tang nano example kernel image
, could you please explain how to do that?
Regards.
size of each file
boot.json
{
"Image": "0x40000000",
"rootfs.cpio": "0x40400000",
"sipeed_tang_nano_20k.dtb": "0x40780000",
"opensbi.bin.tangnano20k": "0x407c0000"
}
@nohahanon
An "Emit compressed instructions when building Linux"
option is CONFIG_RISCV_ISA_C=y
CONFIG_SMP=n
Yes, it disables SMP.
Disable networking CONFIG_NET=n or remove it.
Image: 4125780(0x3EF454), same as you
So close, but mine is 2993104 bytes.
In conclusion, I failed to boot linux using the following file. It stopped in the middle of the opensbi process. By the way, you said root.cpio - extracted from tang nano example kernel image, could you please explain how to do that?
I used binwalk to extrat root.cpio from the example's kernel. binwalk -e Image
. An extracted cpio was placed in _Image.extracted directory.
I had not used buildroot for some reasons:
make config
or make menuconfig
gives me a fine kernel tuning.*** No C library enabled, this is not possible.. Stop.
Maybe it depens on some addition parts like compiler I don't know. I have a riscv coross-compiler + binutils installed from apt.@avkghost I hadn't know binwalk! Thank you very much.
Currently, I believe the only difference between your setup and mine is the Image. Could you please share how you created that Image?
By the way, I encountered the same error with the provided Buildroot recipe, but when I extracted the tar.gz available on buildroot.org and did the make process, I was able to obtain the Image without any errors. So, I am using the Image created using this method.
I'm sorry for taking up your time. Thank you.
report Even with opensbi processing, it progressed quite far, but it still didn't reach the boot and stopped.
When I changed CONFIG_RISCV_ISA_C=n and executed it, opensbi processing stopped at a position further than before! Errors like below are occured...
[ 8.899980] litex-mmc f0005000.mmc: Command (cmd 8) error, status -110
[ 8.924722] litex-mmc f0005000.mmc: Command (cmd 55) error, status -110
[ 8.952200] litex-mmc f0005000.mmc: Command (cmd 55) error, status -110
[ 8.976205] litex-mmc f0005000.mmc: Command (cmd 55) error, status -110
[ 9.000210] litex-mmc f0005000.mmc: Command (cmd 55) error, status -110
boot.json: same as above
.dts: same as above
@nohahanon I've successfully booted from SDCard and added SDCard support to the kernel. As a root.cpio I continue using the old one from the example above. However, I've successfully built root.cpio with a buildroot, but not used it due to a big footprint and out-of-memory while booting.
@avkghost Is that true! I'm glad to hear that report. My goal is to bring files I've created locally onto that Linux running on tang nano 20k so I can execute a C program. However, I couldn't mount it on the SD card in the Linux image provided in the tang nano 20k example (it seems to be a very minimal Linux). So, I want to create my own, more feature-rich image and use it to boot Linux.
You mentioned that you haven't created an image with Buildroot, but how did you create it? I'd like to create an image similar to what you're using. Looking forward to your reply.
Thanks.
@nohahanon Initially, I had a problem creating images with build root. For now, I've successfully built it but I need to tune the size due to an out-of-memory error while Linux loading.
I prefer to use separate kernel configurations to minimize its footprint. I cloned the litex-linux repo and checked out 6.1.0 branch, and used the config provided above to build the kernel image.
To cross-compile build the kernel I used the following command.
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
Below, is a device tree I've used dt_nano_20k.zip
@nohahanon Below is an archive with my experiments. nano_examples.zip It is possible to boot them via serial or SD card.
The SD card needs to be partitioned into 2 or 3 partitions.
A command line from the device tree sets mmcblk0p2 as the root partition. The root partition I extracted from root.cpio.
I couldn't mount it on the SD card in the Linux image provided in the tang nano 20k example (it seems to be a very minimal Linux).
The kernel provided in the Tang Nano example did not have drivers for MMC, block devices, partition schemes, and file systems. It is impossible to mount any filesystem under the example's kernel. It is built as an experiment to show the possibility of running Linux on the board.
Now, I have no idea where I can use this configuration. In other words, I don't see any practical use for this configuration in my projects. In my opinion, there is the best way to use this board with bare metal OS, like FreeRTOS, etc, because in this case, Linux is an overhead for the board. For me, it is interesting in the case of porting/running Linux to embedding systems with an architecture different than x86.
If you need to build and run your own program on a device I recommend you start with litex_bare_metal_demo Build your own demo and run it on the board. For example:
litex_bare_metal_demo --with-cxx --build-path build/sipeed_tang_nano_20k
in a directory contains build result. It creates a demo that you can run on a devicelitex_term --kernel demo/demo.bin
and see how it works.Hope you find it helpful.
Big thanks, bro,
I was able to successfully boot Linux using the provided image, but it seems that I still couldn't mount the SD card. While my initial goal was to run a program on Linux, I'm glad that I was able to run programs like Donut and Helloc on VexRiscv with litex_sim
.
Although I didn't achieve the original goal of running a C program on Linux booted with the locally built Linux image, I will continue this on an Arty board where there is no need to reduce the size of the image.
Hi there!
I'm trying to boot with a Linux image created locally on a tang nano 20k, but I'm encountering an error that says "[LITEX-TERM] Got unexpected response from device 'b'E'" and the log stops without booting. I have attached the detailed log below. Please provide any answer. Thank you!
litex> reboot
Build your hardware, easily!
(c) Copyright 2012-2023 Enjoy-Digital (c) Copyright 2007-2015 M-Labs
BIOS CRC passed (5386dd7d)
LiteX git sha1: 36ce71d5
--=============== SoC ==================-- CPU: VexRiscv SMP-LINUX @ 48MHz BUS: WISHBONE 32-bit @ 4GiB CSR: 32-bit data ROM: 64.0KiB SRAM: 6.0KiB L2: 128B SDRAM: 8.0MiB 32-bit @ 48MT/s (CL-2 CWL-2) MAIN-RAM: 8.0MiB
--========== Initialization ============-- Initializing SDRAM @0x40000000... Switching SDRAM to software control. Switching SDRAM to hardware control. Memtest at 0x40000000 (2.0MiB)... Write: 0x40000000-0x40200000 2.0MiB
Read: 0x40000000-0x40200000 2.0MiB
Memtest OK Memspeed at 0x40000000 (Sequential, 2.0MiB)... Write speed: 18.9MiB/s Read speed: 21.9MiB/s
--============== Boot ==================-- Booting from serial... Press Q or ESC to abort boot completely. sL5DdSMmkekro [LITEX-TERM] Received firmware download request from the device. [LITEX-TERM] Uploading /home/nohara/TangNano-20K-example/linux/image5/Image to 0x40000000 (7726264 bytes)... [LITEX-TERM] Upload calibration... (inter-frame: 10.00us, length: 64) [LITEX-TERM] Upload complete (9.9KB/s). [LITEX-TERM] Uploading /home/nohara/TangNano-20K-example/linux/image5/sipeed_tang_nano_20k.dtb to 0x40ef0000 (2115 bytes)... [LITEX-TERM] Upload calibration... (inter-frame: 10.00us, length: 64) [LITEX-TERM] Got unexpected response from device 'b'E''