SlideShare a Scribd company logo
1 of 31
Download to read offline
Booting Android
Bootloaders, fastboot and boot images
Booting Android 1 Copyright © 2011-2016, 2net Ltd
License
These slides are available under a Creative Commons Attribution-ShareAlike 3.0
license. You can read the full text of the license here
http://creativecommons.org/licenses/by-sa/3.0/legalcode
You are free to
• copy, distribute, display, and perform the work
• make derivative works
• make commercial use of the work
Under the following conditions
• Attribution: you must give the original author credit
• Share Alike: if you alter, transform, or build upon this work, you may distribute
the resulting work only under a license identical to this one (i.e. include this
page exactly as it is)
• For any reuse or distribution, you must make clear to others the license terms of
this work
Booting Android 2 Copyright © 2011-2016, 2net Ltd
About Chris Simmonds
• Consultant and trainer
• Author of Mastering Embedded Linux
Programming
• Working with embedded Linux since 1999
• Android since 2009
• Speaker at many conferences and
workshops
"Looking after the Inner Penguin" blog at http://2net.co.uk/
https://uk.linkedin.com/in/chrisdsimmonds/
https://google.com/+chrissimmonds
Booting Android 3 Copyright © 2011-2016, 2net Ltd
Overview
• Android system images: boot, recovery, system,
userdata and cache
• Android "boot blobs"
• Bootloaders for Android
• Fastboot
• Flash memory and flash filesystems
Booting Android 4 Copyright © 2011-2016, 2net Ltd
Image files
• A typical build for an Android device produces five
image files in out/target/product/<product>
Image Description
boot.img Kernel + ramdisk used for normal boot
recovery.img Kernel + ramdisk used to boot into recovery mode
system.img File system image for /system
userdata.img File system image for /data
cache.img File system image for /cache
Booting Android 5 Copyright © 2011-2016, 2net Ltd
Typical flash memory layout
Bootloader
Boot kernel + ramdisk
Recovery kernel + ramdisk
/system - read-only file system
/data - read/write file system
/cache - read/write file system
misc (optional - used during OTA update)
Booting Android 6 Copyright © 2011-2016, 2net Ltd
The bootloader
• All systems need a bootloader
• Responsible for:
• Early hardware initialisation
• Load and boot kernel and initial ram filesystem
• System maintenance, including loading and flashing
new kernel and system images
• Example: U-Boot
• Open source
• Used in many dev boards (BeagleBone, Raspberry
Pi) and in many shipping products
• http://www.denx.de/wiki/U-Boot/WebHome
Booting Android 7 Copyright © 2011-2016, 2net Ltd
Booting Android
• It is possible to boot Android using a normal
bootloader such as U-Boot
• However, most devices include Android-specific
features:
• Support normal and recovery boot modes
• Ability to load kernel + ramdisk blobs (boot.img and
recovery.img)
• The fastboot protocol
• Example: LK (Little Kernel)
• git://codeaurora.org/kernel/lk.git
• Supports many Qualcomm-based devices as well as
rudimentary support for BeagleBoard and PC-x86
Booting Android 8 Copyright © 2011-2016, 2net Ltd
The Android bootloader
• Pre JB 4.2, AOSP had source for a simple bootloader
in bootable/bootloader/legacy
• Used in early handsets (Android Dev Phone, HTC
Dream)
• Not updated since the Eclair release
• Some of this code may have found its way into
proprietary bootloaders
Booting Android 9 Copyright © 2011-2016, 2net Ltd
Android boot and recovery images
• The files boot.img and recovery.img are created by the
tool mkbootimg (the code is in system/core/mkbootimg)
• They contain a compressed kernel, the kernel
command line and, optionally, a ramdisk in the
normal Linux compressed cpio format
• Most Android bootloaders can read and load these
images into memory
• The format is defined in bootimg.h
Booting Android 10 Copyright © 2011-2016, 2net Ltd
Boot and recovery image format
Header
Kernel
image
(zImage)
ramdisk
image
(compressed
cpio)
struct boot_img_hdr {
unsigned char magic[8]; // "ANDROID!"
unsigned kernel_size;
unsigned kernel_addr;
unsigned ramdisk_size;
unsigned ramdisk_addr;
unsigned second_size; // 2nd image: not used
unsigned second_addr;
unsigned tags_addr;
unsigned page_size; // typically 2048
unsigned unused[2];
unsigned char name[16]; // product name
unsigned char cmdline[512]; // kernel cmdline
unsigned id[8]; // timestamp/checksum/etc
unsigned char extra_cmdline[1024];
};
From system/core/mkbootimg/bootimg.h
Booting Android 11 Copyright © 2011-2016, 2net Ltd
Boot sequence
Bootloader
Boot recovery Boot normal
Load recovery
kernel and ramdisk
Recovery
mode
Load normal
kernel and ramdisk
Run /init
Read init*.rc
Mount file systems
Start services
Normal
mode
Power
on
Booting Android 12 Copyright © 2011-2016, 2net Ltd
Reverse-engineering a boot image
• Sometimes it is useful to extract the files from a boot
or recovery image
• There are numerous tools to do so, for example
boot-extract
https://github.com/csimmonds/boot-extract
$ boot-extract recovery.img
Boot header
flash page size 2048
kernel size 0x432358
kernel load addr 0x10008000
ramdisk size 0x173740
ramdisk load addr 0x11000000
name
cmdline
zImage extracted
ramdisk offset 4403200 (0x433000)
ramdisk.cpio.gz extracted
$ ls
ramdisk.cpio.gz recovery.img zImage
Booting Android 13 Copyright © 2011-2016, 2net Ltd
Extracting files from a ramdisk
• The ramdisk is just a compressed cpio archive
• Extract the files like so:
$ zcat ramdisk.cpio.gz | cpio -i
5665 blocks
$ ls
charger fstab.manta property_contexts
...
Booting Android 14 Copyright © 2011-2016, 2net Ltd
Creating a new ramdisk
• Do the following
$ cd some-directory
$ find . | cpio -H newc --owner root:root -ov > ∼/ramdisk.cpio
$ cd ∼
$ gzip ramdisk.cpio
• The end result will be ramdisk.cpio.gz
Booting Android 15 Copyright © 2011-2016, 2net Ltd
Creating a new boot image
• You can create a boot or recovery image using the
mkbootimg command
• For example:
$ mkbootimg --kernel zImage --ramdisk ramdisk.cpio.gz 
--base 0x10000000 --pagesize 2048 -o recovery-new.img
• --base is used by mkbootimg to calculate the kernel
and ramdisk load addresses as follows:
• kernel_addr = base + 0x00008000
• ramdisk_addr = base + 0x01000000
Booting Android 16 Copyright © 2011-2016, 2net Ltd
Fastboot
• Fastboot is a USB protocol and a command language
for various maintenance and development tasks
• Fastboot protocol v0.4 is defined in:
• bootable/bootloader/legacy/fastboot_protocol.txt
(up to JB 4.1)
• system/core/fastboot/fastboot_protocol.txt (JB 4.3
and later)
NOTE: fastboot is not about the speed of booting; it is about making
the development process simpler (and faster)
Booting Android 17 Copyright © 2011-2016, 2net Ltd
Booting into the bootloader
• On a typical Android device you can boot into the
bootloader by:
• powering on while pressing various buttons (Google
for details)
• from a running device, typing:
$ adb reboot-bootloader
• Once the device has booted into the bootloader you
can use the fastboot command on the development
machine to communicate with it
Booting Android 18 Copyright © 2011-2016, 2net Ltd
fastboot commands (1/3)
Basic commands
Command Description
devices List devices attached that will accept fast-
boot commands
getvar Get a variable
continue Continue boot process as normal
reboot Reboot device
reboot-bootloader Reboot back into bootloader
Booting Android 19 Copyright © 2011-2016, 2net Ltd
fastboot commands (2/3)
Flashing commands
Command Description
erase <partition> Erase <partition>
flash <partition> Erase and program <partition>
with <partition>.img of current
product
flash <partition> <filename> Erase and program <partition>
with <filename>
flashall Erase and program boot.img,
recovery.img and system.img of
current product and then reboot
Where
<partition> is one of boot, recovery, system, userdata, cache
current product is $ANDROID_PRODUCT_OUT
Note: the location and size of partitions is hard-coded in the bootloader
Booting Android 20 Copyright © 2011-2016, 2net Ltd
fastboot commands (3/3)
Special commands
Command Description
oem Device-specific operations
boot <kernel> <ramdisk> Load and boot kernel and ramdisk
Example:
$ fastboot -c "kernel command line" boot zImage ramdisk.cpio.gz
Booting Android 21 Copyright © 2011-2016, 2net Ltd
fastboot variables
The getvar command should return values for at least
these variables:
Variable Meaning
version Version of the protocol: 0.4 is the one doc-
umented
version-bootloader Version string of the Bootloader
version-baseband Version string of the Baseband Software
product Name of the product
serialno Product serial number
secure If "yes" the bootloader requires signed im-
ages
Booting Android 22 Copyright © 2011-2016, 2net Ltd
Unlocking the bootloader
• Most devices ship with the bootloader locked
• fastboot getvar secure returns true
• Unlocking - where it is allowed - is device specific
• For example, on recent Nexus devices you use a
fastboot oem command
$ fastboot oem unlock
• Answer yes to the on-screen prompt
• For security reasons, this wipes the data and cache
partitions
Booting Android 23 Copyright © 2011-2016, 2net Ltd
What goes where?
ramdisk.img:
read-only
ramdisk
/init
/init.rc
/system
/data
/cache
system.img: read-only
/app built-in Android apps
/bin native binaries
/framework Java components of framework
/lib native libraries
...
userdata.img: read-write
/app user-installed Android apps
/data persistent data
/dalvik-cache optimised Dex files
/system
...
cache.img: read-write
/backup place to backup up app data
/recovery logs used in recovery mode
Booting Android 24 Copyright © 2011-2016, 2net Ltd
Flash memory devices
• In almost all cases data is stored in flash memory
• There are two main types
• Raw NAND flash, where the chips are accessed
directly by Linux
• Managed flash, which contain an on-chip controller
• Managed flash is the most common
• Examples:
• MMC, SD and MicroSD cards: removeable storage
• eMMC (embedded MMC): same electrical interface
as MMC, but packaged as a chip
• UFS (Universal Flash Storage): similar to eMMC, but
faster and with a SCSI command set
Booting Android 25 Copyright © 2011-2016, 2net Ltd
Raw NAND flash
• NAND flash chips are accessed via the Linux MTD
(Memory Technology Device) drivers
• Partitions are named /dev/block/mtdblockN where N
is the partition number
• /proc/mtd lists the partitions and sizes
# cat /proc/mtd
dev: size erasesize name
mtd0: 05660000 00020000 "system"
mtd1: 04000000 00020000 "userdata"
mtd2: 04000000 00020000 "cache"
Booting Android 26 Copyright © 2011-2016, 2net Ltd
File systems for raw NAND flash
• Flash translation layer implemented in the filesystem
• NAND flash devices require special filesystem
support, such as:
• jffs2 (Journalling Flash File System 2)
• Note: incompatible with the Android run-time (no
writeable mmaped files)!
• yaffs2 (Yet Another Flash File System 2)
• ubifs (Unsorted Block Image File System)
• Most Android devices with NAND flash use yaffs2
Booting Android 27 Copyright © 2011-2016, 2net Ltd
SD and eMMC
• Flash translation layer implemented in the chip
• The controller chip splits flash memory into 512-byte
sectors just like hard drives
• Accessed via the Linux mmcblock driver
• Partition device nodes have names of the form
mmcblk[chip number]p[partition number]
• For example:
/dev/block/mmcblk0p3 /system
/dev/block/mmcblk0p8 /data
/dev/block/mmcblk0p4 /cache
Booting Android 28 Copyright © 2011-2016, 2net Ltd
File systems for eMMC
• eMMC devices "look" like hard drives
• Use the same filesystem types
• The preferred type in most Android devices is ext4
• Alternative: F2FS (Flash Friendly File System)
• Develpoed by Samsung, and deployed on some of
their devices
• Faster file writes than ext4
Booting Android 29 Copyright © 2011-2016, 2net Ltd
SD cards and other removable media
• This includes MMC, SD, microSD and USB flash
drives
• For compatibility with other operating systems they
come pre-formatted with FAT32
• Use the Linux vfat driver
Booting Android 30 Copyright © 2011-2016, 2net Ltd
Delving deeper
• This is an excerpt from my Android Porting class
• If you would like to find out more secrets of Android,
visit http://www.2net.co.uk/training.html and
book a course
Booting Android 31 Copyright © 2011-2016, 2net Ltd

More Related Content

What's hot

Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)Siji Sunny
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting SequenceJayanta Ghoshal
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardAnne Nicolas
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security InternalsOpersys inc.
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...ijafrc
 

What's hot (20)

Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Android Booting Scenarios
Android Booting ScenariosAndroid Booting Scenarios
Android Booting Scenarios
 
Building aosp
Building aospBuilding aosp
Building aosp
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
Customizing AOSP For Different Embedded Devices And Integration at Applicatio...
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 

Similar to Booting Android: bootloaders, fastboot and boot images

Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devicesChris Simmonds
 
Android on Intel Architecture: ROM Cooking Tutorial
Android on Intel Architecture: ROM Cooking TutorialAndroid on Intel Architecture: ROM Cooking Tutorial
Android on Intel Architecture: ROM Cooking TutorialRon Munitz
 
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)Ron Munitz
 
Reducing boot time in embedded Linux
Reducing boot time in embedded LinuxReducing boot time in embedded Linux
Reducing boot time in embedded LinuxChris Simmonds
 
Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Chris Simmonds
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Opersys inc.
 
Droidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyDroidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyBenjamin Zores
 
ChromePad - Chromium OS ThinkPad X220
ChromePad - Chromium OS ThinkPad X220ChromePad - Chromium OS ThinkPad X220
ChromePad - Chromium OS ThinkPad X220AndrewWright224
 
ChromePad - Chromium OS for ThinkPad
ChromePad - Chromium OS for ThinkPadChromePad - Chromium OS for ThinkPad
ChromePad - Chromium OS for ThinkPadAndrewWright224
 
Security Issues in Android Custom ROM
Security Issues in Android Custom ROMSecurity Issues in Android Custom ROM
Security Issues in Android Custom ROMAnant Shrivastava
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made EasyAlon Fliess
 
Droidcon uk2012 androvm
Droidcon uk2012 androvmDroidcon uk2012 androvm
Droidcon uk2012 androvmdfages
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphoneChris Simmonds
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot) Omkar Rane
 

Similar to Booting Android: bootloaders, fastboot and boot images (20)

Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devices
 
Hacking Android OS
Hacking Android OSHacking Android OS
Hacking Android OS
 
Android on Intel Architecture: ROM Cooking Tutorial
Android on Intel Architecture: ROM Cooking TutorialAndroid on Intel Architecture: ROM Cooking Tutorial
Android on Intel Architecture: ROM Cooking Tutorial
 
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
 
Reducing boot time in embedded Linux
Reducing boot time in embedded LinuxReducing boot time in embedded Linux
Reducing boot time in embedded Linux
 
Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
Droidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyDroidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform Anatomy
 
Introduction to chrome os
Introduction to chrome osIntroduction to chrome os
Introduction to chrome os
 
ChromePad - Chromium OS ThinkPad X220
ChromePad - Chromium OS ThinkPad X220ChromePad - Chromium OS ThinkPad X220
ChromePad - Chromium OS ThinkPad X220
 
ChromePad - Chromium OS for ThinkPad
ChromePad - Chromium OS for ThinkPadChromePad - Chromium OS for ThinkPad
ChromePad - Chromium OS for ThinkPad
 
Security Issues in Android Custom Rom
Security Issues in Android Custom RomSecurity Issues in Android Custom Rom
Security Issues in Android Custom Rom
 
Security Issues in Android Custom ROM
Security Issues in Android Custom ROMSecurity Issues in Android Custom ROM
Security Issues in Android Custom ROM
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
Droidcon uk2012 androvm
Droidcon uk2012 androvmDroidcon uk2012 androvm
Droidcon uk2012 androvm
 
Linux kernel booting
Linux kernel bootingLinux kernel booting
Linux kernel booting
 
Android Platform Debugging & Development
Android Platform Debugging & Development Android Platform Debugging & Development
Android Platform Debugging & Development
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphone
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot)
 

More from Chris Simmonds

Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDBChris Simmonds
 
Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Chris Simmonds
 
Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Chris Simmonds
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiChris Simmonds
 
Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Chris Simmonds
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?Chris Simmonds
 
Embedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneEmbedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneChris Simmonds
 
Quick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOQuick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOChris Simmonds
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of playChris Simmonds
 
Read-only rootfs: theory and practice
Read-only rootfs: theory and practiceRead-only rootfs: theory and practice
Read-only rootfs: theory and practiceChris Simmonds
 
10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easierChris Simmonds
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016Chris Simmonds
 
The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)Chris Simmonds
 
Linux field-update-2015
Linux field-update-2015Linux field-update-2015
Linux field-update-2015Chris Simmonds
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAMChris Simmonds
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depthChris Simmonds
 
A timeline for embedded Linux
A timeline for embedded LinuxA timeline for embedded Linux
A timeline for embedded LinuxChris Simmonds
 

More from Chris Simmonds (17)

Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDB
 
Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?
 
Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
 
Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?
 
Embedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneEmbedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphone
 
Quick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOQuick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIO
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of play
 
Read-only rootfs: theory and practice
Read-only rootfs: theory and practiceRead-only rootfs: theory and practice
Read-only rootfs: theory and practice
 
10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016
 
The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)
 
Linux field-update-2015
Linux field-update-2015Linux field-update-2015
Linux field-update-2015
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAM
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 
A timeline for embedded Linux
A timeline for embedded LinuxA timeline for embedded Linux
A timeline for embedded Linux
 

Recently uploaded

Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 

Recently uploaded (20)

Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 

Booting Android: bootloaders, fastboot and boot images

  • 1. Booting Android Bootloaders, fastboot and boot images Booting Android 1 Copyright © 2011-2016, 2net Ltd
  • 2. License These slides are available under a Creative Commons Attribution-ShareAlike 3.0 license. You can read the full text of the license here http://creativecommons.org/licenses/by-sa/3.0/legalcode You are free to • copy, distribute, display, and perform the work • make derivative works • make commercial use of the work Under the following conditions • Attribution: you must give the original author credit • Share Alike: if you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one (i.e. include this page exactly as it is) • For any reuse or distribution, you must make clear to others the license terms of this work Booting Android 2 Copyright © 2011-2016, 2net Ltd
  • 3. About Chris Simmonds • Consultant and trainer • Author of Mastering Embedded Linux Programming • Working with embedded Linux since 1999 • Android since 2009 • Speaker at many conferences and workshops "Looking after the Inner Penguin" blog at http://2net.co.uk/ https://uk.linkedin.com/in/chrisdsimmonds/ https://google.com/+chrissimmonds Booting Android 3 Copyright © 2011-2016, 2net Ltd
  • 4. Overview • Android system images: boot, recovery, system, userdata and cache • Android "boot blobs" • Bootloaders for Android • Fastboot • Flash memory and flash filesystems Booting Android 4 Copyright © 2011-2016, 2net Ltd
  • 5. Image files • A typical build for an Android device produces five image files in out/target/product/<product> Image Description boot.img Kernel + ramdisk used for normal boot recovery.img Kernel + ramdisk used to boot into recovery mode system.img File system image for /system userdata.img File system image for /data cache.img File system image for /cache Booting Android 5 Copyright © 2011-2016, 2net Ltd
  • 6. Typical flash memory layout Bootloader Boot kernel + ramdisk Recovery kernel + ramdisk /system - read-only file system /data - read/write file system /cache - read/write file system misc (optional - used during OTA update) Booting Android 6 Copyright © 2011-2016, 2net Ltd
  • 7. The bootloader • All systems need a bootloader • Responsible for: • Early hardware initialisation • Load and boot kernel and initial ram filesystem • System maintenance, including loading and flashing new kernel and system images • Example: U-Boot • Open source • Used in many dev boards (BeagleBone, Raspberry Pi) and in many shipping products • http://www.denx.de/wiki/U-Boot/WebHome Booting Android 7 Copyright © 2011-2016, 2net Ltd
  • 8. Booting Android • It is possible to boot Android using a normal bootloader such as U-Boot • However, most devices include Android-specific features: • Support normal and recovery boot modes • Ability to load kernel + ramdisk blobs (boot.img and recovery.img) • The fastboot protocol • Example: LK (Little Kernel) • git://codeaurora.org/kernel/lk.git • Supports many Qualcomm-based devices as well as rudimentary support for BeagleBoard and PC-x86 Booting Android 8 Copyright © 2011-2016, 2net Ltd
  • 9. The Android bootloader • Pre JB 4.2, AOSP had source for a simple bootloader in bootable/bootloader/legacy • Used in early handsets (Android Dev Phone, HTC Dream) • Not updated since the Eclair release • Some of this code may have found its way into proprietary bootloaders Booting Android 9 Copyright © 2011-2016, 2net Ltd
  • 10. Android boot and recovery images • The files boot.img and recovery.img are created by the tool mkbootimg (the code is in system/core/mkbootimg) • They contain a compressed kernel, the kernel command line and, optionally, a ramdisk in the normal Linux compressed cpio format • Most Android bootloaders can read and load these images into memory • The format is defined in bootimg.h Booting Android 10 Copyright © 2011-2016, 2net Ltd
  • 11. Boot and recovery image format Header Kernel image (zImage) ramdisk image (compressed cpio) struct boot_img_hdr { unsigned char magic[8]; // "ANDROID!" unsigned kernel_size; unsigned kernel_addr; unsigned ramdisk_size; unsigned ramdisk_addr; unsigned second_size; // 2nd image: not used unsigned second_addr; unsigned tags_addr; unsigned page_size; // typically 2048 unsigned unused[2]; unsigned char name[16]; // product name unsigned char cmdline[512]; // kernel cmdline unsigned id[8]; // timestamp/checksum/etc unsigned char extra_cmdline[1024]; }; From system/core/mkbootimg/bootimg.h Booting Android 11 Copyright © 2011-2016, 2net Ltd
  • 12. Boot sequence Bootloader Boot recovery Boot normal Load recovery kernel and ramdisk Recovery mode Load normal kernel and ramdisk Run /init Read init*.rc Mount file systems Start services Normal mode Power on Booting Android 12 Copyright © 2011-2016, 2net Ltd
  • 13. Reverse-engineering a boot image • Sometimes it is useful to extract the files from a boot or recovery image • There are numerous tools to do so, for example boot-extract https://github.com/csimmonds/boot-extract $ boot-extract recovery.img Boot header flash page size 2048 kernel size 0x432358 kernel load addr 0x10008000 ramdisk size 0x173740 ramdisk load addr 0x11000000 name cmdline zImage extracted ramdisk offset 4403200 (0x433000) ramdisk.cpio.gz extracted $ ls ramdisk.cpio.gz recovery.img zImage Booting Android 13 Copyright © 2011-2016, 2net Ltd
  • 14. Extracting files from a ramdisk • The ramdisk is just a compressed cpio archive • Extract the files like so: $ zcat ramdisk.cpio.gz | cpio -i 5665 blocks $ ls charger fstab.manta property_contexts ... Booting Android 14 Copyright © 2011-2016, 2net Ltd
  • 15. Creating a new ramdisk • Do the following $ cd some-directory $ find . | cpio -H newc --owner root:root -ov > ∼/ramdisk.cpio $ cd ∼ $ gzip ramdisk.cpio • The end result will be ramdisk.cpio.gz Booting Android 15 Copyright © 2011-2016, 2net Ltd
  • 16. Creating a new boot image • You can create a boot or recovery image using the mkbootimg command • For example: $ mkbootimg --kernel zImage --ramdisk ramdisk.cpio.gz --base 0x10000000 --pagesize 2048 -o recovery-new.img • --base is used by mkbootimg to calculate the kernel and ramdisk load addresses as follows: • kernel_addr = base + 0x00008000 • ramdisk_addr = base + 0x01000000 Booting Android 16 Copyright © 2011-2016, 2net Ltd
  • 17. Fastboot • Fastboot is a USB protocol and a command language for various maintenance and development tasks • Fastboot protocol v0.4 is defined in: • bootable/bootloader/legacy/fastboot_protocol.txt (up to JB 4.1) • system/core/fastboot/fastboot_protocol.txt (JB 4.3 and later) NOTE: fastboot is not about the speed of booting; it is about making the development process simpler (and faster) Booting Android 17 Copyright © 2011-2016, 2net Ltd
  • 18. Booting into the bootloader • On a typical Android device you can boot into the bootloader by: • powering on while pressing various buttons (Google for details) • from a running device, typing: $ adb reboot-bootloader • Once the device has booted into the bootloader you can use the fastboot command on the development machine to communicate with it Booting Android 18 Copyright © 2011-2016, 2net Ltd
  • 19. fastboot commands (1/3) Basic commands Command Description devices List devices attached that will accept fast- boot commands getvar Get a variable continue Continue boot process as normal reboot Reboot device reboot-bootloader Reboot back into bootloader Booting Android 19 Copyright © 2011-2016, 2net Ltd
  • 20. fastboot commands (2/3) Flashing commands Command Description erase <partition> Erase <partition> flash <partition> Erase and program <partition> with <partition>.img of current product flash <partition> <filename> Erase and program <partition> with <filename> flashall Erase and program boot.img, recovery.img and system.img of current product and then reboot Where <partition> is one of boot, recovery, system, userdata, cache current product is $ANDROID_PRODUCT_OUT Note: the location and size of partitions is hard-coded in the bootloader Booting Android 20 Copyright © 2011-2016, 2net Ltd
  • 21. fastboot commands (3/3) Special commands Command Description oem Device-specific operations boot <kernel> <ramdisk> Load and boot kernel and ramdisk Example: $ fastboot -c "kernel command line" boot zImage ramdisk.cpio.gz Booting Android 21 Copyright © 2011-2016, 2net Ltd
  • 22. fastboot variables The getvar command should return values for at least these variables: Variable Meaning version Version of the protocol: 0.4 is the one doc- umented version-bootloader Version string of the Bootloader version-baseband Version string of the Baseband Software product Name of the product serialno Product serial number secure If "yes" the bootloader requires signed im- ages Booting Android 22 Copyright © 2011-2016, 2net Ltd
  • 23. Unlocking the bootloader • Most devices ship with the bootloader locked • fastboot getvar secure returns true • Unlocking - where it is allowed - is device specific • For example, on recent Nexus devices you use a fastboot oem command $ fastboot oem unlock • Answer yes to the on-screen prompt • For security reasons, this wipes the data and cache partitions Booting Android 23 Copyright © 2011-2016, 2net Ltd
  • 24. What goes where? ramdisk.img: read-only ramdisk /init /init.rc /system /data /cache system.img: read-only /app built-in Android apps /bin native binaries /framework Java components of framework /lib native libraries ... userdata.img: read-write /app user-installed Android apps /data persistent data /dalvik-cache optimised Dex files /system ... cache.img: read-write /backup place to backup up app data /recovery logs used in recovery mode Booting Android 24 Copyright © 2011-2016, 2net Ltd
  • 25. Flash memory devices • In almost all cases data is stored in flash memory • There are two main types • Raw NAND flash, where the chips are accessed directly by Linux • Managed flash, which contain an on-chip controller • Managed flash is the most common • Examples: • MMC, SD and MicroSD cards: removeable storage • eMMC (embedded MMC): same electrical interface as MMC, but packaged as a chip • UFS (Universal Flash Storage): similar to eMMC, but faster and with a SCSI command set Booting Android 25 Copyright © 2011-2016, 2net Ltd
  • 26. Raw NAND flash • NAND flash chips are accessed via the Linux MTD (Memory Technology Device) drivers • Partitions are named /dev/block/mtdblockN where N is the partition number • /proc/mtd lists the partitions and sizes # cat /proc/mtd dev: size erasesize name mtd0: 05660000 00020000 "system" mtd1: 04000000 00020000 "userdata" mtd2: 04000000 00020000 "cache" Booting Android 26 Copyright © 2011-2016, 2net Ltd
  • 27. File systems for raw NAND flash • Flash translation layer implemented in the filesystem • NAND flash devices require special filesystem support, such as: • jffs2 (Journalling Flash File System 2) • Note: incompatible with the Android run-time (no writeable mmaped files)! • yaffs2 (Yet Another Flash File System 2) • ubifs (Unsorted Block Image File System) • Most Android devices with NAND flash use yaffs2 Booting Android 27 Copyright © 2011-2016, 2net Ltd
  • 28. SD and eMMC • Flash translation layer implemented in the chip • The controller chip splits flash memory into 512-byte sectors just like hard drives • Accessed via the Linux mmcblock driver • Partition device nodes have names of the form mmcblk[chip number]p[partition number] • For example: /dev/block/mmcblk0p3 /system /dev/block/mmcblk0p8 /data /dev/block/mmcblk0p4 /cache Booting Android 28 Copyright © 2011-2016, 2net Ltd
  • 29. File systems for eMMC • eMMC devices "look" like hard drives • Use the same filesystem types • The preferred type in most Android devices is ext4 • Alternative: F2FS (Flash Friendly File System) • Develpoed by Samsung, and deployed on some of their devices • Faster file writes than ext4 Booting Android 29 Copyright © 2011-2016, 2net Ltd
  • 30. SD cards and other removable media • This includes MMC, SD, microSD and USB flash drives • For compatibility with other operating systems they come pre-formatted with FAT32 • Use the Linux vfat driver Booting Android 30 Copyright © 2011-2016, 2net Ltd
  • 31. Delving deeper • This is an excerpt from my Android Porting class • If you would like to find out more secrets of Android, visit http://www.2net.co.uk/training.html and book a course Booting Android 31 Copyright © 2011-2016, 2net Ltd