Coder Social home page Coder Social logo

extract-dtb's Introduction

extract-dtb

Tool to split a kernel image with appended dtbs into separated kernel and dtb files.

A Device Tree is a data structure for describing hardware. They are used in a lot of ARM devices (e.g. Android), otherwise these would not be able to boot.

This tool is similar to split-appended-dtb but it is written in Python and its code is simpler and almost 3x shorter. Moreover, it doesn't require any external Python library.

If you want to learn more about DTB you can have a look at the Device Tree Reference.

Install & Usage

extract-dtb is available on PyPI!

$ pip install extract-dtb

The extract-dtb command is now available:

$ extract-dtb --help
usage: extract-dtb [-h] [-o OUTPUT_DIR] [-n] [-V] filename

Extract dtbs from kernel images.

positional arguments:
  filename       Android kernel image

optional arguments:
  -h, --help     show this help message and exit
  -o OUTPUT_DIR  Output directory
  -n             Do not extract, just output information
  -V, --version  show program's version number and exit

Example:

$ extract-dtb -n /tmp/postmarketOS-export/vmlinuz-motorola-titan
Found 9 appended dtbs

$ extract-dtb /tmp/postmarketOS-export/vmlinuz-motorola-titan -o /tmp/dtb
Dumped kernel, start=0 end=7534024
Dumped dtbdump_01_Motorola_QC-MSM8226_Titan.dtb, start=7534024 end=7728853
Dumped dtbdump_02_Motorola_QC-MSM8226_Titan.dtb, start=7728853 end=7923682
Dumped dtbdump_03_Motorola_QC-MSM8226_Titan.dtb, start=7923682 end=8118511
Dumped dtbdump_04_Motorola_QC-MSM8226_Titan.dtb, start=8118511 end=8313340
Dumped dtbdump_05_Motorola_QC-MSM8226_Titan.dtb, start=8313340 end=8508169
Dumped dtbdump_06_Motorola_QC-MSM8226_Thea.dtb, start=8508169 end=8700762
Dumped dtbdump_07_Motorola_QC-MSM8226_Thea.dtb, start=8700762 end=8894086
Dumped dtbdump_08_Motorola_QC-MSM8226_Thea.dtb, start=8894086 end=9087470
Dumped dtbdump_09_Motorola_QC-MSM8226_Thea.dtb, start=9087470 end=9280854
Extracted 9 appended dtbs + kernel to /tmp/dtb

$ ls -l /tmp/dtb/
total 9088
-rw-rw-r-- 1 pablo pablo  194829 Aug 21 01:48 dtbdump_01_Motorola_QC-MSM8226_Titan.dtb
-rw-rw-r-- 1 pablo pablo  194829 Aug 21 01:48 dtbdump_02_Motorola_QC-MSM8226_Titan.dtb
-rw-rw-r-- 1 pablo pablo  194829 Aug 21 01:48 dtbdump_03_Motorola_QC-MSM8226_Titan.dtb
-rw-rw-r-- 1 pablo pablo  194829 Aug 21 01:48 dtbdump_04_Motorola_QC-MSM8226_Titan.dtb
-rw-rw-r-- 1 pablo pablo  194829 Aug 21 01:48 dtbdump_05_Motorola_QC-MSM8226_Titan.dtb
-rw-rw-r-- 1 pablo pablo  192593 Aug 21 01:48 dtbdump_06_Motorola_QC-MSM8226_Thea.dtb
-rw-rw-r-- 1 pablo pablo  193324 Aug 21 01:48 dtbdump_07_Motorola_QC-MSM8226_Thea.dtb
-rw-rw-r-- 1 pablo pablo  193384 Aug 21 01:48 dtbdump_08_Motorola_QC-MSM8226_Thea.dtb
-rw-rw-r-- 1 pablo pablo  193384 Aug 21 01:48 dtbdump_09_Motorola_QC-MSM8226_Thea.dtb
-rw-rw-r-- 1 pablo pablo 7534024 Aug 21 01:48 kernel

This tool can also be run directly on boot.img images.

Star History

Star History Chart

extract-dtb's People

Contributors

crackevil avatar drebrez avatar pablocastellano avatar sebaubuntu avatar z3ntu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

extract-dtb's Issues

Command issue: ./extract-dtb.py

FYI: You indicate the command as: ./extract-dtb.py
It should be: ./extract_dtb.py
i.e., underscore not dash between extract and dtb.py

A small issue but confusing until looked at a bit more closely.

Appreciate your work - ran like a charm, once I realized the command issue.

Cheers,
S.

Extract dtb an error occurreda

I have a Chinese TVbox and i got the update.zip .When i unpack it ,i got the dtb.img so i want to use this tool to extract dtb.But something wrong is that it display:“FATAL ERROR: Blob has incorrect magic number“.

I can't extract a boot.img

Hi!

I have phyton installed and when I run the command "extract-dtb.py C:\boot.img" I get an error:
usage: extract-dtb.py [-h] [-o OUTPUT_DIR] [-n] [-V] filename
extract-dtb.py: error: the following arguments are required: filename

But I have a boot.img file in the C:\ path. Same with "extract-dtb.py boot.img" when extract-dtb.py and boot.img are in the same folder. What should I do?

Print DTB name

I've added additional information to the output, the name of the DTB

example output:

Dumped dtbdump_01.dtb, start=6144 end=137216
>>> Qualcomm MSM 8610 CDP
Dumped dtbdump_02.dtb, start=137216 end=268288
>>> Qualcomm MSM 8610v2 CDP
Dumped dtbdump_03.dtb, start=268288 end=405504
>>> Qualcomm MSM 8610 MTP
Dumped dtbdump_04.dtb, start=405504 end=542720
>>> Qualcomm MSM 8610v2 MTP
Dumped dtbdump_05.dtb, start=542720 end=657408
>>> Qualcomm MSM 8610 Simulator
Dumped dtbdump_06.dtb, start=657408 end=813056
>>> Qualcomm MSM 8610 QRD
Dumped dtbdump_07.dtb, start=813056 end=968704
>>> Qualcomm MSM 8610 QRD v2
Dumped dtbdump_08.dtb, start=968704 end=1116160
>>> Qualcomm MSM 8610 QRD G6-U00
Dumped dtbdump_09.dtb, start=1116160 end=1263616
>>> Qualcomm MSM 8610 QRD G6-U00 v2
Dumped dtbdump_10.dtb, start=1263616 end=1398784
>>> Qualcomm MSM 8610 QRD mainboard
Dumped dtbdump_11.dtb, start=1398784 end=1533952
>>> Qualcomm MSM 8610 QRD mainboard v2

here the code I used: https://pastebin.com/XdVjFM4S

of course it should be improved, maybe also use the name in the filename

coding error

Line 45 of extract_dtb.py has an erroneous "arg" prefix in the first argument:

ret = os.path.join(args.output_dir, dtb_filename_new)

and should be

ret = os.path.join(output_dir, dtb_filename_new)

extract_dtb.py extracts part of kernel as dtb

$ python3 extract_dtb.py boot.img
Dumped 00_kernel, start=0 end=8347
Dumped 01_dtbdump_P@0M<@.dtb, start=8347 end=9113600
Dumped 02_dtbdump_Samsung_HEAT_PROJECT_Rev00.dtb, start=9113600 end=9271296
Dumped 03_dtbdump_Samsung_HEAT_PROJECT_Rev02.dtb, start=9271296 end=9429264
Extracted 3 appended dtbs + kernel to dtb

boot.img: boot.zip

Unable to differenciate between dtb & blank space when run on boot.img

When i run the script on a boot.img directly. It's appending all blank space to last dtb.

For example i was extracting dtbs from realme X boot.img. Siz eof boot.img was 67.1 MB. The extracted dtbs are shown below.

size of dtbs when extracted from boot.img:
Screenshot from 2019-10-01 08-55-02

size of dtbs when extracted from zImage (After unpacking with AIK):
Screenshot from 2019-10-01 08-55-18

Last dtb has a size of 53.5 MB on boot.img case & 173 Bytes on zImage case.

So what's the issue ?
If the kernel size increased a little, while using dtbs extracted from boot.img having remaining blank space appended, will result in a larger image which will eventually fail to flash with a error that partition is full.

Extracted filename format

@PabloCastellano could you please add a leading 0 to the number in the filename?
like this:

dtbdump_01.dtb
dtbdump_02.dtb
dtbdump_03.dtb
dtbdump_04.dtb
dtbdump_05.dtb
dtbdump_06.dtb
dtbdump_07.dtb
dtbdump_08.dtb
dtbdump_09.dtb
dtbdump_10.dtb
dtbdump_11.dtb
dtbdump_12.dtb
...

DTBs Size Difference

If i run ./extract-dtb.py on boot.img to extract dtbs it will extract fine but difference in size i mean if i run ./extract-dtb.py on boot.img-kernel or zImage which i extracted from boot.img there's difference in size i am just concerned about it.

escape new lines in filename

hello, first of all nice work, very useful tool

I had encountered an error when dtb_filename would contain new line (\n)
image
i did a simple fix of replacing that char with nothing, but maybe you would want to do more sanitization than this, for other illegal chars, if not you can ignore this issue
image

cheers

DTBO.img

cna this be used to extract dtbo.img

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.