TX2 rt-patch

Hi,
I’m following this guide: https://github.com/kozyilmaz/nvidia-jetson-rt/blob/master/docs/README.03-realtime.md to patch the kernel with rt-patch.
at the step of: make -j4 O=$TEGRA_KERNEL_OUT ARCH=ARCH zImage I fail: nvidia@tegra-ubuntu:~/nvidia/kernel/kernel-4.4 make -j4 O=$TEGRA_KERNEL_OUT ARCH=$ARCH zImage
make[1]: Entering directory ‘/home/nvidia/nvidia/tegra-jetson-tx2-kernel’
/home/nvidia/nvidia/install/bin/aarch64-unknown-linux-gnu-gcc: 1: /home/nvidia/nvidia/install/bin/aarch64-unknown-linux-gnu-gcc: Syntax error: “(” unexpected
GEN ./Makefile
scripts/kconfig/conf --silentoldconfig Kconfig

configuration written to .config

/home/nvidia/nvidia/install/bin/aarch64-unknown-linux-gnu-gcc: 1: /home/nvidia/nvidia/install/bin/aarch64-unknown-linux-gnu-gcc: Syntax error: “(” unexpected
CHK include/config/kernel.release
GEN ./Makefile
WRAP arch/arm64/include/generated/asm/bug.h
WRAP arch/arm64/include/generated/asm/checksum.h
WRAP arch/arm64/include/generated/asm/bugs.h
WRAP arch/arm64/include/generated/asm/cputime.h
WRAP arch/arm64/include/generated/asm/clkdev.h
WRAP arch/arm64/include/generated/asm/current.h
WRAP arch/arm64/include/generated/asm/delay.h
CHK include/generated/uapi/linux/version.h
WRAP arch/arm64/include/generated/asm/div64.h
WRAP arch/arm64/include/generated/asm/dma.h
UPD include/generated/uapi/linux/version.h
WRAP arch/arm64/include/generated/asm/dma-contiguous.h
WRAP arch/arm64/include/generated/asm/early_ioremap.h
WRAP arch/arm64/include/generated/asm/emergency-restart.h
WRAP arch/arm64/include/generated/asm/errno.h
UPD include/config/kernel.release
WRAP arch/arm64/include/generated/asm/ftrace.h
WRAP arch/arm64/include/generated/asm/hw_irq.h
WRAP arch/arm64/include/generated/asm/ioctl.h
WRAP arch/arm64/include/generated/asm/ipcbuf.h
WRAP arch/arm64/include/generated/asm/irq_regs.h
WRAP arch/arm64/include/generated/asm/ioctls.h
WRAP arch/arm64/include/generated/asm/kdebug.h
WRAP arch/arm64/include/generated/asm/kvm_para.h
WRAP arch/arm64/include/generated/asm/local.h
WRAP arch/arm64/include/generated/asm/mcs_spinlock.h
WRAP arch/arm64/include/generated/asm/local64.h
WRAP arch/arm64/include/generated/asm/kmap_types.h
WRAP arch/arm64/include/generated/asm/mman.h
WRAP arch/arm64/include/generated/asm/msgbuf.h
WRAP arch/arm64/include/generated/asm/msi.h
WRAP arch/arm64/include/generated/asm/mutex.h
WRAP arch/arm64/include/generated/asm/pci.h
HOSTCC scripts/basic/bin2c
WRAP arch/arm64/include/generated/asm/pci-bridge.h
WRAP arch/arm64/include/generated/asm/mm-arch-hooks.h
WRAP arch/arm64/include/generated/asm/poll.h
WRAP arch/arm64/include/generated/asm/preempt.h
WRAP arch/arm64/include/generated/asm/resource.h
WRAP arch/arm64/include/generated/asm/rwsem.h
WRAP arch/arm64/include/generated/asm/sections.h
WRAP arch/arm64/include/generated/asm/segment.h
WRAP arch/arm64/include/generated/asm/sembuf.h
WRAP arch/arm64/include/generated/asm/serial.h
WRAP arch/arm64/include/generated/asm/simd.h
WRAP arch/arm64/include/generated/asm/shmbuf.h
WRAP arch/arm64/include/generated/asm/sizes.h
WRAP arch/arm64/include/generated/asm/socket.h
WRAP arch/arm64/include/generated/asm/sockios.h
WRAP arch/arm64/include/generated/asm/swab.h
WRAP arch/arm64/include/generated/asm/switch_to.h
WRAP arch/arm64/include/generated/asm/termbits.h
WRAP arch/arm64/include/generated/asm/termios.h
WRAP arch/arm64/include/generated/asm/topology.h
WRAP arch/arm64/include/generated/asm/types.h
WRAP arch/arm64/include/generated/asm/unaligned.h
WRAP arch/arm64/include/generated/asm/user.h
WRAP arch/arm64/include/generated/asm/vga.h
WRAP arch/arm64/include/generated/asm/xor.h
WRAP arch/arm64/include/generated/asm/trace_clock.h
WRAP arch/arm64/include/generated/uapi/asm/kvm_para.h
Using /home/nvidia/nvidia/kernel/kernel-4.4 as source for kernel
CHK include/generated/utsrelease.h
UPD include/generated/utsrelease.h
Generating include/generated/mach-types.h
HOSTCC scripts/kallsyms
HOSTCC scripts/dtc/dtc.o
CC scripts/mod/empty.o
HOSTCC scripts/dtc/flattree.o
/home/nvidia/nvidia/install/bin/aarch64-unknown-linux-gnu-gcc: 1: /home/nvidia/nvidia/install/bin/aarch64-unknown-linux-gnu-gcc: Syntax error: “(” unexpected
/home/nvidia/nvidia/kernel/kernel-4.4/scripts/Makefile.build:261: recipe for target ‘scripts/mod/empty.o’ failed
make[3]: *** [scripts/mod/empty.o] Error 2
/home/nvidia/nvidia/kernel/kernel-4.4/scripts/Makefile.build:406: recipe for target ‘scripts/mod’ failed
make[2]: *** [scripts/mod] Error 2
make[2]: *** Waiting for unfinished jobs…
HOSTCC scripts/dtc/fstree.o
HOSTCC scripts/dtc/data.o
HOSTCC scripts/dtc/livetree.o
HOSTCC scripts/dtc/treesource.o
CC kernel/bounds.s
/home/nvidia/nvidia/install/bin/aarch64-unknown-linux-gnu-gcc: 1: /home/nvidia/nvidia/install/bin/aarch64-unknown-linux-gnu-gcc: Syntax error: “(” unexpected
/home/nvidia/nvidia/kernel/kernel-4.4/./Kbuild:44: recipe for target ‘kernel/bounds.s’ failed
make[2]: *** [kernel/bounds.s] Error 2
/home/nvidia/nvidia/kernel/kernel-4.4/Makefile:1019: recipe for target ‘prepare0’ failed
make[1]: *** [prepare0] Error 2
make[1]: *** Waiting for unfinished jobs…
HOSTCC scripts/dtc/srcpos.o
HOSTCC scripts/dtc/checks.o
HOSTCC scripts/dtc/util.o
SHIPPED scripts/dtc/dtc-lexer.lex.c
SHIPPED scripts/dtc/dtc-parser.tab.h
SHIPPED scripts/dtc/dtc-parser.tab.c
HOSTCC scripts/dtc/dtc-lexer.lex.o
HOSTCC scripts/dtc/dtc-parser.tab.o
HOSTLD scripts/dtc/dtc
/home/nvidia/nvidia/kernel/kernel-4.4/Makefile:556: recipe for target ‘scripts’ failed
make[1]: *** [scripts] Error 2
make[1]: Leaving directory ‘/home/nvidia/nvidia/tegra-jetson-tx2-kernel’
Makefile:150: recipe for target ‘sub-make’ failed
make: *** [sub-make] Error 2

please help me, thanks in advance

How did you create the initial configuration prior to build? What was the exact build command line?

Hi Avner.Gidron:
Excuse me, where did you download your patch? Is it collect fees or free? Please tell me exactly how to get this patch?

Hi,
As I wrote in the post, “I’m following this guide: https://github.com/kozyilmaz/nvidia-jetson-rt/blob/master/docs/README.03-realtime.md to patch the kernel with rt-patch”
all the configuration and build command line are from there (build command is also in my original post: “make -j4 O=$TEGRA_KERNEL_OUT ARCH=$ARCH zImage”

this patch is downloaded from here: https://developer.nvidia.com/embedded/linux-tegra-r281

For those interested, the RT patches are free. I don’t know how well they work though. The particular URL says to use with the L4T R28.1 release, and the kernel there is somewhat recent so it should be ok with newer releases.

One suggestion you could try…replace this command with an unmodified running system’s config:

make O=$TEGRA_KERNEL_OUT ARCH=$ARCH tegra18_defconfig

When you use tegra18_defconfig you are taking a possible configuration, renaming it to “.config”, and using that as a starting point. On a running Jetson you can find “/proc/config.gz” is a reflection of the actual system’s configuration…that is not a real file, it is the kernel telling you exactly what it is at that moment. Copy config.gz somewhere, gunzip it, and wherever your “$TEGRA_KERNEL_OUT” is, put “.config” there. Then make all configuration edits there via “make nconfig” or “make menuconfig” (may require adding “libncurses5-dev”: “sudo apt-get install libncurses5-dev”).

In the early days the defconfig was a match for what the Jetsons ship with. I don’t believe this is true now. You would still have to match the “CONFIG_LOCALVERSION” since this is the one part of config.gz which is not an exact match, but you should consider this the place to start instead of tegra18_defconfig. Maybe it won’t help, but you really can’t trust a config which is edited with an ordinary editor (and not a configuration editor), or a config which is different from what you currently run and know to work.

Note (not related to your issue): You can build zImage, which also builds the uncompressed Image first, but you only need Image. You could save a tiny amount with just “make Image” instead of “make zImage”. It was in the transition from 32-bit to 64-bit that Jetsons stopped using zImage.

The instructions you followed had this line:

export CROSS_COMPILE=aarch64-unknown-linux-gnu-

Which version is the compiler in question? If you don’t know, then this might say:

aarch64-unknown-linux-gnu-gcc --version

(not all compiler versions work for this)

If that still fails, then I do recall some Makefile issues with some options in earlier releases…those might be showing up in R28.1 but I think that was from before R28.1.

It seems as if the compiler in the gcc-4.8.5-aarch64 package is not working correctly.
the aarch64-unknown-linux-gnu-gcc is placed in this folder and it is not working when I try to get it’s version:

~/nvidia/install/aarch64-unknown-linux-gnu/bin/gcc --version
bash: /home/nvidia/nvidia/install/aarch64-unknown-linux-gnu/bin/gcc: cannot execute binary file: Exec format error

by the name of the folder it seems that it is 4.8.5.
trying to compile the kernel with 5.4.0 gets me further than the one in the package but fails to.
I tried to use the existing config and same results.
I also tried using newer version of the rt-patch 28.2.1 as it is for same version of kernel as mine (4.4.38) but still no luck.
Any other idea?
maybe if I will install other instance of gcc 4.8.5 it will work?

I should back up and make sure I have your environment correct in my mind.

  • Are you compiling natively on the TX2?
  • Or are you cross compiling on a desktop PC host? What do you see from wherever you compile via "uname -p"?
  • What do you see from "file ~/nvidia/install/aarch64-unknown-linux-gnu/bin/gcc"?

(1) Yes, I’m compiling on the TX2.
(2) output of “uname -p”:

nvidia@tegra-ubuntu:~$ uname -p
aarch64

(3) output of “file ~/nvidia/install/aarch64-unknown-linux-gnu/bin/gcc”:

nvidia@tegra-ubuntu:~$ file ~/nvidia/install/aarch64-unknown-linux-gnu/bin/gcc
/home/nvidia/nvidia/install/aarch64-unknown-linux-gnu/bin/gcc: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.24, BuildID[sha1]=f36837f48003dacbe0c3febceae1f762df882f75, not stripped

There’s the problem…you don’t cross compile when on the TX2, and that is a cross compiler meant for a desktop PC. The native TX2 compiler is arm64 and produces arm64. A native PC compiler is x86_64 (or the 32-bit PC version…i386) and produces x86_64. This particular compiler is a cross compiler which runs on x86_64 PC and produces arm64 output. Most of the instructions you see in official documentation are intended for compile from a separate host PC.

There will be a native gcc without using “~/anything…” (type “which gcc” and it should show “/usr/bin/gcc”). No need to name ARCH since it is native, no need for CROSS_COMPILE.

ok, I understand now, so I tried same steps on Ubuntu 18.04 host desktop, but still it failes at same place.

When cross compiling there is more environment setup and you have to have the cross tools installed. If compiling a kernel, then only the cross compiler plus various setup of environment variables. The official documents with that particular release describe the setup in kernel customization section when the host is an Ubuntu desktop PC.

For native compile directly on the TX2 it is somewhat simpler, but you would still need to be familiar with a few basic steps for kernel builds (and you’d want to get rid of the JetPack content on the TX2…it isn’t meant to be on the TX2 other than the source_sync.sh script).

So for the desktop PC cross compile I suggest first go here:
https://developer.nvidia.com/embedded/linux-tegra-archive

Check your current version on the Jetson:

head -n 1 /etc/nv_tegra_release

My assumption is that you are using R28.2.1 (the most recent release for a TX2…although I suspect there will be a new release not too far in the future). Thus:
https://developer.nvidia.com/embedded/linux-tegra-r2821

This is important because actual kernel install steps can differ between older and newer releases (but compile steps will be the same). You will find “Documentation”, e.g.:
https://developer.nvidia.com/embedded/dlc/l4t-documentation-28-2-ga
(I don’t know if you need to sign in there…it would be a separate login from forums if needed…if so, then you might need to log in and then go there a second time)

Save a copy of your running system’s “/proc/config.gz”. This should be uncompressed (gunzip), a pristine copy saved somewhere safe, and then another copy renamed “.config”. If you need information on the CONFIG_LOCALVERSION just ask, but typically when the base kernel is modified you will need to make this something custom and install both the kernel and the modules. I might be tempted to make it something like this:

CONFIG_LOCALVERSION="-rt_patch1"

(and I would increment the “1” each time I try something different…after this the “uname -r” will append “-rt_patch1” and modules will be searched for in “/lib/modules/$(uname -r)/”)

To emphasize, if you were to follow the original instructions there would be a step for “make tegra18_defconfig”, but this produces a default “.config”…having a copy from the original system is superior because you know exactly how it works…sometimes “make *_defconfig” is the same as the shipping config.gz, but not always.

Kernel customization information is given in those documents (they unpack and you point your web browser at the HTML docs). If you wish to do native compile just ask if you need more information.

Note that for “make menuconfig” or “make nconfig” style config editors to work you need to first install package “libncurses5-dev”:

sudo apt-get install libncurses5-dev