kinsamanka / meta-milkv

Milk-V Duo overlay for OpenEmbedded/Yocto
Other
18 stars 3 forks source link

Adding support for duo256m and duos #4

Open oresk opened 3 months ago

oresk commented 3 months ago

I would like to add support for the other two platforms, but would like a bit of insight on how do you think it would be best to do. I have experience with yocto, but not with kas.

Should I just add additional yaml kas project files or pipe the desired platform through env variables into the kas project file, or just make new meta layer for the other two platforms, or something else?

Thnx for your time!

ItamarEliakim-R commented 3 months ago

I would also love to know and help with this effort. Planning on integrating it with Duo-S.

kinsamanka commented 3 months ago

I think it is just a matter of updating the device tree.

I only have the Duo-S though.

DAMEK86 commented 3 months ago

i also like to contribute. i have boath ones.

on the duo-S i was able to jump until the kernel but with the ugly precompiled firmware. i think this would be a nice starting point. with a uboot, the rest is so much easier :)

let me know how i can help / what u need

kinsamanka commented 3 months ago

I've got fsbl and OpenSBI working, still stuck with u-boot :smiley:

It is stuck here:

U-Boot 2021.10 (Nov 19 2023 - 13:34:05 +0000)milkv-duo

DRAM:  510 MiB
gd->relocaddr=0x9fdb2000. offset=0x1fbb2000

The buildroot version:

U-Boot 2021.10 (Aug 01 2024 - 14:12:44 +0800) cvitek_cv181x

DRAM:  510 MiB
gd->relocaddr=0x9493e000. offset=0x1473e000
set_rtc_register_for_power
...
DAMEK86 commented 3 months ago

how did you link the fsbl with the uboot? i saw that multi.its provided in https://github.com/kinsamanka/milkv-duo-buildroot-libraries/tree/main is only available for cv180x targets and not for the duo-s which is a cv181x target.

kinsamanka commented 3 months ago

we're using this one.

this allows loading a different dtb without creating a new fip.bin.

DAMEK86 commented 3 months ago

but don't you need to align https://github.com/kinsamanka/meta-riskv/blob/master/recipes-bsp/milkv-duo-fsbl/milkv-duo-fsbl.bb#L30 somehow? i didn't find the section in the buildroot project where this cmd was created. This sophgo magic was a blocker for me but it seems you made it already :)

if you like to share your progress, i can try working on u-boot as well.

DAMEK86 commented 3 months ago

i struggle a bit bitbaking milkv-duo-fsbl against your latest commit i modified the recipe by updating the following using a new machine milkv-duo-s that is for now just a duplicate of the current milkv-duo.

SRC_URI = "git://github.com/kinsamanka/milkv-duo-buildroot-libraries.git;protocol=https;branch=yocto"
SRCREV = "84c9632e0eabeae6838b2f32272aa431f377088b"

COMPATIBLE_MACHINE = "(milkv-duo|milkv-duo-s)"

# copy the compiled map from the buildroot target
SRC_URI:append:milkv-duo-s = " \
    file://cvi_board_memmap.h;subdir=git/firmware/plat/cv181x/include \
"

# changing the chip arch and offset
CHIP_ARCH:milkv-duo = "cv180x"
BLCP_2ND_RUNADDR:milkv-duo = "0x83f40000"

CHIP_ARCH:milkv-duo-s = "cv181x"
BLCP_2ND_RUNADDR:milkv-duo-s = "0x9fe00000"

# make the compile script more generic
do_compile () {
    unset LDFLAGS
    oe_runmake -C ${S} CROSS_COMPILE=${HOST_PREFIX} ARCH=riscv BOOT_CPU=riscv CHIP_ARCH=${CHIP_ARCH} bl2

    # this is a risc-v bin that contains a busy loop instruction
    # using wfi instruction, this is needed to initialize the
    # secondary core.

    printf '\163\000\120\020\157\360\337\377' > ${B}/blank.bin

    # generate fip.bin
    python3 ${S}/plat/${CHIP_ARCH}/fiptool.py genfip ${B}/fip.bin \
        --MONITOR_RUNADDR=0x80000000 \
        --CHIP_CONF=${S}/plat/${CHIP_ARCH}/chip_conf.bin \
        --NOR_INFO=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF \
        --NAND_INFO=00000000 \
        --BL2=${B}/${CHIP_ARCH}/bl2.bin \
        --BLCP_IMG_RUNADDR=0x05200200 \
        --BLCP_PARAM_LOADADDR=0 \
        --BLCP_2ND=${B}/blank.bin \
        --BLCP_2ND_RUNADDR=${BLCP_2ND_RUNADDR} \
        --DDR_PARAM=${S}/test/cv181x/ddr_param.bin \
        --MONITOR=${DEPLOY_DIR_IMAGE}/fw_dynamic.bin \
        --LOADER_2ND=${DEPLOY_DIR_IMAGE}/u-boot.bin
}

and now i get stuck in the following compile time errors :'(

| Assembler messages:
| Error: x ISA extension `xthead' must be set with the versions
| make: *** [Makefile:195: build/cv181x/bl2/misc_helpers.o] Error 1
| make: *** Waiting for unfinished jobs....
| {standard input}:3: Error: x ISA extension `xthead' must be set with the versions
| lib/cpu/riscv/cpu_helper.c:13: Error: unrecognized opcode `icache.iall'
| lib/cpu/riscv/cpu_helper.c:14: Error: unrecognized opcode `sync.i'
| {standard input}:3: Error: x ISA extension `xthead' must be set with the versions
| {standard input}:3: Error: x ISA extension `xthead' must be set with the versions
| {standard input}:3: Error: x ISA extension `xthead' must be set with the versions

i would be super thankful if somewone has a hint for me

kinsamanka commented 3 months ago

I've pushed my wip branch.

kinsamanka commented 3 months ago

It's booting u-boot now

U-Boot 2021.10 (Nov 19 2023 - 13:34:05 +0000)Milk-V DuoS

DRAM:  510 MiB
gd->relocaddr=0x9fdb2000. offset=0x1fbb2000
MMC:   
Loading Environment from FAT... Loading Environment from nowhere... OK
In:    serial
Out:   serial
Err:   serial
Net:   
Warning: ethernet0@4070000 (eth0) using random MAC address - 4e:c9:06:7a:c0:4e
eth0: ethernet0@4070000
Hit any key to stop autoboot:  0 
No MMC device available
Loading uEnv.txt ...
Couldn't find partition mmc 0
Can't set block device
Error loading uEnv.txt
Booting from SD ...
Couldn't find partition mmc 0
Can't set block device
milkv-duo# 
DAMEK86 commented 3 months ago

nice!! you made it <3

while the working break, i build your branch and run into

|   TARGET bl2 
|   TARGET fip-all 
| echo "  [GEN] fip.bin"
|   [GEN] fip.bin
| . ./build/cv181x/blmacros.env && \
| ./plat/cv181x/fiptool.py -v genfip \
|   './build/cv181x/fip.bin' \
|   --MONITOR_RUNADDR="${MONITOR_RUNADDR}" \
|   --BLCP_2ND_RUNADDR="${BLCP_2ND_RUNADDR}" \
|   --CHIP_CONF='./build/cv181x/chip_conf.bin' \
|   --NOR_INFO='FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' \
|   --NAND_INFO='00000000'\
|   --BL2='./build/cv181x/bl2.bin' \
|   --BLCP_IMG_RUNADDR=0x05200200 \
|   --BLCP_PARAM_LOADADDR=0 \
|   --BLCP=test/empty.bin \
|   --DDR_PARAM='test/cv181x/ddr_param.bin' \
|   --BLCP_2ND='/home/andreas/embedded/duo/build/tmp-glibc/work/riscv64-oe-linux/milkv-duo-fsbl/1.0/git/firmware/build/blank.bin' \
|   --MONITOR='/home/andreas/embedded/duo/build/tmp-glibc/deploy/images/milkv-duos/fw_dynamic.bin' \
|   --LOADER_2ND='/home/andreas/embedded/duo/build/tmp-glibc/deploy/images/milkv-duos/u-boot.bin' \
|   --compress='lzma'
| INFO:root:PROG: fiptool.py
| DEBUG:root:  BL2='./build/cv181x/bl2.bin'
| DEBUG:root:  BL2_FILL=None
| DEBUG:root:  BLCP='test/empty.bin'
| DEBUG:root:  BLCP_2ND='/home/andreas/embedded/duo/build/tmp-glibc/work/riscv64-oe-linux/milkv-duo-fsbl/1.0/git/firmware/build/blank.bin'
| DEBUG:root:  BLCP_2ND_RUNADDR=2682257408
| DEBUG:root:  BLCP_IMG_RUNADDR=85983744
| DEBUG:root:  BLCP_PARAM_LOADADDR=0
| DEBUG:root:  BLOCK_SIZE=None
| DEBUG:root:  CHIP_CONF='./build/cv181x/chip_conf.bin'
| DEBUG:root:  DDR_PARAM='test/cv181x/ddr_param.bin'
| DEBUG:root:  LOADER_2ND='/home/andreas/embedded/duo/build/tmp-glibc/deploy/images/milkv-duos/u-boot.bin'
| DEBUG:root:  MONITOR='/home/andreas/embedded/duo/build/tmp-glibc/deploy/images/milkv-duos/fw_dynamic.bin'
| DEBUG:root:  MONITOR_RUNADDR=2147483648
| DEBUG:root:  NAND_INFO=b'\x00\x00\x00\x00'
| DEBUG:root:  NOR_INFO=b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'
| DEBUG:root:  OLD_FIP=None
| DEBUG:root:  compress='lzma'
| DEBUG:root:  func=<function generate_fip at 0x72994de91ab0>
| DEBUG:root:  output='./build/cv181x/fip.bin'
| DEBUG:root:  subcmd='genfip'
| DEBUG:root:  verbose=10
| DEBUG:root:generate_fip:
| DEBUG:root:add_nor_info:
| DEBUG:root:add_nand_info:
| DEBUG:root:add_chip_conf:
| DEBUG:root:add_blcp:
| DEBUG:root:add_bl2:
| DEBUG:root:ddr_param=0x2000 bytes
| DEBUG:root:blcp_2nd=0x8 bytes
| DEBUG:root:monitor=0x421c8 bytes
| Traceback (most recent call last):
|   File "/home/andreas/embedded/duo/build/tmp-glibc/work/riscv64-oe-linux/milkv-duo-fsbl/1.0/git/firmware/./plat/cv181x/fiptool.py", line 802, in <module>
|     main()
|   File "/home/andreas/embedded/duo/build/tmp-glibc/work/riscv64-oe-linux/milkv-duo-fsbl/1.0/git/firmware/./plat/cv181x/fiptool.py", line 763, in main
|     args.func(args)
|   File "/home/andreas/embedded/duo/build/tmp-glibc/work/riscv64-oe-linux/milkv-duo-fsbl/1.0/git/firmware/./plat/cv181x/fiptool.py", line 693, in generate_fip
|     f(fip, args)
|   File "/home/andreas/embedded/duo/build/tmp-glibc/work/riscv64-oe-linux/milkv-duo-fsbl/1.0/git/firmware/./plat/cv181x/fiptool.py", line 480, in add_loader_2nd
|     with open(args.LOADER_2ND, "rb") as fp:
| FileNotFoundError: [Errno 2] No such file or directory: '/home/andreas/embedded/duo/build/tmp-glibc/deploy/images/milkv-duos/u-boot.bin'
| make: Leaving directory '/home/andreas/embedded/duo/build/tmp-glibc/work/riscv64-oe-linux/milkv-duo-fsbl/1.0/git/firmware'
| make: *** [make_helpers/fip.mk:48: fip-all] Error 1
| ERROR: oe_runmake failed
| WARNING: exit code 1 from a shell command.

seems like the virtual/bootloader dependency isn't defined for the recipe / should be a simple one.

kinsamanka commented 3 months ago

I can't seem to reproduce your issue.

Are you using kas? (make sure you're on wip branch)

It's booting the kernel now. I'll update once I've finished refactoring.

kinsamanka commented 3 months ago

Duo S is working now but not on the original kernel, so not all features are supported (the device tree still needs more work though).

Duo 256M is not tested, but it should work.

DAMEK86 commented 3 months ago

I can't seem to reproduce your issue.

Are you using kas? (make sure you're on wip branch)

It's booting the kernel now. I'll update once I've finished refactoring.

yes, I use your branch with commit 905bd7339b751094d5785d71165eb013aec52abf but using plain old bitbake and set the milkv-duos machine in the local.conf

I see that you define PREFERRED_PROVIDER_virtual/bootloader ?= "u-boot-milkv" in the machine but is not defined as a dependency of milkv-duo-fsbl.bb. I asume that u created it somehow before. i you run a bitbake virtual/bootloader -c clean and try it, it should fail. I was able to build the recipe after manually bitbake the u-boot, so i assume it's just a missing depend on ;)

kinsamanka commented 3 months ago

I see that you define PREFERRED_PROVIDER_virtual/bootloader ?= "u-boot-milkv" in the machine but is not defined as a dependency of milkv-duo-fsbl.bb. I asume that u created it somehow before. i you run a bitbake virtual/bootloader -c clean and try it, it should fail.

this error never occurs when using kas :smile:

I've updated the milkv-duo-fsbl recipe to reflect this dependency.

DAMEK86 commented 3 months ago

I was able to create an image with your latest wip branch by adding these additional changes do you plan to upstream this changes to meta-riscv? if so I expect masking the original recipe is no longer needed.

really create work! thx

From 6e223002b8153643c94db9dca7244e39345ed77a Mon Sep 17 00:00:00 2001
From: Andreas Rehn <rehn.andreas86@gmail.com>
Date: Thu, 22 Aug 2024 21:50:26 +0200
Subject: [PATCH] bitbake: make it compile

---
 conf/layer.conf                              | 2 ++
 conf/machine/include/milkv-common.inc        | 2 +-
 recipes-bsp/milkv-duo-fsbl/milkv-duo-fsbl.bb | 5 ++++-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/conf/layer.conf b/conf/layer.conf
index 37e22c9..b332762 100644
--- a/conf/layer.conf
+++ b/conf/layer.conf
@@ -8,3 +8,5 @@ BBFILE_PATTERN_milkv-duo-layer = "^${LAYERDIR}/"
 BBFILE_PRIORITY_milkv-duo-layer = "7"

 LAYERSERIES_COMPAT_milkv-duo-layer = "scarthgap"
+
+BBMASK += "/meta-riscv/recipes-bsp/milkv-duo-fsbl"
diff --git a/conf/machine/include/milkv-common.inc b/conf/machine/include/milkv-common.inc
index 2f73e7f..7b3e8c0 100644
--- a/conf/machine/include/milkv-common.inc
+++ b/conf/machine/include/milkv-common.inc
@@ -9,7 +9,7 @@ MACHINE_FEATURES = "screen keyboard ext2 ext3 serial"
 KERNEL_CLASSES = "kernel"
 KERNEL_IMAGETYPE = "Image.gz"

-PREFERRED_PROVIDER_virtual/kernel ?= "linux-milkv-duo-dev"
+PREFERRED_PROVIDER_virtual/kernel ?= "linux-milkv-duo-v5.10.y"

 PREFERRED_VERSION_openocd-native = "riscv"
 PREFERRED_VERSION_openocd = "riscv"
diff --git a/recipes-bsp/milkv-duo-fsbl/milkv-duo-fsbl.bb b/recipes-bsp/milkv-duo-fsbl/milkv-duo-fsbl.bb
index 209666d..b942369 100644
--- a/recipes-bsp/milkv-duo-fsbl/milkv-duo-fsbl.bb
+++ b/recipes-bsp/milkv-duo-fsbl/milkv-duo-fsbl.bb
@@ -23,7 +23,10 @@ CHIP_ARCH:milkv-duo = "cv180x"
 DDR_CFG = "ddr3_1866_x16"
 DDR_CFG:milkv-duo = "ddr2_1333_x16"

-do_compile[depends] += "opensbi:do_deploy"
+do_compile[depends] += " \
+   opensbi:do_deploy \
+   virtual/bootloader:do_deploy \
+"

 DEFINES  = " \
    -DCVIMMAP_DRAM_BASE=${CVIMMAP_DRAM_BASE} \
-- 
2.34.1
kinsamanka commented 3 months ago

Here's the upstream pr for the changes.

DAMEK86 commented 3 months ago

today I tried to run the image and the boot process of the duos stopped at

C.SCS/0/0.WD.URPL.C.SCS/0/0.WD.URPL.C.SCS/0/0.WD.URPL.SDI/25000000/6000000.BS/SD.PS.SD/0x0/0x1000/0x1000/0.PE.BS.SD/0x1000/0xa800/0xa800/0.BE.J.
FSBL Jb2829:gf359994-dirty:2024-08-22T19:09:03+00:00
st_on_reason=d0000
st_off_reason=0
P2S/0x1000/0xc010800.
SD/0xb800/0x1000/0x1000/0.P2E.
DPS/0xc800/0x2000.
SD/0xc800/0x2000/0x2000/0.DPE.
cv181x DDR init.
ddr_param[0]=0x78075562.
pkg_type=1
D2_4_1
DDR3-4G-BGA
Data rate=1866.
DDR BIST PASS
PLLS.
PLLE.
C2S/0xe800/0x9fe00000/0x200.
SD/0xe800/0x200/0x200/0.RSC.
C2E.
MS/0xea00/0x80000000/0x42200.
SD/0xea00/0x42200/0x42200/0.ME.
L2/0x50c00.
SD/0x50c00/0x200/0x200/0.L2/0x414d3342/0xcafea467/0x80200000/0x22a00/0x22a00
COMP/1.
SD/0x50c00/0x22a00/0x22a00/0.DCP/0x80200020/0x1000000/0x81500020/0x22a00/1.
DCP/0x4961f/0.
Loader_2nd loaded.
Switch RTC mode to xtal32k
Jump to monitor at 0x80000000.
OPENSBI: next_addr=0x80200020 arg1=0x80080000

normally, the openSBI logo should follow

OPENSBI: next_addr=0x80200020 arg1=0x80080000
OpenSBI v0.9
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : Milk-V DuoS

any ideas?

I used your wip branch with commit d8b243904222415b532876fa671e81126dc27377

update: after switching to your upstream MR + using the latest meta-milkv scarthgap branch everything works as expected. I think I had a raise condition with the bbapends or duplicated recipes.

oresk commented 3 months ago

Well you go for holidays and stuff just happens! :-) Thank everyone for the work. I've built the current master with duos machine specified and it worked without any problems.

kinsamanka commented 3 months ago

Just don't use linux-milkv-duo-v5.10.y.

I've encountered some issues with the SG200x SoC (gpio-leds doesn't work).

linux-milkv-duo-dev works fine.

ItamarEliakim-R commented 2 months ago

Thanks for this great work! Works perfectly on both duo-256mb, and duo-s.

Has anyone tried to compile the TDL SDK through the build? We plan to integrate it with ROS 2.