Dev/OPi/OPiZero/From Scratch: Difference between revisions

From Embeded Linux (and more) Wiki by Nathael
< Dev‎ | OPi‎ | OPiZero
Jump to navigation Jump to search
 
Line 59: Line 59:
=== Use ===
=== Use ===
* Linux Kernel
* Linux Kernel
Compilation result is in arch/arm64/boot/Image
Compilation result is in arch/arm/boot/Image
* Device tree
* Device tree
Use the sun50i-h6-orangepi-3.dtb device-tree (found in arch/arm64/boot/dts/allwinner/)
Use the sun8i-h2-plus-orangepi-zero.dtb device-tree (found in arch/arm/boot/dts/) or sun8i-h2-plus-orangepi-zero-ed3l.dtb from my [http://data.nathael.net/Dev/OPi/OPiZero/ shared ressources].
* Modules
* Modules
If the compilation has been performed using the above command lines you should have a directory "Build/Mods/lib/modules/***" (*** = name of the kernel you just compiled)<br />
If the compilation has been performed using the above command lines you should have a directory "Build/Mods/lib/modules/***" (*** = name of the kernel you just compiled)<br />

Latest revision as of 12:54, 25 September 2020

u-boot

Grab the sources

git clone git://git.denx.de/u-boot.git
cd u-boot
git checkout v2019.07

Compile

make CROSS_COMPILE=arm-linux-gnueabihf- orangepi_zero_defconfig
make -j8 CROSS_COMPILE=arm-linux-gnueabihf-

Use

Erase the first Mo of the SD card while keeping the partition table:

dd if=/dev/zero of=${card} bs=1k count=1023 seek=1

Copy uboot images to the SD card:

dd if=u-boot-sunxi-with-spl.bin of=${card} bs=1024 seek=8

Create file "boot.cmd" :

# default values
setenv kernel_image "Image-5.3.0-ed3l"
setenv rootdev "/dev/mmcblk0p2"
setenv fdtfile "sun50i-h6-orangepi-3.dtb"

setenv consoleargs "console=ttyS0,115200"
setenv usbstoragequirks "0x2537:0x1066:u,0x2537:0x1068:u"

# Print boot source
itest.b *0x10028 == 0x00 && echo "U-boot loaded from SD"
itest.b *0x10028 == 0x02 && echo "U-boot loaded from eMMC or secondary SD"
itest.b *0x10028 == 0x03 && echo "U-boot loaded from SPI"

echo "Boot script loaded from ${devtype}"

setenv bootargs "${consoleargs} root=${rootdev} rw rootwait usb-storage.quirks=${usbstoragequirks} quiet"
# setenv bootargs "${consoleargs} root=${rootdev} rw rootwait ignore_loglevel console_loglevel=4"

load ${devtype} ${devnum} ${fdt_addr_r} ${fdtfile}
load ${devtype} ${devnum} ${kernel_addr_r} ${kernel_image}

booti ${kernel_addr_r} - ${fdt_addr_r}

# Recompile with:
# mkimage -C none -A arm -T script -d boot.cmd boot.scr

Convert boot.cmd to boot.scr using mkimage :

mkimage -C none -A arm -T script -d boot.cmd boot.scr

Put boot.scr file in the first partition of the SD card (with the kernel and the device tree)

Linux Kernel

Grab the sources

  • Kernel 5.3 from kernel.org
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

Compile

mkdir -p Build/linux
cd linux
make ARCH=arm -j8 O=../Build/linux/ sunxi_defconfig
make ARCH=arm -j8 O=../Build/linux/ CROSS_COMPILE=arm-linux-gnueabihf-
make ARCH=arm -j8 O=../Build/linux/ CROSS_COMPILE=arm-linux-gnueabihf- dtbs
make ARCH=arm -j8 O=../Build/linux/ CROSS_COMPILE=arm-linux-gnueabihf- modules_install INSTALL_MOD_PATH=../Mods

Use

  • Linux Kernel

Compilation result is in arch/arm/boot/Image

  • Device tree

Use the sun8i-h2-plus-orangepi-zero.dtb device-tree (found in arch/arm/boot/dts/) or sun8i-h2-plus-orangepi-zero-ed3l.dtb from my shared ressources.

  • Modules

If the compilation has been performed using the above command lines you should have a directory "Build/Mods/lib/modules/***" (*** = name of the kernel you just compiled)
You must copy the whole directory (not only the content) on the SD card, in the partition holding the root filesystem (rootfs), in the /lib/modules/ directory without changing the name.

SD Card creation

Original information from linux-sunxi wiki

SD card architecture

start sector size usage
0KB 0 8KB Unused, available for an MBR or (limited) GPT partition table
8KB 16 32KB Initial SPL loader
40KB 80 - U-Boot proper

Typically partitions start at 1MB (which is the default setting of most partitioning tools), but there is no hard requirement for this, so U-Boot can grow bigger than 984KB, if needed.

The 8KB offset is dictated by the BROM, it will check for a valid eGON/TOC0 header at this location. The 40KB offset for U-Boot proper is the default U-Boot setting and can be changed at build time using the CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR configuration variable.

Cleaning

Erase the first Mo of the SD card while keeping the partition table:

dd if=/dev/zero of=${card} bs=1k count=1023 seek=1

(Use count=1024 and remove "seek" option to also erase the partition table)

Bootloader

Copy uboot images (u-boot-sunxi-with-spl.bin, found in u-boot main directory after compilation) to the SD card:

dd if=u-boot-sunxi-with-spl.bin of=${card} bs=1024 seek=8

The file "u-boot-sunxi-with-spl.bin" seems to be an aggregate of spl/u-boot-spl.bin and u-boot.bin

First partition

The first partition must start at +1Mo, and be a few Mo (50 Mo should be OK) and be formated using ext2/3/4
Place the files "zImage", "sun8i-h2-plus-orangepi-zero.dtb" and "boot.scr" on the first partition.

Second partition

The second partition must be formated using ext4 and starts right after the first one. It can take all the remaining size unless you have other specific needs.

This partition holds the root filesystem (rootfs).

Rootfs

This board uses an ARM processor with hardfloat support, thus the root filesystem should be built using "arm-linux-gnueabihf-" cross-toolchain or use the armhf architecture for Devuan or other Debian based distribution.

Refer to the rootfs creation page for more information. You should find a base Devuan rootfs here : rootfs_devuan_ceres_armhf_***.tar.bz2.