Package: uboot
pyUBoot is an Open Source python based library for manipulating with
U-Boot images and environment variables. Is distributed with following
command-line utilities (tools):envimg- a tool for editing environment
variables inside U-Boot imagemkenv- a tool to generate/extract U-Boot
environment variables into/from a binary blobmkimg- a tool for manipulation with U-Boot
executable images (zImage, Scripts, …)DependenciesPython- Python 3.x interpreterClick- Python package for creating
beautiful command line interface.pyFDT- Python package for
manipulation with Device Tree images.Installation$pipinstallubootTo install the latest version from master branch execute in shell
following commands:$pipinstall-rhttps://raw.githubusercontent.com/molejar/pyUBoot/master/requirements.txt$pipinstall-Uhttps://github.com/molejar/pyUBoot/archive/master.zipIn case of development, install it from cloned sources:$gitclonehttps://github.com/molejar/pyUBoot.git$cdpyUBoot$pipinstall-rrequirements.txt$pipinstall-U-e.NOTE:You may run into a permissions issues running these commands.
Here are a few options how to fix it:Run withsudoto install pyUBoot 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.UsageThe first example is showing how to useEnvBlobclass fromubootmodule in your code.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)The second example is showing how to create Multi-File U-Boot image withubootmodule.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)