mirror of
https://github.com/rosalinux/image-builder.git
synced 2025-02-23 10:22:50 +00:00
add func and template to generate kernel.spec for defined device
This commit is contained in:
parent
a03aed2198
commit
21cec0479c
3 changed files with 129 additions and 0 deletions
|
@ -1,14 +1,19 @@
|
|||
ARCH="aarch64"
|
||||
|
||||
KERNEL="https://github.com/raspberrypi/linux.git#rpi-6.6.y"
|
||||
KERNEL_CONFIG="bcm2711_defconfig"
|
||||
KERNEL_EXTRACONFIG="--module NTFS3_FS --enable NTFS3_LZX_XPRESS --enable NTFS3_FS_POSIX_ACL --disable NTFS3_64BIT_CLUSTER"
|
||||
DTB="broadcom/bcm2711-rpi-4-b"
|
||||
|
||||
CMDLINE="dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait"
|
||||
NEED_INITRD=no
|
||||
|
||||
# disk section
|
||||
# /boot is vfat partition
|
||||
BOOT_FSTYPE="vfat"
|
||||
BOOT_SIZE="256MB"
|
||||
# / is ext4 partition
|
||||
ROOT_FSTYPE="ext4"
|
||||
ROOT_SIZE="1024MB"
|
||||
|
||||
PRESET_CONFIG="local_config"
|
||||
|
|
83
utils/generate_spec.py
Normal file
83
utils/generate_spec.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
from common import load_config
|
||||
|
||||
def get_kernel_version(kernel_url, branch):
|
||||
"""Extract kernel version from kernel URL and branch"""
|
||||
return branch
|
||||
|
||||
def generate_spec_file(vendor, device):
|
||||
"""Generate RPM spec file from template and config"""
|
||||
# Load device config
|
||||
config_path = os.path.join("device", vendor, device, "config")
|
||||
if not os.path.exists(config_path):
|
||||
print(f"Error: Config file not found at {config_path}")
|
||||
sys.exit(1)
|
||||
|
||||
config = load_config(config_path)
|
||||
|
||||
# Load template
|
||||
template_path = os.path.join("utils", "kernel.template")
|
||||
if not os.path.exists(template_path):
|
||||
print(f"Error: Template file not found at {template_path}")
|
||||
sys.exit(1)
|
||||
|
||||
with open(template_path, 'r') as f:
|
||||
template = f.read()
|
||||
|
||||
# Extract kernel version from kernel URL and branch
|
||||
kernel_url, kernel_branch = config["KERNEL"].split("#")
|
||||
kernel_version = get_kernel_version(kernel_url, kernel_branch)
|
||||
|
||||
# Determine KERNEL_ARCH and CROSS_COMPILE based on ARCH
|
||||
arch = config.get("ARCH", "unknown")
|
||||
kernel_config = config.get("KERNEL_CONFIG", "unknown")
|
||||
if arch == "aarch64":
|
||||
kernel_arch = "arm64"
|
||||
cross_compile = "aarch64-linux-gnu"
|
||||
else:
|
||||
kernel_arch = arch
|
||||
cross_compile = f"{arch}-linux-gnu" # Default cross compile format
|
||||
|
||||
# Prepare replacements
|
||||
device_name = f"{vendor}-{device}"
|
||||
replacements = {
|
||||
"{BOARD_NAME}": device_name,
|
||||
"{KERNEL_VERSION}": kernel_version,
|
||||
"{DEVICE_NAME}": device_name,
|
||||
"{KERNEL_ARCH}": kernel_arch,
|
||||
"{ARCH}": arch, # Add ARCH replacement
|
||||
"{KERNEL_CONFIG}": kernel_config, # Add ARCH replacement
|
||||
"{CROSS_COMPILE}": cross_compile # Add CROSS_COMPILE replacement
|
||||
}
|
||||
|
||||
# Apply replacements
|
||||
spec_content = template
|
||||
for key, value in replacements.items():
|
||||
spec_content = spec_content.replace(key, value)
|
||||
|
||||
# Define output directory and path
|
||||
output_dir = os.path.join("tmp", vendor, device, "kernel-build")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
# Write spec file
|
||||
spec_file_path = os.path.join(output_dir, f"kernel-{device_name}.spec")
|
||||
with open(spec_file_path, 'w') as f:
|
||||
f.write(spec_content)
|
||||
|
||||
print(f"Generated spec file: {spec_file_path}")
|
||||
return spec_file_path
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: generate_spec.py <vendor> <device>")
|
||||
sys.exit(1)
|
||||
|
||||
vendor = sys.argv[1]
|
||||
device = sys.argv[2]
|
||||
|
||||
generate_spec_file(vendor, device)
|
||||
|
41
utils/kernel.template
Normal file
41
utils/kernel.template
Normal file
|
@ -0,0 +1,41 @@
|
|||
%define debug_package %{nil}
|
||||
%define _modulesdir /usr/lib/modules
|
||||
|
||||
Name: kernel-{BOARD_NAME}
|
||||
Version: {KERNEL_VERSION}
|
||||
Release: 1
|
||||
Summary: kernel for {BOARD_NAME} devices
|
||||
Group: System/Kernel and hardware
|
||||
Source0: kernel.tar
|
||||
Source1: {KERNEL_CONFIG}
|
||||
License: GPLv2
|
||||
Provides: kernel = %{EVRD}
|
||||
|
||||
%description
|
||||
kernel for ${BOARD_NAME}
|
||||
|
||||
%prep
|
||||
%autosetup -p1 -n kernel
|
||||
cp %{S:1} .config
|
||||
grep -Irl /lib/modules | xargs sed -i -e 's,/lib/modules,%{_modulesdir},g' -e 's,/usr/usr/lib/modules,/usr/lib/modules,g'
|
||||
|
||||
%build
|
||||
%make_build CROSS_COMPILE=/usr/bin/{ARCH}-linux-gnu- ARCH={KERNEL_ARCH}
|
||||
|
||||
%install
|
||||
# Install kernel modules, if any
|
||||
make V=1 modules_install ARCH={KERNEL_ARCH} \
|
||||
INSTALL_MOD_PATH=%{buildroot} \
|
||||
INSTALL_DTBS_PATH=%{buildroot}/boot
|
||||
|
||||
make dtbs_install ARCH={KERNEL_ARCH} \
|
||||
INSTALL_MOD_PATH=%{buildroot} \
|
||||
INSTALL_DTBS_PATH=%{buildroot}/boot
|
||||
|
||||
cp arch/arm64/boot/Image %{buildroot}/boot/vmlinuz-%{version}
|
||||
|
||||
find %{buildroot} -type f -name "*.ko" -exec %{_bindir}/{ARCH}-linux-gnu-strip {} \;
|
||||
|
||||
%files
|
||||
/boot/*
|
||||
/usr/lib/modules/*
|
Loading…
Add table
Reference in a new issue