Skip to content

DevTerm R‐01 Create OS image from scratch

emutyworks edited this page Jun 25, 2022 · 21 revisions

DevTerm R‐01

**This procedure was done with "Raspberry Pi 3B + SSD + Ubuntu Server 22.04 LTS".

**This is not yet complete. I will update soon.

- Prepare
$ sudo apt update
$ sudo apt install gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
$ sudo apt install qemu-user-static
$ sudo apt install build-essential
$ sudo apt install bison flex
$ sudo apt install libncurses5-dev libncursesw5-dev
$ sudo apt install swig
$ sudo apt install python3-dev libssl-dev

- SPL(Boot0)
$ git clone https://github.com/smaeul/sun20i_d1_spl
$ pushd sun20i_d1_spl
$ git checkout origin/mainline
$ make CROSS_COMPILE=riscv64-linux-gnu- p=sun20iw1p1 mmc

- Flash to SD card
$ sudo fdisk -l
$ sudo dd if=nboot/boot0_sdcard_sun20iw1p1.bin of=/dev/sdc1 bs=512 seek=16
$ popd

- OpenSBI
$ git clone https://github.com/tekkamanninja/opensbi -b allwinner_d1
$ pushd opensbi
$ CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PIC=y BUILD_INFO=y make
$ popd

- U-boot
$ git clone https://github.com/tekkamanninja/u-boot -b allwinner_d1
$ pushd u-boot
$ make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv nezha_defconfig
$ make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv menuconfig
----------
Deveice Drivers --->
  MMC Host controller Support  --->
    [*] Poll for broken card detection case
----------
$ make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv u-boot.bin u-boot.dtb

- Build u-boot.toc1
$ vi toc1.cfg
----------
[opensbi]
file = fw_dynamic.bin
addr = 0x40000000
[dtb]
file = u-boot.dtb
addr = 0x44000000
[u-boot]
file = u-boot.bin
addr = 0x4a000000
----------
$ cp ../opensbi/build/platform/generic/firmware/fw_dynamic.bin .
$ tools/mkimage -T sunxi_toc1 -d toc1.cfg u-boot.toc1

- Flash u-boot.toc1 to SD card
$ sudo dd if=u-boot.toc1 of=/dev/sdc1 bs=512 seek=32800
$ popd

- Create disk image file
$ MEGA=16777216
$ dd if=/dev/zero bs=$MEGA count=1024 of=disk.img
$ echo -e "o\nn\np\n2\n69632\n319487\nn\np\n3\n319488\n1320959\nn\np\n4\n1320960\n\n\nt\n2\nc\na\n3\n\nw" | fdisk disk.img
$ fdisk -l disk.img
----------
Device     Boot   Start      End  Sectors  Size Id Type
disk.img2         69632   319487   249856  122M  c W95 FAT32 (LBA)
disk.img3  *     319488  1320959  1001472  489M 83 Linux
disk.img4       1320960 33554431 32233472 15.4G 83 Linux
----------

$ sudo losetup --show -f -P disk.img #/dev/loop3
$ sudo mkfs.vfat /dev/loop3p2
$ sudo mkfs.ext4 /dev/loop3p3
$ sudo mkfs.ext4 /dev/loop3p4

Clone this wiki locally