Port linux mainline on Khadas VIM
This tutorial is about how to port linux mainline on Khadas VIM.
Preperations:
Before starting
Create the working directories:
$ install -d ~/project/khadas/ubuntu/{linux,rootfs,archives/{ubuntu-base,debs,hwpacks},images,scripts}
$ cd ~/project/khadas/ubuntu/
Clone the utils
repository to fetch the tools for development:
$ git clone https://github.com/khadas/utils.git
Build U-Boot:
Download the U-Boot source tree, take a notice of the branch ubuntu
as the option when you run git clone
:
$ git clone https://github.com/khadas/u-boot -b ubuntu
You should modify bootargs
to support linux mainline:
diff --git a/board/khadas/configs/kvim.h b/board/khadas/configs/kvim.h
index 540b09c..3e9dda2 100644
--- a/board/khadas/configs/kvim.h
+++ b/board/khadas/configs/kvim.h
@@ -88,7 +88,7 @@
"fb_height=1080\0" \
"bootdisk=ramdisk\0" \
"bootargs=" \
- "root=LABEL=ROOTFS rootflags=data=writeback rw logo=osd1,loaded,0x3d800000,1080p60hz vout=1080p60hz,enable hdmimode=1080p60hz console=ttyS0,115200n8 console=tty0 no_consol
+ "root=/dev/mmcblk0p1 rootflags=data=writeback rw rootwait console=ttyAML0,115200 console=tty0 earlyprintk=aml-uart,0xc81004c0 fsck.repair=yes governor=ondemand no_console_suspend elevator=noop\0" \
"\0" \
/* boot partition name for dual boot
Build for Khadas VIM:
$ cd u-boot/
$ make kvim_defconfig
$ make -j8 CROSS_COMPILE=aarch64-linux-gnu-
Generated files:
- fip/u-boot.bin: bootloader blob for eMMC
- fip/u-boot.bin.sd.bin: bootloader blob for SD card
- fip/u-boot.bin.usb.tpl: third program loader for USB burning
- fip/u-boot.bin.usb.bl2: bootloader blob for USB disk(āFIXMEā)
Build linux mainline:
Fetch the linux mainline repository from Linus Torvaldsās GitHub repository:
$ cd ~/project/khadas/ubuntu/linux
$ git remote add torvalds https://github.com/torvalds/linux.git
$ git fetch torvalds master
$ git checkout remotes/torvalds/master
Configure Ethernet:
$ make ARCH=arm64 defconfig
$ make ARCH=arm64 menuconfig
Configure the following:
CONFIG_NET_VENDOR_STMICRO=y
CONFIG_STMMAC_ETH=y
CONFIG_STMMAC_PLATFORM=y
CONFIG_DWMAC_GENERIC=y
CONFIG_DWMAC_IPQ806X=y
CONFIG_DWMAC_MESON=y
Configure HDMI, add HDMI DTS node:
diff --git a/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dts b/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dts
index 5df1dbc..9083de5 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dts
+++ b/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dts
@@ -55,6 +55,29 @@
linux,default-trigger = "default-on";
};
};
+
+ hdmi-connector {
+ compatible = "hdmi-connector";
+ type = "a";
+
+ port {
+ hdmi_connector_in: endpoint {
+ remote-endpoint = <&hdmi_tx_tmds_out>;
+ };
+ };
+ };
+};
+
+&hdmi_tx {
+ status = "okay";
+ pinctrl-0 = <&hdmi_hpd_pins>, <&hdmi_i2c_pins>;
+ pinctrl-names = "default";
+};
+
+&hdmi_tx_tmds_port {
+ hdmi_tx_tmds_out: endpoint {
+ remote-endpoint = <&hdmi_connector_in>;
+ };
};
Disable scpi clock:
diff --git a/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dts b/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dts
index 72c5a9f..ee70893 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dts
+++ b/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dts
@@ -135,3 +135,7 @@
pinctrl-0 = <&uart_ao_b_pins>;
pinctrl-names = "default";
};
+
+&scpi_clocks {
+ status = "disabled";
+};
Bulid:
$ cd ~/project/khadas/ubuntu/linux
$ touch .scmversion
$ make -j8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image amlogic/meson-gxl-s905x-khadas-vim.dtb modules
Build rootfs
Create an SD card with one partition in ext4 format
$ sudo umount /dev/sdb1
$ sudo mkfs.ext4 /dev/sdb1
Mount SD card on /mnt
$ sudo mount /dev/sdb1 /mnt/
$ cd /mnt
$ sudo rm -rf * lost+found/
Download the Ubuntu-base tarball from official Ubuntu website:
$ sudo wget http://cdimage.ubuntu.com/ubuntu-base/releases/16.04.2/release/ubuntu-base-16.04.2-base-arm64.tar.gz
Extract the ubuntu-base tarball into the mounted folder:
$ sudo tar -xzf ubuntu-base-16.04.2-base-arm64.tar.gz
$ sudo rm -rf ubuntu-base-16.04.2-base-arm64.tar.gz
And now you have already completed the basic rootfs, check it:
$ ls /mnt
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
Install the qemu so you can run chroot to arm64:
$ sudo apt-get install qemu qemu-user-static binfmt-support debootstrap
It would be better for you to understand the qemu on ARM64 first.
Install linux kernel modules
$ cd ~/project/khadas/ubuntu/linux
$ sudo make -j8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_install INSTALL_MOD_PATH=/mnt
Check it:
$ ls /mnt/lib/modules
4.12.0-rc5
$ ls /mnt/lib/modules/4.12.0-rc5/
build modules.alias modules.builtin modules.dep modules.devname modules.softdep modules.symbols.bin
kernel modules.alias.bin modules.builtin.bin modules.dep.bin modules.order modules.symbols source
$
Chroot and setup
Setup the Chroot environment:
$ sudo cp -a /usr/bin/qemu-aarch64-static /mnt/usr/bin/
$ sudo mount -o bind /proc /mnt/proc
$ sudo mount -o bind /sys /mnt/sys
$ sudo mount -o bind /dev /mnt/dev
$ sudo mount -o bind /dev/pts /mnt/dev/pts
Tips:
-
/usr/bin/qemu-arm-static
is for 32-bit armhf architecture -
/usr/bin/qemu-aarch64-static
is for 64-bit arm64 architecture
Enter the arm64 Chroot:
$ sudo chroot /mnt/
Note: Now you are in the target emulator.
The first thing must be setup a password for the root user:
# echo root:khadas | chpasswd
Follow the prompts to complete the setup.
You might also want to create an administrator user with āsudoā permission:
# useradd -G sudo -m -s /bin/bash khadas
# echo khadas:khadas | chpasswd
Tips: The format input line of chpasswd
is: āuser_name:passwordā. Run man chpasswd
for further info.
Setup a hostname for your target device:
# echo Khadas > /etc/hostname
# echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts
# echo "127.0.0.1 Khadas" >> /etc/hosts
Setup DNS resolver:
# echo "nameserver 127.0.1.1" > /etc/resolv.conf
Fetch the latest package lists from server:
# apt-get update
Upgrade:
# apt-get upgrade
Install the network packages:
# apt-get install ifupdown net-tools
Install udev device manager:
# apt-get install udev
Install packages to suit your taste:
# apt-get install vim sudo ssh
Install initramfs-tools package:
# apt-get install initramfs-tools
Build the ramdisk:
# mkinitramfs -o /boot/initrd.img 4.12.0-rc5
Install fbset package:
# apt-get install fbset
When everything you want to setup has been done, exit the Chroot:
# exit
Generate ramdisk.img
$ sudo cp /mnt/boot/initrd.img /mnt/initrd.img
$ cd ~/project/khadas/ubuntu
$ sudo ./utils/mkbootimg --kernel linux/arch/arm64/boot/Image --ramdisk /mnt/initrd.img -o /mnt/ramdisk.img
Copy dtb to SD card:
$ cd ~/project/khadas/ubuntu
$ sudo cp linux/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-khadas-vim.dtb /mnt
Umount
Remember to synchronize cached writes to persistent storage first:
$ sudo sync
Umount:
$ sudo umount /mnt/dev/pts
$ sudo umount /mnt/dev
$ sudo umount /mnt/proc
$ sudo umount /mnt/sys
$ sudo umount /mnt
Reference:
Installation
Install U-boot on SD card:
$ umount /dev/sdb1
$ cd ~/project/khadas/ubuntu/u-boot
$ sudo dd if=./fip/u-boot.bin.sd.bin of=/dev/sdb conv=fsync,notrunc bs=1 count=444
$ sudo dd if=./fip/u-boot.bin.sd.bin of=/dev/sdb conv=fsync,notrunc bs=512 skip=1 seek=1
$ sudo eject /dev/sdb
Check it:
Ensure that you have done the right setup of Serial to USB module.
In order to check the bootable SD card, you might also need to make sure that all the data stored in the onboard eMMC has been wipe out.
Reference:
Test
Insert the SD card to VIM board, hit Enter
and power on, then you will enter uboot command line.
Setup uboot environment:
kvim# setenv bootcmd "ext4load mmc 0 1080000 ramdisk.img;ext4load mmc 0 5080000 meson-gxl-s905x-khadas-vim.dtb;bootm 1080000 - 5080000"
kvim# save
kvim# reset