How to build last kernel linux(6.6.6) for JP6?

Hello,
I’m trying the last stable kernel linux 6.6.6 for Jetson AGX.

For desktop, I use:

sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison
latest_tag=$(git ls-remote --tags --sort='v:refname' https://github.com/torvalds/linux.git | tail -n1 | sed 's/.*\///; s/\^{}//')
kernel_version=$(echo $latest_tag | sed 's/^v//')

git clone --depth 1 --branch $latest_tag https://github.com/torvalds/linux.git "linux-$kernel_version"
cd "linux-$kernel_version"

# Crear la carpeta de salida si no existe
mkdir -p ./output

cp -v /boot/config-$(uname -r) .config
yes "" | scripts/config --disable SYSTEM_TRUSTED_KEYS
yes "" | scripts/config --disable SYSTEM_REVOCATION_KEYS
yes "" | make oldconfig

sudo make -j $(nproc)
sudo make -j $(nproc) modules_install
sudo make -j $(nproc) install 
# make -j $(nproc) deb-pkg

# Mover los archivos generados a la carpeta de salida
#mv ../*.deb ./output/
# cd ./output/

# sudo dpkg -i ../linux-headers-*.deb ../linux-image-*.deb

sudo update-initramfs -c -k $kernel_version  
sudo update-grub

It’s clear that jetson not has grub and needs specific drivers.
I read the documentation https://developer.nvidia.com/embedded/jetson-linux
Kernel Customization — Jetson Linux<br/>Developer Guide 34.1 documentation

But I have some questions.
How can I introduce 6.6.6 kernel in this Linux-Tegra after ./source_sync.sh?
Can I copy the default configuration from jp6?

Hi,
Please refer to the section in developer guide:
Bring Your Own Kernel — NVIDIA Jetson Linux Developer Guide 1 documentation

We don’t try the version. It would be great if you can try and share the experience.

1 Like


I’m working on that. Now, I’m Building the NVIDIA Out-of-Tree Modules.

WIP:
There are some errors in driver.c and mem_mgmt_utils.c with linux 6.6.7 that I fixed. When I have all errors fixed in drivers, and kernel working I will share it.
errors:
Error in driver.c: The error struct class has no member named ‘owner’ suggests that the class structure in the kernel you are compiling against does not have an owner field. This field was removed in recent Linux kernel versions. To resolve this, you can simply remove the line setting the owner field, as it’s no longer needed.

So, in your driver.c file, you can comment out or remove the line:
FIX:

hwpm_linux->class.owner = THIS_MODULE;

Error in mem_mgmt_utils.c: The error related to get_user_pages function indicates a change in the API of this function in newer kernel versions. The newer get_user_pages function has a reduced number of arguments. You’ll need to update the usage of get_user_pages to match the current kernel API.
FIX:

/* ... [previous code] ... */

/* Calculate the number of pages */
alist_buf_size = tegra_hwpm_safe_add_u64(offset, alist_buf_size);
alist_buf_size = tegra_hwpm_safe_sub_u64(
    tegra_hwpm_safe_add_u64(alist_buf_size, PAGE_SIZE), 1ULL);
hwpm->alist_map->num_pages = alist_buf_size / PAGE_SIZE;

/* Allocate memory for the pages array */
hwpm->alist_map->pages = (struct page **)tegra_hwpm_kcalloc(
    hwpm, hwpm->alist_map->num_pages, sizeof(struct page *));
if (!hwpm->alist_map->pages) {
    tegra_hwpm_err(hwpm, "Couldn't allocate memory for pages array");
    err = -ENOMEM;
    goto fail;
}

/* Set up get_user_pages call */
unsigned int gup_flags = 0; // Modify as needed based on your use case
pinned_pages = get_user_pages(user_va & PAGE_MASK, hwpm->alist_map->num_pages, gup_flags, hwpm->alist_map->pages);
if (pinned_pages != hwpm->alist_map->num_pages) {
    tegra_hwpm_err(hwpm, "Requested %llu pages / Got %ld pages",
        hwpm->alist_map->num_pages, pinned_pages);
    err = -ENOMEM;
    goto fail;
}

/* ... [rest of the function] ... */

WIP:

error oot driver:

  1. vm_flags Assignment Error:
  • The error assignment of read-only member ‘vm_flags’ suggests that the code is trying to modify a read-only structure member. Recent kernel versions may have made vm_flags read-only to prevent direct modification.
  • Solution: You might need to modify the driver code to use appropriate kernel APIs or mechanisms to achieve the desired functionality without directly modifying vm_flags.
  1. pci_disable_pcie_error_reporting Implicit Declaration:
  • This error suggests that the function pci_disable_pcie_error_reporting is not available or declared in the current kernel headers.
  • Solution: Check if this function is available in your kernel version. If not, you may need to update the driver code to use an alternative method or conditional compilation.
  1. iommu_map Function Signature Mismatch:
  • The iommu_map function’s signature has changed in recent kernel versions, and your driver code seems to be using an outdated signature.
  • Solution: Update the calls to iommu_map in the driver code to match the signature in your kernel version. Check the iommu.h header file for the correct signature.
  1. register_shrinker Signature Mismatch:
  • Similar to iommu_map, it seems that register_shrinker’s signature in your driver does not match that in the kernel.
  • Solution: Update the register_shrinker call in the driver code to match the kernel’s expected signature.

I fixed errors and more errors… now is imposible to update easily… I fixed more than 20 errors compilation and still I obtain. The code is outdated, needs to be upgraded for current kernels(6.6.7 in my case)
So I’m sticking with the version that jetpack 6 provides me.
My last error:

The compilation error you're encountering in the `ioctl_ctrl.c` 
file within the NVIDIA GPU drivers (`nvgpu` ) seems to be related 
to the use of the `mmap_write_trylock` function. 
This function is not available or not declared in your environment,
 leading to an implicit declaration warning, 
which is treated as an error due to the `-Werror` flag.

Hello!

Build errors with the latest Linux kernels are common and we are continuously working to fix these errors. However, there will always be a lag between new Linux kernels being released and the updates to the NVIDIA drivers being rolled out. The good news is that we have been working to fix the errors you encountered with v6.6 (and later kernels) and the latest drivers are now available on public git repositories.

This is what I would recommend …

  1. Sync the latest driver sources using the tag ‘rel-36_eng_2024-01-24’
    Kernel Customization — NVIDIA Jetson Linux Developer Guide 1 documentation

  2. Build the drivers against your kernel settings KERNEL_HEADERS environment variable as necessary.
    Kernel Customization — NVIDIA Jetson Linux Developer Guide 1 documentation

Hope this helps.
Jon

1 Like

I will inform you and create a video or post with my steps for everyone.

where is the link of public git?
Also when I synchronize, the kernel that it download is 5.15?

There are a total of 5 git trees that needed to be sync’ed …

  1. linux-hwpm - Gitiles
  2. linux-nv-oot - Gitiles
  3. linux-nvgpu - Gitiles
  4. kernel/nvethernetrm - Gitiles
  5. tegra/kernel-src/nv-kernel-display-driver - Gitiles

It is recommended that you use the ‘source_sync.sh’ script to sync these. The Makefile that is provided for building the drivers requires that they are placed in the appropriate location because there are some interdependencies (headers and symbols) between these repositories. Also there is a soft-link that the source_sync.sh script creates between the nvethernetrm and linux-nv-oot repositories.

Correct. The kernel sources that are downloaded is the v5.15 kernel that Jet Pack 6 uses by default.

1 Like

And the kernel that script download, is it 5.15 right??

Correct.

1 Like

I still have some errors but I hadn’t gotten this far until now.
Kernel that I’m using is 6.6.14

@jonathanh If i don’t put tag, is it synchronize with master from your repositories? That means WIP code?
I mean because with new tag either I can’t compile

You need to enable CONFIG_ARCH_HAS_PMEM_API in your kernel config and rebuild your kernel. This is required.

Do not use the master branch for the drivers. This does not point to the latest and the master branch is not updated. You need to use the latest tag that is populated.

1 Like

thanks a lot for your help.
Where is config from kernel 5.15?
Normally in x86 I do similar to this:

cp -v /boot/config-$(uname -r) .config
yes "" | scripts/config --disable SYSTEM_TRUSTED_KEYS
yes "" | scripts/config --disable SYSTEM_REVOCATION_KEYS
yes "" | make oldconfig

@jonathanh Is there any config from you that I can find to guide me?
if i do menuconfig where can i find CONFIG_ARCH_HAS_PMEM_API?

I saw that is not configurable. I put it manually in .config

Can you try enabling CONFIG_ARM64_PMEM=y in the defconfig?

https://nv-tegra.nvidia.com/r/plugins/gitiles/3rdparty/canonical/linux-jammy/+/refs/tags/rel-36_eng_2024-01-24/arch/arm64/configs/defconfig#83

1 Like

I compile it. But now it’s a new problem @jonathanh

I thinkt that it’s the same error that above a few months ago.
4. register_shrinker Signature Mismatch:

  • Similar to iommu_map, it seems that register_shrinker’s signature in your driver does not match that in the kernel.
  • Solution: Update the register_shrinker call in the driver code to match the kernel’s expected signature.

This should already be handled by the following code …

#if defined(NV_SHRINKER_ALLOC_PRESENT) /* Linux 6.7 */
	nvmap_page_pool_shrinker = shrinker_alloc(0, "nvmap_pp_shrinker");
	if (!nvmap_page_pool_shrinker) {
		goto fail;
	}
	nvmap_page_pool_shrinker->count_objects = nvmap_page_pool_count_objects;
	nvmap_page_pool_shrinker->scan_objects = nvmap_page_pool_scan_objects;
	nvmap_page_pool_shrinker->seeks = 1;
	shrinker_register(nvmap_page_pool_shrinker);
#else
#if defined(NV_REGISTER_SHRINKER_HAS_FMT_ARG) /* Linux v6.0 */
	register_shrinker(&nvmap_page_pool_shrinker, "nvmap_pp_shrinker");
#else
	register_shrinker(&nvmap_page_pool_shrinker);
#endif
#endif

https://nv-tegra.nvidia.com/r/plugins/gitiles/linux-nv-oot/+/refs/tags/rel-36_eng_2024-01-24/drivers/video/tegra/nvmap/nvmap_pp.c#778

Are you using the Makefile shipped with the JetPack BSP to build these? This Makefile is located under …

Linux_for_Tegra/source/Makefile

Prior to building the drivers this Makefile runs a script called conftest.sh to detect the versions of the APIs in the kernel. This then creates the necessary definitions for compiling the drivers. Otherwise, yes the build will most likely fail.