Linux
  • Register

How to extract Device-Tree-Blob from an Android device and use it to fine-tune Linux on that device.

Disclaimer
Do not take this informations as the only reference! Everything here is intended strictly for personal and educational purpose. You should always be prepared to brick your device and you should always know, that you are the only person to blame for it.

1. Extract DTB image from running Android device

It is useful, but not required, to have an SSH server installed on the Android Box. It allows direct connection from your PC to issue commands and grab files. Check Google Play for available apps or use your favorite if you already have one. Right now, I'm using the Ssh Server - it allows SSH connections and SCP for file transfers.  

... to be written .. 

Simple version:

dd if=/dev/dtb > /storage/downloads/droid.dtb

You can download the file here: droid.dtb 

2. Extract clean DTB files from DTB image

We are going to use the extract-dtb script from Pablo Castellano's git repository https://github.com/PabloCastellano/extract-dtb 


$ wget https://github.com/PabloCastellano/extract-dtb/archive/master.zip --2020-02-21 13:05:20-- https://github.com/PabloCastellano/extract-dtb/archive/master.zip Prevádza sa github.com (github.com) na IP adresu... 140.82.118.4 Pripájanie k github.com (github.com)|140.82.118.4|:443... pripojené. HTTP požiadavka odoslaná, čakám na odpoveď... 302 Found Presmerované na: https://codeload.github.com/PabloCastellano/extract-dtb/zip/master [nasledované] --2020-02-21 13:05:21-- https://codeload.github.com/PabloCastellano/extract-dtb/zip/master Prevádza sa codeload.github.com (codeload.github.com) na IP adresu... 192.30.253.120 Pripájanie k codeload.github.com (codeload.github.com)|192.30.253.120|:443... pripojené. HTTP požiadavka odoslaná, čakám na odpoveď... 200 OK Dĺžka: neudané [application/zip] Ukladá sa do: „master.zip“ master.zip [ <=> ] 16,35K 97,1KB/s za 0,2s 2020-02-21 13:05:22 (97,1 KB/s) - „master.zip“ uložený [16739] $ unzip master.zip Archive: master.zip 86affcb2926bff50e14e0c0a0ea534ef7ceb941a creating: extract-dtb-master/ inflating: extract-dtb-master/.gitignore inflating: extract-dtb-master/LICENSE inflating: extract-dtb-master/NEWS.md inflating: extract-dtb-master/README.md inflating: extract-dtb-master/extract-dtb.py $ ./extract-dtb-master/extract-dtb.py droid.dtb Dumped 00_kernel, start=0 end=2048 Dumped 01_dtbdump_Amlogic.dtb, start=2048 end=45056 Dumped 02_dtbdump_Amlogic.dtb, start=45056 end=262144 Extracted 2 appended dtbs + kernel to dtb

no, we have two dtb files 01_dtbdump_Amlogic.dtb and 02_dtbdump_Amlogic.dtb.

3. Convert DTB (Device Tree Blob) to DTS (Device Tree Source)

We are using the standard device tree compiler

$ sudo apt install device-tree-compiler 

then we hawe to run the conversion:

$ dtc -I dtb -O dts -o 01_dtbdump_Amlogic.dts 01_dtbdump_Amlogic.dtb 
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /mali has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /timer_bc has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /pm has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /cpu_iomap/io_cbus_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /cpu_iomap/io_apb_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /cpu_iomap/io_aobus_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /amlogic-watchdog has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /meson_clock has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /pinmux has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /cpu_version has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /meson_clk_msr has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /scpi_clocks/scpi_clocks@0 has a unit name, but no reg property
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /rng has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /saradc has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /defendkey has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /spicc has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aml_aes has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aml_tdes has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aml_sha has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /meson-pwm has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /memory@00000000 has a unit name, but no reg property
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /reserved-memory/linux,secmon has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /reserved-memory/linux,secos has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /reserved-memory/aml_pstore has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /reserved-memory/linux,meson-fb has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_cbus_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_dos_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_hiubus_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_aobus_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_vcbus_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_dmc_base has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /amvdec_656in0 has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /amvdec_656in1 has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /emmc has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /sd has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /sdio has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /nand has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aocec has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /i2c_gpio/i2c_gpio_edid has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /canvas has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /dwc2_a has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /t9015 has a reg or ranges property, but no unit name
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aml-sensor@0 has a unit name, but no reg property
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /thermal-zones/soc_thermal/trips/trip-point@0 has a unit name, but no reg property
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /thermal-zones/soc_thermal/trips/trip-point@1 has a unit name, but no reg property
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /thermal-zones/soc_thermal/trips/trip-point@2 has a unit name, but no reg property
01_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /thermal-zones/soc_thermal/trips/trip-point@3 has a unit name, but no reg property
01_dtbdump_Amlogic.dts: Warning (unit_address_format): Node /memory@00000000 unit name should not have leading 0s
01_dtbdump_Amlogic.dts: Warning (unit_address_format): Node /ethernet@0xc9410000 unit name should not have leading "0x"
01_dtbdump_Amlogic.dts: Warning (interrupts_property): interrupts size is (8), expected multiple of 12 in /i2c@c8100500/hym8563@51


and the same for the second file:

$ dtc -I dtb -O dts -o 02_dtbdump_Amlogic.dts 02_dtbdump_Amlogic.dtb 
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /mali has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /timer_bc has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /pm has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /cpu_iomap/io_cbus_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /cpu_iomap/io_apb_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /cpu_iomap/io_aobus_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /amlogic-watchdog has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /meson_clock has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /pinmux has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /cpu_version has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /meson_clk_msr has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /scpi_clocks/scpi_clocks@0 has a unit name, but no reg property
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /rng has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /saradc has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /defendkey has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /spicc has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aml_aes has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aml_tdes has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aml_sha has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /meson-pwm has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /memory@00000000 has a unit name, but no reg property
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /reserved-memory/linux,secmon has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /reserved-memory/linux,secos has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /reserved-memory/aml_pstore has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /reserved-memory/linux,meson-fb has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_cbus_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_dos_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_hiubus_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_aobus_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_vcbus_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /codec_io/io_dmc_base has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /amvdec_656in0 has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /amvdec_656in1 has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /emmc has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /sd has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /sdio has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /nand has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /mtd_nand has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aocec has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /i2c_gpio/i2c_gpio_edid has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /canvas has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /dwc2_a has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /t9015 has a reg or ranges property, but no unit name
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /aml-sensor@0 has a unit name, but no reg property
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /thermal-zones/soc_thermal/trips/trip-point@0 has a unit name, but no reg property
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /thermal-zones/soc_thermal/trips/trip-point@1 has a unit name, but no reg property
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /thermal-zones/soc_thermal/trips/trip-point@2 has a unit name, but no reg property
02_dtbdump_Amlogic.dts: Warning (unit_address_vs_reg): Node /thermal-zones/soc_thermal/trips/trip-point@3 has a unit name, but no reg property
02_dtbdump_Amlogic.dts: Warning (unit_address_format): Node /memory@00000000 unit name should not have leading 0s
02_dtbdump_Amlogic.dts: Warning (unit_address_format): Node /ethernet@0xc9410000 unit name should not have leading "0x"
02_dtbdump_Amlogic.dts: Warning (interrupts_property): interrupts size is (8), expected multiple of 12 in /i2c@c8100500/hym8563@51

after looking to the first lines of each file:

$ cat 01_dtbdump_Amlogic.dts|head
/dts-v1/;

/ {
	model = "Amlogic";
	compatible = "amlogic, Gxbb";
	amlogic-dt-id = "gxl_G16_1g";
	interrupt-parent = <0x1>;
	#address-cells = <0x2>;
	#size-cells = <0x2>;

$ cat 02_dtbdump_Amlogic.dts|head
/dts-v1/;

/ {
	model = "Amlogic";
	amlogic-dt-id = "gxl_G16_2g";
	compatible = "amlogic, Gxbb";
	interrupt-parent = <0x1>;
	#address-cells = <0x2>;
	#size-cells = <0x2>;

we can see, that the 01_dtbdump_Amlogic.dts is for 1G version and the 02_dtbdump_Amlogic.dts is for 2G version. In this case that means 1GB or 2GB of RAM. You can assume that from the amlogic-dt-id  parameter and you can easily verify this assumption by checking the usable-memory

$ cat 01_dtbdump_Amlogic.dts|grep usable-memory
linux,usable-memory = <0x0 0x100000 0x0 0x3ff00000>;
$ cat 02_dtbdump_Amlogic.dts|grep usable-memory
linux,usable-memory = <0x0 0x100000 0x0 0x7ff00000>;

If you convert the 0x3ff00000 to decimal, you will get 1 072 693 248 Bytes and for  0x7ff00000, you will get 2 146 435 072 Bytes.


In your case there might be more dtb files, or maybe less - depends on your hardware and firmware.
In my case, I'm dealing with 1GB RAM version so I will continue by using the 01_dtbdump_Amlogic.dts.


Sources & Links

ToDo:

  • add used files
  • finish section 1