A minimal toolkit to generate ready-to-flash image for your own custom OS

I integrated essential toolkits to build ready-to-flash .img images for the Milk-V Duo 256M in one click, making it easier to develop a custom OS from scratch. I created this repository because I found the existing tutorials not very beginner-friendly (I personally struggled with them for about a day).

3 Likes

Wow, sounds cool! Thanks for taking time. :heart:

BTW, is there a chance it will build on an ARM64 machine?

What do I do wrong?

$ make
make -C example
make\[1\]: Entering directory ‘/home/user/milkv-baremetal-toolkit/example’
riscv64-unknown-elf-gcc -mcmodel=medany -nostdlib -fno-builtin -march=rv64gc -mabi=lp64f -g -Wall -T kernel.ld boot.c main.c start.s -o kernel.elf
riscv64-unknown-elf-objcopy -O binary kernel.elf kernel.bin
make\[1\]: Leaving directory ‘/home/user/milkv-baremetal-toolkit/example’
cp example/kernel.bin .
fiptool/fiptool 
–fsbl fiptool/data/fsbl/cv181x.bin 
–ddr_param fiptool/data/ddr_param.bin 
–opensbi ./pre-build-binary/fw_dynamic.bin 
–uboot kernel.bin 
–rtos fiptool/data/cvirtos.bin
Packing Param1…
Param1:    0x0
FSBL:      0x1000
Packing Param2…
Param2:    0x9400
DDR Param: 0xa400
RTOS:      0xc400
OpenSBI:   0xfa00
U-Boot:    0x2c200
Success
pre-build-binary/genimage 
–config 
genimage.cfg 
–rootpath mktemp -d 
–tmppath mktemp -d 
–inputpath . 
–outputpath .
pre-build-binary/genimage: error while loading shared libraries: libconfuse.so.2: cannot open shared object file: No such file or directory
make: \*\*\* \[Makefile:16: kernel.img\] Error 127
~/milkv-baremetal-toolkit$ git submodule status
7f59889c91f7d5d440d6a09aad0209f0aca3d09d fiptool (heads/master)
67a399476add05f29ef1ad722856728fb7639ba9 genimage (v19)

Oh, I see: not only am I missing the libconfuse-dev package, but also libc6 version `GLIBC_2.38’ not found.

I see the problem and have added it to the dependencies. Thanks for pointing it out.

1 Like

I think the same method will work on ARM64 machine since it also puts the fip.bin(, which is the FIP format defined in ARM Trusted Firmware Design) in the vfat partition. All we have to do is to replace the opensbi firmware and the kernel.

image boot.vfat {
	vfat {
		label = "boot"
		files = {
			"fip.bin",
			"rawimages/boot.sd",
		}
	}
	size = 128M
}

However, I haven’t try it.

1 Like

Unfortunately, no:

pre-build-binary/genimage: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=ae1bba05e90ae82a0ce90f165c45c2245bc01183, for GNU/Linux 3.2.0, with debug_info, not stripped

Not usable by alien architectures.

Oh, I thought you wanted to run an ARM system on the MilkV Duo-256M. If you want to run genimage on an ARM machine, maybe you can compile it from the source.

1 Like

Cool! Thanks, will try it.

Feels like I’m about to move to a ZFS volume with all these files…

Ideally, I’d like to assemble Milk-V related stuff on a Duo S. Just for fun.

LOL, no way:

host-tools/gcc/riscv64-linux-musl-x86_64/bin/riscv64-unknown-linux-musl-gcc: cannot execute binary file: Exec format error

Will require going even deeper, I guess.

1 Like

Nice work! Thanks for publishing this for the rest of us!

2 Likes

Thank you! Very cool!

1 Like