Skip to content

Finalized Automation scripts for x86-64 RT kernel Upgrade #345

Draft
jatinjb444 wants to merge 4 commits into
ni:nilrt/master/scarthgapfrom
jatinjb444:dev
Draft

Finalized Automation scripts for x86-64 RT kernel Upgrade #345
jatinjb444 wants to merge 4 commits into
ni:nilrt/master/scarthgapfrom
jatinjb444:dev

Conversation

@jatinjb444
Copy link
Copy Markdown

@jatinjb444 jatinjb444 commented Apr 9, 2026

Changes

This PR introduces automation to fetch and merge the latest stable‑RT kernel tags into the target NI Linux Real‑Time branch.
Key changes:

Automatically clone the NI Linux kernel repository in a clean workspace.
Fetch upstream stable‑RT tags from the RT kernel repository.
Identify and merge the latest applicable RT tag into the configured target branch.
Ensure a deterministic and clean git state before merging to support re‑runs and CI usage.
Send notification emails on successful merge or on merge failure with relevant details.

This automation is focused only on the fetch and merge workflow.
Kernel build and deployment steps will be added in follow‑up changes.

Update: April 14th , 2026
Get the Cross Compile toolchain from the nirvana path and set it
Build and install the kernel on the NI's target
Copied the modules to the target
Check the network configurations working fine after reboot

Update: May 5th , 2026
Automates out‑of‑tree driver rebuild after kernel installation.
Mounts kernel source on the target via SSHFS (no local copy).
Fixes build and source symlinks under /lib/modules/.
Prepares kernel headers and invokes dkms auto install.
Integrated into the existing kernel build and test flow

Update: May 7th , 2026
Implements US‑4 and US‑5 automation:
Regenerates nati_x86_64_defconfig when required
Adds gated kernel PR creation after successful RT merge, build, install, and driver rebuild
Failure paths send immediate notification; success sends a single final summary email

Kernel PR creation is guarded behind --skip-push-and-pr and is intended to be enabled only after review.

Testing

The changes were validated by:

Running the script in a fresh workspace to verify repository cloning and RT tag discovery.
Verifying that the latest stable‑RT tag is correctly detected and merged.

After the target reboot , was able to check the latest kernel version using - { uname -r }
Verified the network modules working fine after reboot.

Confirmed SSHFS mount, header preparation, and DKMS rebuild.
Validated rebuilt drivers using dkms status.

Process

Suggested Reviewers:
@rajendra-desai-ni
@Shreejit-03

@Shreejit-03
Copy link
Copy Markdown
Contributor

Please run flake8 ( python3 -m flake8 ) on all the python files and fix all the issues we can. Some of them could be fixed by running black (python3 -m black ).

@jatinjb444 jatinjb444 force-pushed the dev branch 6 times, most recently from dbeefde to e0fcb85 Compare May 5, 2026 05:45
@jatinjb444 jatinjb444 changed the title Finalized fetch and merge script for rt-tags Finalized Automation scripts for x86-64 RT kernel Upgrade May 7, 2026
@jatinjb444 jatinjb444 force-pushed the dev branch 3 times, most recently from 5328398 to 4709c45 Compare May 8, 2026 05:58
- Install kernel on target with reboot and SSH readiness checks.
- Rebuild out-of-tree drivers automatically using DKMS.
- Kernel source is mounted via SSHFS to avoid local copy.
- Fix build/source symlinks and prepare kernel headers.

Verified on real NI RT target with DKMS-managed drivers.
Signed-off-by: Jatin Bharti <jatin.bharti@emerson.com>
Signed-off-by: Jatin Bharti <jatin.bharti@emerson.com>
…ndling , formatted and cleaned up json.config

Signed-off-by: Jatin Bharti <jatin.bharti@emerson.com>

def __init__(self, automation_conf_path, work_item_id):
with open(automation_conf_path, "r", encoding="utf-8") as file:
def __init__(self, config_path, work_item_id):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to rename it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to make sure that the json config file is a generic config loader file, and not tied to work with automation_conf only.

self.ssh_connection = config.get("ssh_connection")
# Kernel build configuration (optional section)
kernel_config = config.get("kernel_build", {})
# Expand environment variables in paths
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the need for using environment variables

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah , i have changed it to standardize the overall json config file and use the paths explicitly.

self.work_item_id = config.get("work_item_id", "")
self.ssh_target = kernel_config.get("ssh_target")

def _expand_path(self, path):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we aren't making use of any environment variables, then this can be removed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — since we’re not relying on environment variable expansion right now, I can remove _expand_path and keep the paths explicit.

return 1


def run_cmd(cmd):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is run_cmd any different from run_command in its usage and implementation? It would be better to use run_command .

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes—run_cmd differs intentionally. run_command relies on shlex.split, which breaks SSH commands that include shell operators (||, &&, pipes, quoted remote commands). The rebuild/install steps depend on shell semantics, so run_cmd executes via the shell to preserve existing behavior.


git_fetch("origin")
git_checkout(config.target_branch, create=True, force_checkout=True)
git_reset(hard=True, target=f"origin/{config.target_branch}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the ni/linux repo will be freshly cloned, I don't really see the need for git_merge_abort(), git_reset(), git_clean().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just added for an extra check, but yes it can be removed if we are assuming it will work for cloning freshly every time .

print("[INFO] Cloning kernel repository")

repo = os.path.abspath(config.kernel_src_dir)
config.kernel_src_dir = repo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be handled in json_config.py.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure , i have handled it in the json_config.py

git_reset(hard=True, target=f"origin/{config.target_branch}")

_, remotes = git_remote()
if "stable-rt" not in remotes:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not use kernel_repo.add_remote()?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so since we already have a GitRepo instance here, I’ve switched to using kernel_repo.add_remote() to keep git operations encapsulated and consistent

Signed-off-by: Jatin Bharti <jatin.bharti@emerson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants