In this post I am going to take a look at rebuilding the Sheeva64’s kernel.  The Sheeva64 is a 64-bit ARM based single board computer based on a Marvell Armada 3720 SoC.  More information about the SoC can be found at Marvell’s website here (https://www.marvell.com/embedded-processors/armada/armada-3700/), or GlobalScale Technologies (the manufacturer) website here (https://www.globalscaletechnologies.com/p-86-sheeva64.aspx).

This process is also very similar to the guide at wiki.espressobin.net located here (http://wiki.espressobin.net/tiki-index.php?page=Software+HowTo).  The SoC is identical, but the board layout and peripherals are slightly different, therefore the exact kernel configuration won’t have all the drivers necessary for the Sheeva64, but it doesn’t hurt to give it a try, it won’t break anything.

First I would like to give credit to the origianl source for most of this located at the below link.
I would like to thank the author for deciphring all the logic in the Armbian.com build system so I could come up with some parts of these instructions.
http://tinkering-is-fun.blogspot.com/2019/02/espressobin-rebuilding-kernel-based-on.html

Next the Armbian.com website and their efforts to make a stand alone fully automated build solution for various single board computers, it is really quite impressive.  The system Armbian.com put together is a really, really nice build setup and recommend you try it if you have any supported boards.  Unfortinatly the Sheeva64 is not supported yet, but a very close match is the EspressoBin containing the exact same Marvell Armada 3720 SoC.
Because the peripherals and board are different the EspressoBin build will not work 100% correctly, but it helped me come up with the below script.  I sure hope they continue supporting and updating their build system.
(https://www.armbian.com/)

The actual Armbian.com build environment, to which I sourced some information, such as the toolchains and patches, is here.
https://github.com/armbian/build

I will try to provide references to original sources and give credit where appropiate.  This is an effort to provide a detailed resource to assist others with the Sheeva64 kernel building process, no harm intended.
If there is something used here that is not referenced properly, please let me know and I will add the appropriate references.

While I try to be accurate, it is possible I missed something or made some mistakes, please double check what you do before you blindly copy-paste and run commands, just incase.  Especially with updating the actual /boot files on the Sheeva64, and u-boot environment, please be very careful and double check.  Some mistakes in here can be costly and take time to fix.

I shouldn’t have to remind you to make back up copies of these items you are going to download, in original unmodified form, incase they ever go away.  More often than not external links will disapear, with no easy way to get ahold of them again.

For peace of mind I would make sure you have an offline copy of these instructions and all required source files.
To ensure you have a build environment that always works, a VM or VirtualMachine is not a bad idea, it will always work and keep its last used state.

Personally I make tar/bz2 backups of sources in their original state for archive purposes.  The below command will help with that (the dot on the end is important, don’t forget it).

tar -jcvpf your_file_name.tar.bz2 –directory=/path_to_folder_you_want_to_archive .

Now onto the actual kernel creation process

rename all the “/your_build_root” to your actual build root.

Create your working folder
cd /your_build_root
mkdir sheeva64_kernel_builder_20190926
cd /your_build_root/sheeva64_kernel_builder_20190926

Grab the configuration file for the Sheeva64, you can get it by one of the following methods below, although I may upload it here soon.
This file will be used as the initial kernel configuration to base your new kernel on, since it has a known working configuration.
For this to work best, the kernel version should match, all the way down to the 120 at the end of the version number.
Use one of the below commands, result should be the same.
cat /proc/config.gz | gunzip > config_4.4.120-armada-18.09.2-g302564291ad5
zcat /proc/config.gz > config_4.4.120-armada-18.09.2-g302564291ad5

For the kernel version running, you can use the below command to name the file accurately.
This sniplet of code is from the below source.
https://www.cyberciti.biz/faq/inux-kernel-where-to-find-modules/

echo “Modules dir: /lib/modules/$(uname -r) for kernel version $(uname -r)”

Next, grab the recommended toolchain from the below link.
https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz

Just use wget to grab it quick, if you would like a troublefree download.
wget https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz

You can see other files related to this toolchain by opening the folder
https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu
It is very likely others will work, but, this is what I used and works

Once you get this downloaded extract the tar file using the below command, it will end up in its own folder
tar -xvpf gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz

If the above link ever goes away, I will try to find a way to fix it or make it available

Grab kernel files from the Marvell repositiory
git clone https://github.com/MarvellEmbeddedProcessors/linux-marvell.git

It might be a good idea to archive these, just incase, but optional
tar -jcvpf linux-marvell_20190927.tar.bz2 –directory=/your_build_root/sheeva64_kernel_builder_20190926/linux-marvell .

Change to the linux-marvell folder
cd linux-marvell

Checkout the correct version, this version (branch) for sure works, I have not tested others, you are welcome to try other branches
git checkout linux-4.4.120-armada-18.09

Apply patches
This automation script was obtained from here
https://gitlab.com/snippets/1827562
Original maker’s webpage is here
http://tinkering-is-fun.blogspot.com/2019/02/espressobin-rebuilding-kernel-based-on.html

The patch files are from here https://github.com/armbian/build/tree/master/patch/kernel/meson64-default

You might find it easier just to use a git clone (git clone https://github.com/armbian/build) and download the entire repository, then copy out what you need instead of messing with downloading individual files.  These patches should be placed in the below folder to line up with the patch command, also below

/your_build_root/sheeva64_kernel_builder_20190926/patch/kernel/meson64-default

I believe the “https://github.com/armbian/build/tree/master/patch/kernel/meson64-next” folder is for later kernel versions, if you want to try that out, but I stuck with 4.14.120 since I know it works.

I believe these patches apply to 4.14.120, but not quite sure, they may already be patched into the linux-marvell source.
Including them just incase… it is possible you don’t need them
Currently this patch script also just runs all of the patches and applies the ones it can… maybe not the best way to do it, will get back to fixing it later

Run the next command inside the linux-marvell folder.
The working copy needs to be clean and there must be no untracked files.
Perform a “git reset –hard” to clean out any problems, all changes will be reverted to the last commit
A commit will be performed after each successful patch
Make sure the file is executable, if not fix it
chmod u+x ../apply-armbian-patches.sh
../apply-armbian-patches.sh ../patches/kernel/mvebu64-default/0005-patch-4.14.120-121.patch

Copy over the configuration file
cp ../config_4.4.120-armada-18.09.2-g302564291ad5 .config

Update .config if changing to a new kernel using make oldconfig.
CROSS_COMPILE=/your_build_root/sheeva64_kernel_builder_20190926/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- ARCH=arm64 make oldconfig

With our kernel sources now prepared, we can go onto configuration and the actual building.

Run menuconfig to customize the kernel, if you would like to, can skip this if you happy with the original configuration.
CROSS_COMPILE=/your_build_root/sheeva64_kernel_builder_20190926/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- ARCH=arm64 make menuconfig

Now is your chance to turn on any driver support you may want for USB serial devices, etc.

Finaly build the kernel.
It takes the i7-9700K CPU @ 3.60GHz running Linux Gentoo that I recently put together for compiling about 5 minutes or so to compile the kernel with its original options.
CROSS_COMPILE=/your_build_root/sheeva64_kernel_builder_20190926/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- ARCH=arm64 make

Double check kernel modules got built.
CROSS_COMPILE=/your_build_root/sheeva64_kernel_builder_20190926/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- ARCH=arm64 make modules

Copy out the kernel modules, be careful here, if you leave off the INSTALL_MOD_PATH it will attempt to copy into your /lib/modules folder!!!
CROSS_COMPILE=/your_build_root/sheeva64_kernel_builder_20190926/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- ARCH=arm64 make modules_install INSTALL_MOD_PATH=/your_build_root/sheeva64_kernel_builder_20190926/modules_install

You will find your shiny new kernel under this path, copy it out to where you choose
This file will eventually make its way into your Sheeva64’s /boot folder, but I would change the name and not overwrite the original, just incase.
arch/arm64/boot/Image

Also the kernel modules will be needed too, copy them into /lib/modules on the Sheeva64
/your_build_root/sheeva64_kernel_builder_20190926/modules_install/lib/modules/4.4.120-armada-18.09.2-g4b3df2c67631

The dtb file, or flattened device tree will be located here, you should not need to update it though, it will be slightly off since there is not one taylored specifically for the Sheeva64 and you will find some devices won’t work, or will be unstable.  If you choose to compile a different kernel version, this DTB file *might* need to be updated as well.
arch/arm64/boot/dts/marvell/
I can’t recommend a specific one since there is not a direct match for the Sheeva64, but you are welcome to experiment with any of the files marked for the armada-3720 if you want to test things out.

Thats it! Place your new kernel into your Sheeva64 and see if it boots up correctly!
Personally these are the steps I do to update the kernel.
+ scp the files over
+ the Image file goes in /boot but I would rename it to something like Image_20190927 and append the date, don’t overwrite your original
+ the copy the entire kernel modules folder, 4.4.120-armada-18.09.2-g4b3df2c67631, into /lib/modules
+ plug in the mini-USB cable
+ fire up minicom or a terminal program so I can see what the Sheeva64 is doing (115200-8-N-1, no flow control)
+ issue a sudo “shutdown -r now” to restart the Sheeva64 gracefully
+ interrupt the u-boot autoboot process on the terminal when it comes up
+ use “env edit image_name” to direct u-boot to boot the new kernel
+ use “env save” to save the above changes
+ use “boot” to continue the boot process, or “reset” to reset the Sheeva64 and let it autoboot

At this point, you can see in the terminal window if your kernel boots or not, if all goes well, you will see the login prompt
If there are any issues, freezes, or panics, there is a problem with your kernel build, missing an important driver, or other issues
If this is the case perform these steps to bring back the original kernel
+ restart the Sheeva64 by cycling power
+ interrupt the autoboot process in terminal
+ use “env edit image_name” to restore your previous kernel
+ use “env save” to save your changes
+ use “boot” to continue the boot process, or “reset” to reset the Sheeva64 and let it autoboot

Your Sheeva64 should now be back on the old kernel and booting up.
At this point you can try to identify what went wrong and attempt another kernel build changing options in menuconfig as necessary.

Leave a Reply

Your email address will not be published. Required fields are marked *