使用i.mx平台轻松开发的开源库
imx的Python项目详细描述
这个存储库收集了一个有用的工具和python模块,目标是 i.MX Applications Processors。
实现的内容:
- DCD(设备配置数据)API
- 启动映像v2(i.mx6和i.mx7)API
- 启动映像v3(i.mx8qm-a0和i.mx8qxp-a0)API
- SDP(串行下载协议)API-仅USB接口
- HAB日志分析器(仅i.mx6和i.mx7)
- SRK表API
嵌入式工具:
imxim -使用*.imxboot image进行操作的工具
imxsd -通过串行口在i.mx socs上下载和执行代码的工具 下载协议(SDP)
This project is still in developing phase. Please, test it and report founded issues.
依赖关系
安装
$ pip install imx
要从shell中的master branch execute安装最新版本 以下命令:
$ pip install -r https://raw.githubusercontent.com/molejar/pyIMX/master/requirements.txt $ pip install -U https://github.com/molejar/pyIMX/archive/master.zip
如果要进行开发,请从以下来源安装pyimx:
$ git clone https://github.com/molejar/pyIMX.git
$ cd pyIMX
$ pip install -r requirements.txt
$ pip install -U -e .
运行这些命令可能会遇到权限问题。这里有一个 很少有解决方法:
- 使用sudo运行以全局安装pyimx和依赖项
- 指定--user选项以本地安装到您的家庭中 目录(如果没有,则将“~/.local/bin”导出到路径变量中)。
- 在 virtualenv本地到 特定项目工作集。
用法
在下面的示例中演示了使用i.mx boot的简单性 图像api由imx.img模块覆盖:
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())
第二个示例演示了i.mx串行下载程序协议api的使用 由imx.sdp模块覆盖:
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``.
待办事项
- 为imx.sdp模块添加串行接口支持
- 添加图像安全功能(签名和加密)
- 添加efuses读、写和验证功能
- 为i.mx-rt和i.mx8设备添加HAB日志分析器
- 添加对qspi flash图像的支持