Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom rnodeconf build #5

Open
jacobeva opened this issue May 20, 2024 · 1 comment
Open

Custom rnodeconf build #5

jacobeva opened this issue May 20, 2024 · 1 comment
Assignees

Comments

@jacobeva
Copy link

I need to create an rnodeconf-like utility which will support all the extra boards which are able to be flashed by this repository.

@jacobeva jacobeva self-assigned this May 20, 2024
@jacobeva
Copy link
Author

@WifiHero91 sent me this earlier:

import os
import re
import subprocess

MAKEFILE_PATH = "Makefile"

def parse_firmware_targets(makefile_path):
    """Parse firmware targets from the Makefile."""
    with open(makefile_path, "r") as file:
        content = file.read()

    # Regex to find firmware targets
    firmware_pattern = re.compile(r"^firmware-([\w_]+):", re.MULTILINE)
    targets = firmware_pattern.findall(content)
    
    return targets

def parse_upload_targets(makefile_path):
    """Parse upload targets from the Makefile."""
    with open(makefile_path, "r") as file:
        content = file.read()

    # Regex to find upload targets
    upload_pattern = re.compile(r"^upload-([\w_]+):", re.MULTILINE)
    targets = upload_pattern.findall(content)
    
    return targets

def select_target(targets, target_type):
    """Allow the user to select a target from the list."""
    print(f"\nAvailable {target_type} targets:")
    for idx, target in enumerate(targets):
        print(f"{idx + 1}: {target}")

    choice = int(input(f"\nSelect a {target_type} target by number: ")) - 1
    return targets[choice]

def build_firmware(firmware_target):
    """Build the firmware using the selected firmware target."""
    try:
        print(f"Building firmware for: {firmware_target}...")
        subprocess.check_call(["make", firmware_target])
        print(f"Firmware {firmware_target} built successfully.")
    except subprocess.CalledProcessError:
        print(f"Error occurred during build of {firmware_target}.")
        exit(1)

def upload_firmware(upload_target):
    """Upload the firmware using the selected upload target."""
    try:
        print(f"Uploading firmware to: {upload_target}...")
        subprocess.check_call(["make", f"upload-{upload_target}"])
        print(f"Firmware uploaded successfully to {upload_target}.")
    except subprocess.CalledProcessError:
        print(f"Error occurred during upload to {upload_target}.")
        exit(1)

if __name__ == "__main__":
    # Step 1: Parse firmware and upload targets
    firmware_targets = parse_firmware_targets(MAKEFILE_PATH)
    upload_targets = parse_upload_targets(MAKEFILE_PATH)

    if not firmware_targets:
        print("No firmware targets found in Makefile.")
        exit(1)

    if not upload_targets:
        print("No upload targets found in Makefile.")
        exit(1)

    # Step 2: Select firmware and upload targets
    selected_firmware = select_target(firmware_targets, "firmware")
    selected_upload = select_target(upload_targets, "upload")

    # Step 3: Build the firmware
    build_firmware(f"firmware-{selected_firmware}")

    # Step 4: Upload the firmware
    upload_firmware(selected_upload)

Although it isn't what I'm literally looking to do, it may be useful for helping people who don't have skills in using make to flash their boards directly from the repo, instead of downloading the firmware as a binary blob from online.

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

No branches or pull requests

1 participant