aospdtgen

repository·master·Indexed 43 days ago

https://github.com/sebaubuntu-python/aospdtgen

A Python tool (v1.2.1) used to create LineageOS-compatible device trees from Android stock ROM dumps produced by dumpyara. It is specifically designed for Treble-enabled Android devices (Android 8.0+). The tool provides a CLI and a DeviceTree class to parse dumps and generate makefiles, blueprints, and prebuilt files.

Tokens
1.8K
Snippets
10
Records
11
Agent score
48%

What's inside aospdtgen

  1. Generate a LineageOS-compatible device tree

    master

    Use aospdtgen to create a device tree from an Android stock ROM dump.

    Requirements:

    • The dump must be created using dumpyara.
    • The device must be Treble-enabled (Android 8.0+ with VNDK enabled). You can verify Treble status via adb shell getprop ro.treble.enabled or using the Treble Info app.
    • For pre-Treble devices, use twrpdtgen instead.
    python -m aospdtgen [options] dump_path
  2. Use the aospdtgen CLI

    master

    The aospdtgen module is invoked via the Python module interface.

    Arguments and Options:

    • dump_path (positional): The path to the Android dump directory created by dumpyara.
    • -o, --output OUTPUT: Specify a custom folder for the generated device tree.
    • --no-proprietary-files: Skip the generation of the proprietary files list and the extract-files script.
    • -h, --help: Show the help message and exit.
    $ python -m aospdtgen --help
    usage: python -m aospdtgen [-h] [-o OUTPUT] [--no-proprietary-files] dump_path
    
    Android device tree generator
    
    positional arguments:
      dump_path             path to an Android dump made with dumpyara
    
    options:
      -h, --help            show this help message and exit
      -o, --output OUTPUT   custom output folder
      --no-proprietary-files
                            Don't generate the proprietary files list and the
                            extract-files script
  3. Use the DeviceTree class to generate an Android device tree

    master

    The DeviceTree class is the primary entry point for generating an Android device tree from a dumpyara dump. When initialized, it parses the dump to identify partitions, build properties, device information, fstab entries, and boot configurations.

    To use it, instantiate DeviceTree with the path to your dump, then call dump_to_folder to write the generated makefiles, blueprints, and prebuilt files to a target directory.

    from pathlib import Path
    from aospdtgen.device_tree import DeviceTree
    
    # Initialize with the path to a dumpyara dump
    dt = DeviceTree(Path("/path/to/dump"))
    
    # Generate the device tree files in a specific folder
    dt.dump_to_folder(Path("/path/to/output_folder"))
    
    # Clean up temporary files
    dt.cleanup()
  4. Dump device tree files with dump_to_folder()

    master

    The dump_to_folder method exports the parsed information into a structured directory format suitable for Android build systems. If the target folder already exists, it is deleted and recreated.

    Generated Files/Directories:

    • Makefiles/Blueprints: Android.bp, Android.mk, AndroidProducts.mk, BoardConfig.mk, device.mk, lineage_<codename>.mk, and README.md.
    • Extraction Scripts: extract-files.py and setup-makefiles.py (marked as executable) if proprietary_files_list is present.
    • Proprietary List: proprietary-files.txt.
    • Build Props: Individual .prop files for each partition.
    • Prebuilts: A prebuilts/ directory containing files from the boot image.
    • Rootdir: A rootdir/ directory containing bin/ and etc/ subdirectories with necessary binaries and configuration files, along with rootdir_Android.bp and rootdir_Android.mk.
    • Manifest: manifest.xml containing the vendor manifest.
    def dump_to_folder(self, folder: Path):
        """Dump all makefiles, blueprint and prebuilts to a folder."""
  5. Reference: aospdtgen CLI arguments and flags

    master

    The following arguments and flags are available for the aospdtgen CLI tool:

    dump_path (Path)             # path to an Android dump made with dumpyara
    -o, --output (Path)          # custom output folder (default: current_path / "output")
    --no-proprietary-files        # Don't generate the proprietary files list and the extract-files script
  6. Use the aospdtgen CLI to generate an Android device tree

    master

    The aospdtgen command-line tool generates an Android device tree from a dump created with dumpyara.

    Usage: python -m aospdtgen <dump_path> [options]

    Arguments:

    • dump_path (Positional): The path to the Android dump directory/file created using dumpyara.

    Options:

    • -o, --output: Specifies a custom output folder for the generated device tree. If not provided, it defaults to an output folder in the current working directory.
    • --no-proprietary-files: If this flag is set, the tool will skip generating the proprietary files list and the extract-files script.
    python -m aospdtgen /path/to/dumpyara_dump -o /path/to/output_dir
  7. Initialize DeviceTree

    master

    The DeviceTree constructor parses a dumpyara dump at the provided path.

    Parameters:

    • path (Path): The filesystem path to the dumpyara dump.
    • no_proprietary_files (bool): If set to True, the ProprietaryFilesList will not be generated. Defaults to False.

    Internal State Created:

    • self.partitions: A Partitions object representing the device's partition scheme.
    • self.device_info: DeviceInfo extracted from build properties.
    • self.fstab: The parsed Fstab object.
    • self.boot_configuration: BootConfiguration extracted from the boot image.
    • self.proprietary_files_list: An optional ProprietaryFilesList containing the list of proprietary files.
    DeviceTree(path: Path, no_proprietary_files: bool = False)