2024-11-13 11:48:35 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import multiprocessing
|
2024-11-13 12:52:55 +00:00
|
|
|
from utils.bootstrap_setup import setup_bootstrap
|
2024-11-14 19:35:34 +03:00
|
|
|
from utils.common import load_config, clone_repo
|
2024-11-13 20:05:50 +00:00
|
|
|
from utils.make_disk import create_disk_image, setup_loop_device
|
2024-11-14 00:15:39 +03:00
|
|
|
from utils.make_disk import create_partitions, mount_partitions
|
2024-11-14 19:35:34 +03:00
|
|
|
from utils.generate_spec import generate_spec_file
|
|
|
|
from utils.kernel import clone_kernel, make_kernel_tar
|
2024-11-15 12:44:24 +03:00
|
|
|
from utils.uboot import build_uboot
|
2024-11-15 13:12:28 +03:00
|
|
|
from utils.patch import apply_uboot_patches, apply_kernel_patches
|
|
|
|
|
2024-11-13 11:48:35 +00:00
|
|
|
|
|
|
|
BASE_DIR = os.getcwd()
|
|
|
|
TMP_DIR = os.path.join(BASE_DIR, "tmp")
|
|
|
|
NUM_CORES = str(multiprocessing.cpu_count())
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if len(sys.argv) < 3 or "--distro" not in sys.argv:
|
2024-11-13 23:57:20 +03:00
|
|
|
print("example: python build.py --distro <distro_name> <vendor/device> [--skip-kernel] [--skip-uboot] [--skip-rootfs]")
|
|
|
|
print("""Usage: optional features:
|
|
|
|
--skip-kernel [do not build kernel]
|
|
|
|
--skip-uboot [do not build u-boot]
|
|
|
|
--skip-rootfs [do not create distro rootfs]""")
|
2024-11-13 11:48:35 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
distro_idx = sys.argv.index("--distro") + 1
|
|
|
|
distro = sys.argv[distro_idx]
|
|
|
|
vendor_device = sys.argv[distro_idx + 1]
|
|
|
|
vendor, device = vendor_device.split("/")
|
|
|
|
config_path = os.path.join("device", vendor, device, "config")
|
|
|
|
skip_kernel = "--skip-kernel" in sys.argv
|
|
|
|
skip_uboot = "--skip-uboot" in sys.argv
|
2024-11-13 11:58:49 +00:00
|
|
|
skip_rootfs = "--skip-rootfs" in sys.argv
|
2024-11-13 11:48:35 +00:00
|
|
|
|
|
|
|
if not os.path.exists(config_path):
|
|
|
|
print(f"Configuration file for {vendor}/{device} not found.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
config = load_config(config_path)
|
2024-11-14 00:34:01 +03:00
|
|
|
arch = config["ARCH"]
|
2024-11-13 11:48:35 +00:00
|
|
|
|
|
|
|
print(f"Building for {vendor}/{device} with distro {distro}...")
|
|
|
|
|
|
|
|
if not skip_kernel:
|
2024-11-14 19:35:34 +03:00
|
|
|
generate_spec_file(TMP_DIR, config, vendor, device)
|
|
|
|
kernel_dir = os.path.join(TMP_DIR, vendor, device, "kernel")
|
2024-11-15 13:12:28 +03:00
|
|
|
clone_kernel(TMP_DIR, BASE_DIR, config, vendor, device, kernel_dir)
|
2024-11-14 19:35:34 +03:00
|
|
|
kernel_rpm_dir = os.path.join(TMP_DIR, vendor, device, "kernel-build")
|
|
|
|
make_kernel_tar(kernel_dir, kernel_rpm_dir)
|
2024-11-13 11:48:35 +00:00
|
|
|
else:
|
|
|
|
print("Skipping kernel build.")
|
|
|
|
|
|
|
|
if not skip_uboot:
|
2024-11-15 13:12:28 +03:00
|
|
|
build_uboot(TMP_DIR, BASE_DIR, config, vendor, device)
|
2024-11-13 11:48:35 +00:00
|
|
|
else:
|
|
|
|
print("Skipping U-Boot build.")
|
|
|
|
|
2024-11-13 11:58:49 +00:00
|
|
|
if not skip_rootfs:
|
2024-11-14 01:05:24 +03:00
|
|
|
# dd here
|
2024-11-14 00:34:01 +03:00
|
|
|
disk_image_path = create_disk_image(TMP_DIR, config, vendor, device)
|
|
|
|
if disk_image_path:
|
|
|
|
loop_device = setup_loop_device(disk_image_path)
|
|
|
|
print(f"Loop device setup at {loop_device}")
|
2024-11-14 01:05:24 +03:00
|
|
|
# fdisk, mkfs here
|
2024-11-14 00:34:01 +03:00
|
|
|
create_partitions(loop_device, config)
|
|
|
|
mount_partitions(config, loop_device, TMP_DIR, vendor, device)
|
2024-11-14 01:05:24 +03:00
|
|
|
# dnf install rootfs here
|
2024-11-14 00:34:01 +03:00
|
|
|
setup_bootstrap("bootstrap", TMP_DIR, vendor, device, distro, arch)
|
|
|
|
|
2024-11-13 11:58:49 +00:00
|
|
|
else:
|
|
|
|
print("Skipping rootfs bootstrap")
|
2024-11-13 11:48:35 +00:00
|
|
|
|
|
|
|
print(f"Build completed for {vendor}/{device} with distro {distro}")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|