Package: imx
This repository collects a useful tools and python module targeted fori.MX Applications
Processors.What is implemented:DCD (Device Configuration Data) APIBoot Image v2 (i.MX6 and i.MX7) APIBoot Image v3 (i.MX8QM-A0 and i.MX8QXP-A0) APISDP (Serial Download Protocol) API - only USB interfaceHAB-Log parser (only i.MX6 and i.MX7 yet)SRK Table APIEmbedded tools:imxim- a tool for manipulation with*.imxboot imageimxsd- 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.DependenciesPython- Python 3.x interpreterClick- 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 developersPyUSB- Python package to access
USB devices in Linux OS.PyWinUSB- Python
package that simplifies USB-HID communications on Windows OS.Installation$pipinstallimxTo install the latest version from master branch execute in shell
following commands:$pipinstall-rhttps://raw.githubusercontent.com/molejar/pyIMX/master/requirements.txt$pipinstall-Uhttps://github.com/molejar/pyIMX/archive/master.zipIn case of development, install pyIMX from sources:$gitclonehttps://github.com/molejar/pyIMX.git$cdpyIMX$pipinstall-rrequirements.txt$pipinstall-U-e.You may run into a permissions issues running these commands. Here are a
few options how to fix it:Run withsudoto install pyIMX and dependencies globallySpecify the--useroption to install locally into your home
directory (export “~/.local/bin” into PATH variable if haven’t).Run the command in avirtualenvlocal to a
specific project working set.UsageIn following example is demonstrated the simplicity of usage i.MX boot
image API covered byimx.imgmodule:fromimximportimg# --------------------------------------------------------------------------------# Create new U-Boot i.MX6/7 image# --------------------------------------------------------------------------------# Create DCD segment instancedcd=img.SegDCD()# Create Write Data command and append values with addressescmd=img.CmdWriteData(4,img.EnumWriteOps.WRITE_VALUE)cmd.append(0x30340004,0x4F400005)cmd.append(0x30391000,0x00000002)cmd.append(0x307A0000,0x01040001)# Append commands into DCD segmentdcd.append(cmd)dcd.append(img.CmdCheckData(4,img.EnumCheckOps.ANY_CLEAR,0x307900C4,0x00000001))# Open U-Boot raw imagewithopen('u-boot.img','rb')asf:app=f.read()# Create IMX U-Boot image with DCD segmentimage=img.BootImg2(0x877FF000,app,dcd)# Print image infoprint(image)# Save IMX U-Boot imagewithopen('u-boot.imx','wb')asf:f.write(image.export())# --------------------------------------------------------------------------------# Extract DCD from existing U-Boot i.MX6/7 image# --------------------------------------------------------------------------------# Open U-Boot IMX imagewithopen('u-boot.imx','rb')asf:data=f.read()# Parse U-Boot IMX imageimage=img.BootImg2.parse(data)# Extract DCD from U-Boot IMX imagedcd=image.dcd# Print extracted DCD infoprint(dcd)# Save extracted DCD content as raw imagewithopen('dcd.img','wb')asf:f.write(dcd.export())# Save extracted DCD content as readable text filewithopen('dcd.txt','w')asf:f.write(dcd.store())Second example demonstrate usage of i.MX serial downloader protocol API
covered byimx.sdpmodule:fromimximportsdp# scan for connected USB devsdevs=sdp.scan_usb()ifdevs:# Print list of connected devicesfori,devinenumerate(devs):print("{}){}".format(i,dev.usbd.info()))# Connect to first i.MX deviceflasher=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 Deviceflasher.close()Forrunning``imx.sdp``modulewithoutrootprivilegesinLinuxOScopyattachedudevrules`90-imx-sdp.rules<https://github.com/molejar/pyIMX/blob/master/udev/90-imx-sdp.rules>`__into``/etc/udev/rules.d``directoryandreloaditwithcommand:``sudoudevadmcontrol--reload-rules``.TODOAdd serial interface support forimx.sdpmoduleAdd image security features (sign and encryption)Add eFuses read, write and validation functionalityAdd HAB-log parser for i.MX-RT and i.MX8 devicesAdd support for QSPI Flash image