Git Product home page Git Product logo

pyimx's Introduction

pyIMX

Build Status Coverage Status PyPI Status Python Version

This repository collects a useful tools and python module targeted for i.MX Applications Processors.

What is implemented:

  • DCD (Device Configuration Data) API
  • Boot Image v2 (i.MX6 and i.MX7) API
  • Boot Image v3 (i.MX8QM-A0 and i.MX8QXP-A0) API
  • SDP (Serial Download Protocol) API - only USB interface
  • HAB-Log parser (only i.MX6 and i.MX7 yet)
  • SRK Table API

Embedded tools:

  • imxim - a tool for manipulation with *.imx boot image
  • imxsd - a tool to download and execute code on i.MX SoCs through the Serial Download Protocol (SDP)

This project is still in developing phase. Please, test it and report founded issues.

Dependencies

  • Python - Python 3.x interpreter
  • Click - Python package for creating beautiful command line interface.
  • pyYAML - YAML parser and emitter for the Python programming language.
  • bincopy - Python package for parsing S-Record, Intel HEX and TI-TXT files.
  • easy_enum - User friendly implementation of documented Enum type for Python language.
  • cryptography - Provides cryptographic recipes and primitives to Python developers
  • PyUSB - Python package to access USB devices in Linux OS.
  • PyWinUSB - Python package that simplifies USB-HID communications on Windows OS.

Installation

    $ pip install imx

To install the latest version from master branch execute in shell following commands:

    $ pip install -r https://raw.githubusercontent.com/molejar/pyIMX/master/requirements.txt
    $ pip install -U https://github.com/molejar/pyIMX/archive/master.zip

In case of development, install pyIMX from sources:

    $ git clone https://github.com/molejar/pyIMX.git
    $ cd pyIMX
    $ pip install -r requirements.txt
    $ pip install -U -e .

You may run into a permissions issues running these commands. Here are a few options how to fix it:

  1. Run with sudo to install pyIMX and dependencies globally
  2. Specify the --user option to install locally into your home directory (export "~/.local/bin" into PATH variable if haven't).
  3. Run the command in a virtualenv local to a specific project working set.

Usage

In following example is demonstrated the simplicity of usage i.MX boot image API covered by imx.img module:

    from imx import img

    # --------------------------------------------------------------------------------
    # Create new U-Boot i.MX6/7 image
    # --------------------------------------------------------------------------------

    # Create DCD segment instance
    dcd = img.SegDCD()

    # Create Write Data command and append values with addresses
    cmd = img.CmdWriteData(4, img.EnumWriteOps.WRITE_VALUE)
    cmd.append(0x30340004, 0x4F400005)
    cmd.append(0x30391000, 0x00000002)
    cmd.append(0x307A0000, 0x01040001)

    # Append commands into DCD segment
    dcd.append(cmd)
    dcd.append(img.CmdCheckData(4, img.EnumCheckOps.ANY_CLEAR, 0x307900C4, 0x00000001))

    # Open U-Boot raw image
    with open('u-boot.img', 'rb') as f:
        app = f.read()

    # Create IMX U-Boot image with DCD segment
    image = img.BootImg2(0x877FF000, app, dcd)

    # Print image info
    print(image)

    # Save IMX U-Boot image
    with open('u-boot.imx', 'wb') as f:
        f.write(image.export())

    # --------------------------------------------------------------------------------
    # Extract DCD from existing U-Boot i.MX6/7 image
    # --------------------------------------------------------------------------------

    # Open U-Boot IMX image
    with open('u-boot.imx', 'rb') as f:
        data = f.read()

    # Parse U-Boot IMX image
    image = img.BootImg2.parse(data)

    # Extract DCD from U-Boot IMX image
    dcd = image.dcd

    # Print extracted DCD info
    print(dcd)

    # Save extracted DCD content as raw image
    with open('dcd.img', 'wb') as f:
        f.write(dcd.export())

    # Save extracted DCD content as readable text file
    with open('dcd.txt', 'w') as f:
        f.write(dcd.store())

Second example demonstrate usage of i.MX serial downloader protocol API covered by imx.sdp module:

    from imx import sdp

    # scan for connected USB devs
    devs = sdp.scan_usb()

    if devs:
        # Print list of connected devices
        for i, dev in enumerate(devs):
            print("{}) {}".format(i, dev.usbd.info()))

        # Connect to first i.MX device
        flasher = devs[0]
        flasher.open()

        # Read data from i.MX Device (i.MX7D OCRAM)
        data = flasher.read(0x910000, 100, 8)

        # Write boot image data into i.MX Device (i.MX7D OCRAM)
        flasher.write_file(0x910000, data)

        # Other commands
        # ...

        # Disconnect IMX Device
        flasher.close()

For running imx.sdp module without root privileges in Linux OS copy attached udev rules 90-imx-sdp.rules into /etc/udev/rules.d directory and reload it with command: sudo udevadm control --reload-rules.

TODO

  • Add serial interface support for imx.sdp module
  • Add image security features (sign and encryption)
  • Add eFuses read, write and validation functionality
  • Add HAB-log parser for i.MX-RT and i.MX8 devices
  • Add support for QSPI Flash image

pyimx's People

Contributors

dependabot[bot] avatar molejar avatar sadamek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyimx's Issues

I cannot install the dependency

I run the dependency installation command but I face a dependency error.

:~/pyIMX$ pip3 install -U --process-dependency-links -e .
Obtaining file:///home/daiane/pyIMX
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "./src/imx/sd/usbif.py", line 174, in <module>
        import usb.core
    ImportError: No module named 'usb'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/daiane/pyIMX/setup.py", line 22, in <module>
        import imx
      File "./src/imx/__init__.py", line 20, in <module>
        from .sd import SerialDownloader, \
      File "./src/imx/sd/__init__.py", line 16, in <module>
        from .serdown import SerialDownloader, \
      File "./src/imx/sd/serdown.py", line 20, in <module>
        from .usbif import USBIF
      File "./src/imx/sd/usbif.py", line 177, in <module>
        raise Exception("PyUSB is required on a Linux Machine")
    Exception: PyUSB is required on a Linux Machine
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /home/daiane/pyIMX
```/


Can you, please, help?

Issue running imxim

Hi,

so I installed pyIMX tools via

pip install imx

After that, I am unable to use imxim info on any of my imx images(imx6ull).

I just get:

imxim info u-boot.imx.signed

Unknown Error !

Not sure what the problem is...

regards,
Fabian

imxsd makes USB keyboard and mouse stop working

Hello!

I have an i.MX6UL board connected via USB to my PC. When I run sudo imxsd info my USB keyboard and mouse stops working. I have to unplug the USB cables (and plug in again) to make them work again.

I have version 0.1.3 installed.

Command execution:

> sudo imxsd info

 DEVICE: SP Blank 6UL  (0x15A2, 0x007D)

 - ERROR: Target is locked !

dmesg before running the command:

[950800.947850] usb 2-2: new high-speed USB device number 84 using xhci_hcd
[950801.096546] usb 2-2: New USB device found, idVendor=15a2, idProduct=007d, bcdDevice= 0.01
[950801.096549] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[950801.096550] usb 2-2: Product: SP Blank 6UL 
[950801.096551] usb 2-2: Manufacturer: Freescale SemiConductor Inc 
[950801.101223] hid-generic 0003:15A2:007D.0093: hiddev0,hidraw2: USB HID v1.10 Device [Freescale SemiConductor Inc  SP Blank 6UL ] on usb-0000:00:14.0-2/input0

dmesg after running the command:

[950805.296031] usb 2-3.4: reset low-speed USB device number 83 using xhci_hcd
[950805.756053] usb 2-3.3: reset full-speed USB device number 82 using xhci_hcd
[950805.992122] usb 2-2: reset high-speed USB device number 84 using xhci_hcd
[950811.374151] usb 2-2: USB disconnect, device number 84
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.