diff mbox series

[3/4] board/odroidc2: add board

Message ID 20200717164643.4702-3-daggs@gmx.com
State Accepted
Headers show
Series [1/4] meson-tools: new Package | expand

Commit Message

Dagg Stompler July 17, 2020, 4:46 p.m. UTC
re add the odroidc2 board to buildroot.
 - uses latest uboot.
 - uses kernel 5.6

Signed-off-by: Dagg Stompler <daggs@gmx.com>
---
 board/hardkernel/odroidc2/boot.cmd            | 11 ++++
 board/hardkernel/odroidc2/genimage.cfg        | 33 +++++++++++
 board/hardkernel/odroidc2/post-build.sh       |  8 +++
 board/hardkernel/odroidc2/post-image.sh       | 29 ++++++++++
 board/hardkernel/odroidc2/readme.txt          | 57 +++++++++++++++++++
 .../rootfs_overlay/etc/init.d/S09modload      | 23 ++++++++
 6 files changed, 161 insertions(+)
 create mode 100644 board/hardkernel/odroidc2/boot.cmd
 create mode 100644 board/hardkernel/odroidc2/genimage.cfg
 create mode 100755 board/hardkernel/odroidc2/post-build.sh
 create mode 100755 board/hardkernel/odroidc2/post-image.sh
 create mode 100644 board/hardkernel/odroidc2/readme.txt
 create mode 100755 board/hardkernel/odroidc2/rootfs_overlay/etc/init.d/S09modload

--
2.27.0

Comments

Thomas Petazzoni Sept. 3, 2020, 6:53 p.m. UTC | #1
Hello Dagg,

On Fri, 17 Jul 2020 19:46:42 +0300
Dagg Stompler <daggs@gmx.com> wrote:

> re add the odroidc2 board to buildroot.
>  - uses latest uboot.
>  - uses kernel 5.6

This patch and the next one should have been one single patch. And in
fact you're using Linux 5.7, not 5.6.

> diff --git a/board/hardkernel/odroidc2/genimage.cfg b/board/hardkernel/odroidc2/genimage.cfg
> new file mode 100644
> index 0000000000..a36b924b08
> --- /dev/null
> +++ b/board/hardkernel/odroidc2/genimage.cfg
> @@ -0,0 +1,33 @@
> +image boot.vfat {
> +	vfat {
> +		files = {
> +			"Image",
> +			"meson-gxbb-odroidc2.dtb",
> +			"boot.scr"
> +		}
> +	}
> +	size = 64M
> +}
> +
> +image sdcard.img {
> +	hdimage {
> +	}

I've added here an entry to flash the bl1.bin.hardkernel into the
sdcard.img file instead of doing it manually in the post-image script.

> +
> +	partition u-boot {
> +		in-partition-table = "no"
> +		image = "uboot-odc2.img"
> +		offset = 49664
> +	}
> +
> +	partition boot {
> +		partition-type = 0xC
> +		bootable = "true"
> +		image = "boot.vfat"
> +	}
> +
> +	partition rootfs {
> +		partition-type = 0x83
> +		image = "rootfs.ext4"
> +		size = 512M
> +	}
> +}
> diff --git a/board/hardkernel/odroidc2/post-build.sh b/board/hardkernel/odroidc2/post-build.sh
> new file mode 100755
> index 0000000000..745fb2a724
> --- /dev/null
> +++ b/board/hardkernel/odroidc2/post-build.sh
> @@ -0,0 +1,8 @@
> +#!/bin/sh
> +# post-build.sh for Odroid C2 taken from CubieBoard's post-build.sh
> +# 2013, Carlo Caione <carlo.caione@gmail.com>
> +
> +BOARD_DIR="$(dirname $0)"
> +MKIMAGE=$HOST_DIR/bin/mkimage
> +
> +${MKIMAGE} -A arm64 -O linux -T script -C none -n "Boot script" -d "${BOARD_DIR}/boot.cmd" ${BINARIES_DIR}/boot.scr

This was not useful, as this is already done by:

BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/hardkernel/odroidc2/boot.cmd"

so I've dropped the post-build script entirely.

> diff --git a/board/hardkernel/odroidc2/post-image.sh b/board/hardkernel/odroidc2/post-image.sh
> new file mode 100755
> index 0000000000..3783a65a1c
> --- /dev/null
> +++ b/board/hardkernel/odroidc2/post-image.sh
> @@ -0,0 +1,29 @@
> +#!/bin/sh
> +
> +BOARD_DIR="$(dirname $0)"
> +GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
> +GENIMAGE_CFG="${BOARD_DIR}/genimage.cfg"
> +SIGNED_UBOOT_IMG="${BINARIES_DIR}/uboot-odc2.img"
> +ODRODIDC2_ATF_FOLDER="${HOST_DIR}/usr/share/odroidc2_atf"
> +IM_FILE="${ODRODIDC2_ATF_FOLDER}/bl1.bin.hardkernel"
> +
> +${HOST_DIR}/bin/fip_create --bl30 ${ODRODIDC2_ATF_FOLDER}/bl30.bin --bl301 ${ODRODIDC2_ATF_FOLDER}/bl301.bin --bl31 ${ODRODIDC2_ATF_FOLDER}/bl31.bin --bl33 ${BINARIES_DIR}/u-boot.bin ${BINARIES_DIR}/fip.bin
> +${HOST_DIR}/bin/fip_create --dump ${BINARIES_DIR}/fip.bin
> +cat ${ODRODIDC2_ATF_FOLDER}/bl2.package ${BINARIES_DIR}/fip.bin > ${BINARIES_DIR}/boot_new.bin
> +${HOST_DIR}/bin/amlbootsig ${BINARIES_DIR}/boot_new.bin ${BINARIES_DIR}/u-boot.img
> +
> +dd if=${BINARIES_DIR}/u-boot.img of=${SIGNED_UBOOT_IMG} bs=512 skip=96
> +
> +rm -rf "${GENIMAGE_TMP}"
> +
> +genimage                           \
> +	--rootpath "${TARGET_DIR}"     \
> +	--tmppath "${GENIMAGE_TMP}"    \
> +	--inputpath "${BINARIES_DIR}"  \
> +	--outputpath "${BINARIES_DIR}" \
> +	--config "${GENIMAGE_CFG}"

I've simplified this by using support/scripts/genimage.sh.

> +dd if=${IM_FILE} of=${BINARIES_DIR}/sdcard.img bs=1 count=442 conv=sync,notrunc
> +dd if=${IM_FILE} of=${BINARIES_DIR}/sdcard.img bs=512 skip=1 seek=1 conv=fsync,notrunc

This was no longer needed as bl1.bin.hardkernel is now taken care of by
genimage directly.

> +rm -rf ${BINARIES_DIR}/fip.bin ${BINARIES_DIR}/boot_new.bin ${BINARIES_DIR}/u-boot.img

It's not necessary to clean things up this way.

Overall, this allowed to simplify the post-image script quite a bit.

See the final commit at:

  https://git.buildroot.org/buildroot/commit/?id=c8ee85ecd91c0b36be8694224b80846a276a849e

Could you check if it works for you, on the hardware platform ?

Thanks!

Thomas
diff mbox series

Patch

diff --git a/board/hardkernel/odroidc2/boot.cmd b/board/hardkernel/odroidc2/boot.cmd
new file mode 100644
index 0000000000..d800a6d44b
--- /dev/null
+++ b/board/hardkernel/odroidc2/boot.cmd
@@ -0,0 +1,11 @@ 
+setenv kernel_filename "Image"
+setenv fdt_filename "meson-gxbb-odroidc2.dtb"
+setenv bootargs "console=ttyAML0,115200n8 earlyprintk root=/dev/mmcblk1p2 rootwait rw"
+
+echo > Loading Kernel...
+fatload mmc 0:1 ${kernel_addr_r} ${kernel_filename}
+echo > Loading FDT...
+fatload mmc 0:1 ${fdt_addr_r} ${fdt_filename}
+
+echo > Booting System...
+booti ${kernel_addr_r} - ${fdt_addr_r}
diff --git a/board/hardkernel/odroidc2/genimage.cfg b/board/hardkernel/odroidc2/genimage.cfg
new file mode 100644
index 0000000000..a36b924b08
--- /dev/null
+++ b/board/hardkernel/odroidc2/genimage.cfg
@@ -0,0 +1,33 @@ 
+image boot.vfat {
+	vfat {
+		files = {
+			"Image",
+			"meson-gxbb-odroidc2.dtb",
+			"boot.scr"
+		}
+	}
+	size = 64M
+}
+
+image sdcard.img {
+	hdimage {
+	}
+
+	partition u-boot {
+		in-partition-table = "no"
+		image = "uboot-odc2.img"
+		offset = 49664
+	}
+
+	partition boot {
+		partition-type = 0xC
+		bootable = "true"
+		image = "boot.vfat"
+	}
+
+	partition rootfs {
+		partition-type = 0x83
+		image = "rootfs.ext4"
+		size = 512M
+	}
+}
diff --git a/board/hardkernel/odroidc2/post-build.sh b/board/hardkernel/odroidc2/post-build.sh
new file mode 100755
index 0000000000..745fb2a724
--- /dev/null
+++ b/board/hardkernel/odroidc2/post-build.sh
@@ -0,0 +1,8 @@ 
+#!/bin/sh
+# post-build.sh for Odroid C2 taken from CubieBoard's post-build.sh
+# 2013, Carlo Caione <carlo.caione@gmail.com>
+
+BOARD_DIR="$(dirname $0)"
+MKIMAGE=$HOST_DIR/bin/mkimage
+
+${MKIMAGE} -A arm64 -O linux -T script -C none -n "Boot script" -d "${BOARD_DIR}/boot.cmd" ${BINARIES_DIR}/boot.scr
diff --git a/board/hardkernel/odroidc2/post-image.sh b/board/hardkernel/odroidc2/post-image.sh
new file mode 100755
index 0000000000..3783a65a1c
--- /dev/null
+++ b/board/hardkernel/odroidc2/post-image.sh
@@ -0,0 +1,29 @@ 
+#!/bin/sh
+
+BOARD_DIR="$(dirname $0)"
+GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+GENIMAGE_CFG="${BOARD_DIR}/genimage.cfg"
+SIGNED_UBOOT_IMG="${BINARIES_DIR}/uboot-odc2.img"
+ODRODIDC2_ATF_FOLDER="${HOST_DIR}/usr/share/odroidc2_atf"
+IM_FILE="${ODRODIDC2_ATF_FOLDER}/bl1.bin.hardkernel"
+
+${HOST_DIR}/bin/fip_create --bl30 ${ODRODIDC2_ATF_FOLDER}/bl30.bin --bl301 ${ODRODIDC2_ATF_FOLDER}/bl301.bin --bl31 ${ODRODIDC2_ATF_FOLDER}/bl31.bin --bl33 ${BINARIES_DIR}/u-boot.bin ${BINARIES_DIR}/fip.bin
+${HOST_DIR}/bin/fip_create --dump ${BINARIES_DIR}/fip.bin
+cat ${ODRODIDC2_ATF_FOLDER}/bl2.package ${BINARIES_DIR}/fip.bin > ${BINARIES_DIR}/boot_new.bin
+${HOST_DIR}/bin/amlbootsig ${BINARIES_DIR}/boot_new.bin ${BINARIES_DIR}/u-boot.img
+
+dd if=${BINARIES_DIR}/u-boot.img of=${SIGNED_UBOOT_IMG} bs=512 skip=96
+
+rm -rf "${GENIMAGE_TMP}"
+
+genimage                           \
+	--rootpath "${TARGET_DIR}"     \
+	--tmppath "${GENIMAGE_TMP}"    \
+	--inputpath "${BINARIES_DIR}"  \
+	--outputpath "${BINARIES_DIR}" \
+	--config "${GENIMAGE_CFG}"
+
+dd if=${IM_FILE} of=${BINARIES_DIR}/sdcard.img bs=1 count=442 conv=sync,notrunc
+dd if=${IM_FILE} of=${BINARIES_DIR}/sdcard.img bs=512 skip=1 seek=1 conv=fsync,notrunc
+
+rm -rf ${BINARIES_DIR}/fip.bin ${BINARIES_DIR}/boot_new.bin ${BINARIES_DIR}/u-boot.img
diff --git a/board/hardkernel/odroidc2/readme.txt b/board/hardkernel/odroidc2/readme.txt
new file mode 100644
index 0000000000..ef5a91d453
--- /dev/null
+++ b/board/hardkernel/odroidc2/readme.txt
@@ -0,0 +1,57 @@ 
+ODROID-C2
+
+Intro
+=====
+To be able to use ODROID-C2 board with the images generated by
+Buildroot, you have to prepare the SDCard or eMMC.
+
+How to build it
+===============
+
+  $ make odroidc2_defconfig
+
+Then you can edit the build options using
+
+  $ make menuconfig
+
+Compile all and build rootfs image:
+
+  $ make
+
+Note: you will need to have access to the network, since Buildroot will
+download the packages' sources.
+
+Result of the build
+-------------------
+
+After building, you should obtain this tree:
+
+    output/images/
+    +-- Image
+    +-- uImage			   [2]
+    +-- boot.scr                   [1]
+    +-- boot.vfat
+    +-- meson-gxbb-odroidc2.dtb
+    +-- rootfs.ext2
+    +-- rootfs.ext4
+    +-- rootfs.tar
+    +-- sdcard.img
+    +-- uboot-odc2.img		   [3]
+    `-- u-boot.bin
+
+[1] This is the ODROID-C2 configuration file used in u-boot.
+[2] This is the ODROID-C2 kernel image file which will be booted.
+[3] This is the ODROID-C2 signed u-boot image which will be used.
+
+How to write the SD card or eMMC
+================================
+
+Once the build process is finished you will have an image called "sdcard.img"
+in the output/images/ directory.
+
+Copy the bootable "sdcard.img" onto an SD card or eMMC with "dd":
+
+  $ sudo dd if=output/images/sdcard.img of=/dev/sdX
+
+Insert the SDcard into your ODROID-C2, and power it up. Your new system
+should come up now.
diff --git a/board/hardkernel/odroidc2/rootfs_overlay/etc/init.d/S09modload b/board/hardkernel/odroidc2/rootfs_overlay/etc/init.d/S09modload
new file mode 100755
index 0000000000..8d694a7331
--- /dev/null
+++ b/board/hardkernel/odroidc2/rootfs_overlay/etc/init.d/S09modload
@@ -0,0 +1,23 @@ 
+#!/bin/sh
+#
+
+load_drivers()
+{
+	echo "Loading needed modules..."
+	for file in $(echo "dwmac_generic dwmac-meson8b meson_dw_hdmi meson_gxbb_wdt"); do
+		modprobe ${file}
+	done
+}
+
+case "$1" in
+	start)
+		load_drivers
+		;;
+	stop)
+		;;
+	restart|reload)
+		;;
+	*)
+		echo "Usage: $0 {start|stop|restart}"
+		exit 1
+esac