Skip to contentSkip to conversation

board: add support for Chromebook Snow

PATCH Superseded Alex Suykov 2 participants 3 messages Dec 27, 2015 – Jan 5, 2016

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 2/2 board: add support for Chromebook Snow

Chromebook Snow (Samsung XE303C12) is an Exynos 5 board with a keyboard, an 11 inch screen and a battery attached. It is relatively developer-friendly and can run mainline Linux kernels with little to no effort.

There is barely anything special about this target as far as toolchain is concerned, but its bootloader only accepts signed kernel images in a Chromium OS specific format, and is not controllable otherwise.

This config provides a script for building the proper kernel blobs, and a short manual for booting Buildroot images on the device.

The kernel defconfig is also provided. Mainline kernel already has exynos_defconfig which could have been used here, but it builds mwifiex statically, and that module tries to load its firmware during initialization.

Since the board was going to get a custom kernel config anyway, exynos_defconfig was trimmed to only include the drivers needed for this particular chip and this particular board.

---
v2: script to make complete SD card image
explicit kernel version in defconfig
comments and text updates
v3: host-dtc dependency
text tweaks

I'm messing with nv-boot on this board now, and while it does remove the kernel-signing part completely I don't think it is something that should go into buildroot board readme.
The signed-kpart way is also kind of officially recommended by Google.

 board/chromebook/snow/kernel.args      |   1 +
 board/chromebook/snow/kernel.its       |  34 +++++++
 board/chromebook/snow/linux-4.3.config | 161 +++++++++++++++++++++++++++++++++
 board/chromebook/snow/mksd.sh          |  72 +++++++++++++++
 board/chromebook/snow/readme.txt       | 145 +++++++++++++++++++++++++++++
 board/chromebook/snow/sign.sh          |  44 +++++++++
 configs/chromebook_snow_defconfig      |  24 +++++
 7 files changed, 481 insertions(+)
 create mode 100644 board/chromebook/snow/kernel.args
 create mode 100644 board/chromebook/snow/kernel.its
 create mode 100644 board/chromebook/snow/linux-4.3.config
 create mode 100755 board/chromebook/snow/mksd.sh
 create mode 100644 board/chromebook/snow/readme.txt
 create mode 100755 board/chromebook/snow/sign.sh
 create mode 100644 configs/chromebook_snow_defconfig
board/chromebook/snow/kernel.args new file +1 -0
new file mode 100644
index 0000000..1220bf8
@@ -0,0 +1 @@
+console=tty1 clk_ignore_unused root=/dev/mmcblk1p2 rootfstype=ext4 ro
board/chromebook/snow/kernel.its new file +34 -0
new file mode 100644
index 0000000..33f2c00
@@ -0,0 +1,34 @@
+/dts-v1/;
+
+/ {
+    description = "Buildroot kernel for Chromebook Snow";
+    images {
+        kernel at 1{
+            description = "kernel";
+            data = /incbin/("zImage");
+            type = "kernel";
+            arch = "arm";
+            os = "linux";
+            compression = "none";
+            load = <0x40008000>;
+            entry = <0x40008000>;
+        };
+        fdt at 1{
+            description = "exynos5250-snow.dtb";
+            data = /incbin/("exynos5250-snow.dtb");
+            type = "flat_dt";
+            arch = "arm";
+            compression = "none";
+            hash at 1{
+                algo = "sha1";
+            };
+        };
+    };
+    configurations {
+        default = "conf at 1";
+        conf at 1{
+            kernel = "kernel at 1";
+            fdt = "fdt at 1";
+        };
+    };
+};
board/chromebook/snow/linux-4.3.config new file +161 -0

161 lines not on this page · raw message

board/chromebook/snow/mksd.sh new file +72 -0

72 lines not on this page · raw message

board/chromebook/snow/readme.txt new file +145 -0

145 lines not on this page · raw message

board/chromebook/snow/sign.sh new file +44 -0

44 lines not on this page · raw message

configs/chromebook_snow_defconfig new file +24 -0
new file mode 100644
index 0000000..d73aceb
@@ -0,0 +1,24 @@
+BR2_arm=y
+BR2_cortex_a15=y
+BR2_KERNEL_HEADERS_4_3=y
+BR2_BINUTILS_VERSION_2_25_X=y
+BR2_GCC_VERSION_5_X=y
+BR2_TARGET_GENERIC_GETTY_PORT="tty1"
+BR2_TARGET_GENERIC_GETTY_TERM="linux"
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/chromebook/snow/sign.sh"
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/chromebook/snow/mksd.sh"
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_SAME_AS_HEADERS=y
+BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/chromebook/snow/linux-4.3.config"
+BR2_LINUX_KERNEL_ZIMAGE=y
+BR2_LINUX_KERNEL_DTS_SUPPORT=y
+BR2_LINUX_KERNEL_INTREE_DTS_NAME="exynos5250-snow"
+BR2_PACKAGE_LINUX_FIRMWARE=y
+BR2_PACKAGE_LINUX_FIRMWARE_MWIFIEX_SD8797=y
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
+BR2_PACKAGE_HOST_DTC=y
+BR2_PACKAGE_HOST_PARTED=y
+BR2_PACKAGE_HOST_UBOOT_TOOLS=y
+BR2_PACKAGE_HOST_VBOOT_UTILS=y
Signature · 1 line
2.6.4
#1 lore raw

PATCH v3 2/2 board: add support for Chromebook Snow

Dear Alex Suykov,

Thanks a lot for this patch. I believe it's almost ready to be applied, but there's a few minor nits that I'd like to see fixed beforehand. Overall, it's super nicely documented and explained, so really thanks a lot for this high quality patch.

Quoted 4 lines · Alex Suykov

The kernel defconfig is also provided. Mainline kernel already has exynos_defconfig which could have been used here, but it builds mwifiex statically, and that module tries to load its firmware during initialization.

And so the rootfs is not available by that time and the firmware loading fails? Does it work on other distros because they use an initramfs that is readily available with the firmware? It is somewhat sad that we can't use the exynos_defconfig.

If all you need is to override the mwifiex driver to be built as a module, then you can use a cool feature: fragment files. Use a configuration like this:

BR2_LINUX_KERNEL_DEFCONFIG="exynos" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/chromebook/snow/linux-4.3.fragment"

The board/chromebook/snow/linux-4.3.fragment file should contain the line:

CONFIG_MWIFIEX=m

And tada, your kernel configuration will have mwifiex as a module.

Quoted 11 lines
board/chromebook/snow/mksd.sh new file +5 -0
new file mode 100755
index 0000000..539eed7
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+# This scripts makes a minimal bootable SD card image for the Chromebook.
+# The resulting file is called bootsd.img. It should be written directly
+# to the card:

board/chromebook/snow/mksd.sh line 15

Quoted 10 lines
board/chromebook/snow/mksd.sh new file +10 -0
+#
+#	SD=/dev/mmcblk1		# check your device name!
+#	dd if=output/images/bootsd.img of=$SD
+#
+# The partitions are created just large enough to hold the kernel and
+# the rootfs image. Most of the card will be empty, and the secondary
+# GPT will not be in its proper location.
+
+output_images=${BINARIES_DIR:-output/images}
+output_host=${HOST_DIR:-output/host}

I don't think this ${BINARIES_DIR:-output/images} is needed. BINARIES_DIR and HOST_DIR are always passed in the environment when the script is called as a post-build or post-image script.

And if your argument is that the script might be called outside of a post-build or post-image script, then output/<foo> is not a great default since people could very well do out of tree build with Buildroot.

So, I'd prefer if you simply used directly ${HOST_DIR} and ${BINARIES_DIR} throughout the script.

board/chromebook/snow/mksd.sh line 41

Quoted 7 lines
board/chromebook/snow/mksd.sh new file +7 -0
+# The card is partitioned in sectors of 8KB.
+# 4 sectors are reserved for MBR+GPT. Their actual size turns out
+# to be 33 512-blocks which is just over 2 sectors, but we align
+# it to a nice round number.
+sec=8192
+kernelsec=$[(kernelsize+8191)>>13]
+rootfssec=$[(rootfssize+8191)>>13]

Is this sort of calculation POSIX compliant, or a bash extension? If a bash extension, then the shebang of the script should be #!/bin/bash

Quoted 15 lines
board/chromebook/snow/readme.txt new file +9 -0
new file mode 100644
index 0000000..4c2d8f5
@@ -0,0 +1,145 @@
+Samsung XE303C12 aka Chromebook Snow
+====================================
+
+This file describes booting the Chromebook from an SD card containing
+Buildroot kernel and rootfs, using the original bootloader. This is
+the least invasive way to get Buildroot onto the devices and a good
+starting point.
+
+The bootloader will only boot a kernel from a GPT partition marked

board/chromebook/snow/readme.txt line 19

Quoted 10 lines
board/chromebook/snow/readme.txt new file +10 -0
+bootable with cgpt tool from vboot-utils package.
+The kernel image must be signed using futility from the same package.
+The signing part is done by sign.sh script in this directory.
+
+It does not really matter where rootfs is as long as the kernel is able
+to find it, but this particular configuration assumes the kernel is on
+partition 1 and rootfs is on partition 2 of the SD card.
+Make sure to check kernel.args if you change this.
+
+

Nit: one empty new line is sufficient here.

board/chromebook/snow/readme.txt line 21

Quoted 2 lines
board/chromebook/snow/readme.txt new file +2 -0
+Making the boot media
+---------------------

Nit: one empty line would be good here (and ditto in the rest of the file).

Quoted 64 lines
board/chromebook/snow/readme.txt new file +64 -0
+Start by configuring and building the images.
+
+	make chromebook_snow_defconfig
+	make menuconfig # if necessary
+	make
+
+The important files are:
+
+	uImage.kpart (kernel and device tree, signed)
+	rootfs.tar
+	bootsd.img (SD card image containing both kernel and rootfs)
+
+Write the image directly to some SD card.
+WARNING: make sure there is nothing important on that card,
+and double-check the device name!
+
+	SD=/dev/mmcblk1		# may be /dev/sdX on some hosts
+	dd if=output/images/bootsd.img of=$SD
+
+
+Switching to developer mode and booting from SD
+-----------------------------------------------
+Power Chromebook down, then power it up while holding Esc+F3.
+BEWARE: switching to developer mode deletes all user data.
+Create backups if you need them.
+
+While in developer mode, Chromebook will boot into a white screen saying
+"OS verification is off".
+
+Press Ctrl-D at this screen to boot ChromeOS from eMMC.
+Press Ctrl-U at this screen to boot from SD (or USB)
+Press Power to power it off.
+Do NOT press Space unless you mean it.
+This will switch it back to normal mode.
+
+The is no way to get rid of the white screen without re-flashing the bootloader.
+
+
+Troubleshooting
+---------------
+Loud *BEEP* after pressing Ctrl-U means there's no valid partition to boot from.
+Which in turn means either bad GPT or improperly signed kernel.
+
+Return to the OS verification screen without any sounds means the code managed
+to reboot the board. May indicate properly signed but invalid image.
+
+Blank screen means the image is valid and properly signed but cannot boot
+for some reason, like missing or incorrect DT.
+
+In case the board becomes unresponsive:
+
+* Press Esc+F3+Power. The board should reboot instantly.
+  Remove SD card to prevent it from attempting a system recovery.
+
+* Hold Power button for around 10s. The board should shut down into
+  its soft-off mode. Press Power button again or open the lid to turn in on.
+
+* If that does not work, disconnect the charger and push a hidden
+  button on the underside with a pin of some sort. The board should shut
+  down completely. Opening the lid and pressing Power button will not work.
+  To turn it back on, connect the charger.
+
+
+Partitioning SD card manually

board/chromebook/snow/readme.txt line 95

Quoted 10 lines
board/chromebook/snow/readme.txt new file +10 -0
+----------------------------
+Check mksd.sh for partitioning commands.
+
+Use parted and cgpt on a real device, and calculate the partition
+sizes properly. The kernel partition may be as small as 4MB, but
+you will probably want the rootfs to occupy the whole remaining space.
+
+cgpt may be used to check current layout:
+
+	output/hosst/usr/bin/cgpt show $SD

typo: hosst -> host.

Quoted 13 lines
board/chromebook/snow/readme.txt new file +13 -0
+
+All sizes and all offsets are in 512-byte blocks.
+
+
+Writing kernel and rootfs to a partitioned SD card
+--------------------------------------------------
+Write .kpart directly to the bootable partition:
+
+	dd if=output/images/uImage.kpart of=${SD}1
+
+Make a new filesystem on the rootfs partition, and unpack rootfs.tar there:
+
+	mkfs.ext4 ${SD}2

board/chromebook/snow/readme.txt line 118

Quoted 10 lines
board/chromebook/snow/readme.txt new file +10 -0
+	mount ${SD2} /mnt/<ROOTFS-PARTITION>
+	tar -xvf output/images/rootfs.tar -C /mnt/<ROOTFS-PARTITION>
+	umount /mnt/<ROOTFS-PARTITION>
+
+This will require root permissions even if you can write to $SD.
+
+
+Kernel command line
+-------------------
+The command line is taken from board/chromebook/kernel.args and stored

The path is board/chromebook/snow/kernel.args.

Quoted 6 lines
board/chromebook/snow/sign.sh new file +0 -0
new file mode 100755
index 0000000..396f7fa

board/chromebook/snow/sign.sh line 8

Quoted 8 lines
board/chromebook/snow/sign.sh new file +8 -0
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# This script creates u-boot FIT image containing the kernel and the DT,
+# then signs it using futility from vboot-utils.
+# The resulting file is called uImage.kpart.
+
+output_images=${BINARIES_DIR:-$PWD/output/images}
+output_host=${HOST_DIR:-$PWD/output/host}

Ditto previous script.

board/chromebook/snow/sign.sh line 10

Quoted 1 line
board/chromebook/snow/sign.sh new file +1 -0
+board=$PWD/board/chromebook/snow

you could also do:

BOARD_DIR=$(dirname $0)

Quoted 40 lines
board/chromebook/snow/sign.sh new file +34 -0
+mkimage=$output_host/usr/bin/mkimage
+futility=$output_host/usr/bin/futility
+devkeys=$output_host/usr/share/vboot/devkeys
+
+run() { echo "$@"; "$@"; }
+die() { echo "$@" >&2; exit 1; }
+test -f $output_images/zImage || \
+	die "No kernel image found"
+test -x $mkimage || \
+	die "No mkimage found (host-uboot-tools has not been built?)"
+test -x $futility || \
+	die "No futility found (host-vboot-utils has not been built?)"
+
+# kernel.its references zImage and exynos5250-snow.dtb, and all three
+# files must be in current directory for mkimage.
+run cd $output_images || exit 1
+cp $board/kernel.its ./kernel.its || exit 1
+run $mkimage -f kernel.its uImage.itb
+
+# futility requires non-empty file to be supplied with --bootloader
+# even if it does not make sense for the target platform.
+echo > dummy.txt
+
+run $futility vbutil_kernel \
+	--keyblock $devkeys/kernel.keyblock \
+	--signprivate $devkeys/kernel_data_key.vbprivk \
+	--arch arm \
+	--version 1 \
+	--config $board/kernel.args \
+	--vmlinuz uImage.itb \
+	--bootloader dummy.txt \
+	--pack uImage.kpart
+
+rm -f kernel.its dummy.txt
configs/chromebook_snow_defconfig new file +0 -0
new file mode 100644
index 0000000..d73aceb

configs/chromebook_snow_defconfig line 3

Quoted 3 lines
configs/chromebook_snow_defconfig new file +3 -0
@@ -0,0 +1,24 @@
+BR2_arm=y
+BR2_cortex_a15=y
+BR2_KERNEL_HEADERS_4_3=y

Please use:

BR2_KERNEL_HEADERS_VERSION=y
BR2_DEFAULT_KERNEL_VERSION="4.3"
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_3=y

So that we stay at 4.3 even if the option BR2_KERNEL_HEADERS_4_3 disappears (which it will, since 4.3 is not a long term version).

configs/chromebook_snow_defconfig line 5

Quoted 2 lines
configs/chromebook_snow_defconfig new file +2 -0
+BR2_BINUTILS_VERSION_2_25_X=y
+BR2_GCC_VERSION_5_X=y

Can you tried without overriding those values? We prefer to use the default version for the toolchain components, unless there's a strong reason to do otherwise.

Quoted 9 lines
configs/chromebook_snow_defconfig new file +9 -0
+BR2_TARGET_GENERIC_GETTY_PORT="tty1"
+BR2_TARGET_GENERIC_GETTY_TERM="linux"
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/chromebook/snow/sign.sh"
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/chromebook/snow/mksd.sh"
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_SAME_AS_HEADERS=y
+BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/chromebook/snow/linux-4.3.config"
+BR2_LINUX_KERNEL_ZIMAGE=y

configs/chromebook_snow_defconfig line 24

Quoted 10 lines
configs/chromebook_snow_defconfig new file +10 -0
+BR2_LINUX_KERNEL_DTS_SUPPORT=y
+BR2_LINUX_KERNEL_INTREE_DTS_NAME="exynos5250-snow"
+BR2_PACKAGE_LINUX_FIRMWARE=y
+BR2_PACKAGE_LINUX_FIRMWARE_MWIFIEX_SD8797=y
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
+BR2_PACKAGE_HOST_DTC=y
+BR2_PACKAGE_HOST_PARTED=y
+BR2_PACKAGE_HOST_UBOOT_TOOLS=y
+BR2_PACKAGE_HOST_VBOOT_UTILS=y

The rest looks good, thanks! Can you rework to take into account the various comments I made?

Thanks a lot!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH v3 2/2 board: add support for Chromebook Snow

Quoted 7 lines · Thomas Petazzoni
Quoted 4 lines

The kernel defconfig is also provided. Mainline kernel already has exynos_defconfig which could have been used here, but it builds mwifiex statically, and that module tries to load its firmware during initialization.

And so the rootfs is not available by that time and the firmware loading fails?

Yes, and it never retries, just gives up on the device.

Quoted 2 lines

Does it work on other distros because they use an initramfs that is readily available with the firmware?

That particular defconfig expects the whole system to reside in initrd, judging by their kernel command line.

Big distros typically have custom kernel configs, and tend to avoid static modules, so it's probably not a issue for them. And many use initramfs anyway.

Quoted 2 lines

If all you need is to override the mwifiex driver to be built as a module, then you can use a cool feature: fragment files.

I was not aware of this. Yes, a simple fragment to turn mwifiex into a module is enough, the rest of exynos_defconfig is perfectly usable.

Quoted 10 lines

board/chromebook/snow/mksd.sh line 41

Quoted 7 lines
board/chromebook/snow/mksd.sh new file +7 -0
+# The card is partitioned in sectors of 8KB.
+# 4 sectors are reserved for MBR+GPT. Their actual size turns out
+# to be 33 512-blocks which is just over 2 sectors, but we align
+# it to a nice round number.
+sec=8192
+kernelsec=$[(kernelsize+8191)>>13]
+rootfssec=$[(rootfssize+8191)>>13]

Is this sort of calculation POSIX compliant, or a bash extension? If a bash extension, then the shebang of the script should be #!/bin/bash

Looks like changing $[ ] to $(( )) makes it POSIX compliant, even with bitshifts. At least that works in dash. And with ${var:-value} expressions gone, I think it's ok to leave /bin/sh there.

Quoted 6 lines

configs/chromebook_snow_defconfig line 5

Quoted 2 lines
configs/chromebook_snow_defconfig new file +2 -0
+BR2_BINUTILS_VERSION_2_25_X=y
+BR2_GCC_VERSION_5_X=y

Can you tried without overriding those values? We prefer to use the default version for the toolchain components, unless there's a strong reason to do otherwise.

No reason at all, I wonder why it got into defconfig. It's a Cortex-A15, nothing special about it, so I think it will work with pretty much any ARM7 toolchain.

The rest fixed, and I got it working with nv-uboot, so I'm sending v4.