用于使用u-boot映像和环境变量进行操作的开源库

uboot的Python项目详细描述


Build StatusCoverage StatusPyPI StatusPython Version

pyuboot是一个基于python的开源库,用于处理 U-boot映像和环境变量。分布有以下内容 命令行实用程序(工具):

  • envimg-编辑环境的工具 U-boot映像中的变量
  • mkenv-生成/提取u-boot的工具 进入/离开二进制blob的环境变量
  • mkimg-使用u-boot进行操作的工具 可执行图像(zimage、脚本等)

依赖关系

  • Python-python 3.x解释器
  • Click-用于创建的python包 漂亮的命令行界面。
  • pyFDT-python包 使用设备树图像进行操作。

安装

$ pip install uboot

要从shell中的master branch execute安装最新版本 以下命令:

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

如果要进行开发,请从克隆源安装:

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

注意:运行这些命令可能会遇到权限问题。 以下是一些解决方法:

  1. 使用sudo运行以全局安装pyuboot和依赖项
  2. 指定--user选项以本地安装到您的家庭中 目录(如果没有,则将“~/.local/bin”导出到路径变量中)。
  3. virtualenv本地到 特定项目工作集。

用法

第一个例子展示了如何使用^{tt3}中的^{tt4}类$ 代码中的模块。

importuboot# --------------------------------------------------------------------------------# create env blob# --------------------------------------------------------------------------------env=uboot.EnvBlob(name="U-Boot Variables")env.redundant=Trueenv.set("bootdelay","3")env.set("stdin","serial")env.set("stdout","serial")# --------------------------------------------------------------------------------# save env blob as binary file# --------------------------------------------------------------------------------withopen("env.img",'wb')asf:f.write(env.export())# --------------------------------------------------------------------------------# save env blob in readable format as text file# --------------------------------------------------------------------------------withopen("env.txt",'w')asf:f.write(env.store())# --------------------------------------------------------------------------------# parse env blob from binary file# --------------------------------------------------------------------------------withopen("env.img",'rb')asf:env.parse(f.read())# print env blob infoprint("U-Boot enviroment blob loaded from env.img file:")print(env)print()# --------------------------------------------------------------------------------# load env blob from text file# --------------------------------------------------------------------------------withopen("env.txt",'r')asf:env.load(f.read())# print env blob infoprint("U-Boot enviroment blob loaded from env.txt file:")print(env)

第二个例子展示了如何使用 uboot模块。

importuboot# --------------------------------------------------------------------------------# create dummy firmware image (u-boot executable image)# --------------------------------------------------------------------------------fwimg=uboot.StdImage(bytes([1]*512),name="Firmware Test Image",laddr=0,eaddr=0,arch=uboot.EnumArchType.ARM,os=uboot.EnumOsType.LINUX,image=uboot.EnumImageType.FIRMWARE,compress=uboot.EnumCompressionType.NONE)# --------------------------------------------------------------------------------# create script image (u-boot executable image)# --------------------------------------------------------------------------------scimg=uboot.ScriptImage()scimg.Name="Test Script Image"scimg.OsType=uboot.EnumOsType.LINUXscimg.ArchType=uboot.EnumArchType.ARMscimg.Compression=uboot.EnumCompressionType.NONEscimg.EntryAddress=0scimg.LoadAddress=0scimg.append("echo","'===== U-Boot settings ====='")scimg.append("setenv","stdin serial")scimg.append("setenv","stdout serial")scimg.append("setenv","rootdev mmcblk2p2")# --------------------------------------------------------------------------------# create multi-file image# --------------------------------------------------------------------------------mimg=uboot.MultiImage(name="Multi-File Test Image",laddr=0,eaddr=0,arch=uboot.EnumArchType.ARM,os=uboot.EnumOsType.LINUX,compress=uboot.EnumCompressionType.NONE)mimg.append(fwimg)mimg.append(scimg)# print created image infoprint(mimg)# --------------------------------------------------------------------------------# save created image into file: uboot_mimg.img# --------------------------------------------------------------------------------withopen("uboot_mimg.img","wb")asf:f.write(mimg.export())# --------------------------------------------------------------------------------# open and read image file: uboot_mimg.img# --------------------------------------------------------------------------------withopen("uboot_mimg.img","rb")asf:data=f.read()# --------------------------------------------------------------------------------# parse binary data into new img object of specific image type# --------------------------------------------------------------------------------img=uboot.parse_img(data)# print parsed image infoprint(img)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
选项卡内的java 安卓工具栏   java接口VS API VS公共类   无法解析java。lang.ClassNotFoundException:在安卓 studio中找不到类“com.example.安卓.camera2basic.AutoFitTextureView”?   java等待线程正常完成   java在JTable中的prepareRenderer方法中编辑单元格数据是否可行?   java SessionNotCreatedException selenium webdriver   java Android Studio Gradle CreateProcess错误=2   java找不到适用于异常(int)的构造函数   javascript如何在不使用正则表达式的情况下检查输入是否为表情符号?   从JAVA运行ant时,JAVA_HOME变量不正确   long的java min值引发异常   java如何在这段代码中实现侦听器?   带有透明文本的java Android按钮   图像Java扫描仪问题(JFrame)   java模拟输入蒸汽似乎在Junit测试的第一次输入中就被吃掉了   压缩Java Deflater,现在和将来的结果相同(确定性)   java JTable getModel()。setValueAt从数组中删除第一个元素   java我有不同于编译器和计算器的价值   使用C#客户端调用基本身份验证java webservice   java相同类型的多个@Embedded字段在持久化后始终为空