{"id":265,"date":"2014-04-14T05:21:05","date_gmt":"2014-04-14T12:21:05","guid":{"rendered":"http:\/\/bclary.com\/blog\/?p=265"},"modified":"2014-04-14T05:21:05","modified_gmt":"2014-04-14T12:21:05","slug":"splitting-and-packing-android-boot-images","status":"publish","type":"post","link":"https:\/\/bclary.com\/blog\/2014\/04\/14\/splitting-and-packing-android-boot-images\/","title":{"rendered":"Splitting and Packing Android Boot images"},"content":{"rendered":"<p>After wandering twisty little passages, all alike concerning rooting Android devices I decided the best way forward for devices with unlocked bootloaders was to root via modifying the default.prop values in the boot image. There are a number of different scripts available on various sites which purport to unpack and pack Android boot images, but it seemed that the best approach was to go to the <a href=\"https:\/\/android.googlesource.com\/platform\/system\/core\/+\/android-4.4_r1\/mkbootimg\/\">source<\/a> and see how Android dealt with boot images.<\/p>\n<p>I created <a href=\"https:\/\/github.com\/bclary\/bootimg\">spbootimg and pkbootimg<\/a> from the official mkbootimg in order that it would properly handle official android boot images at least.<\/p>\n<h2>spbootimg<\/h2>\n<pre>\r\nusage: spbootimg\r\n       -i|--input <filename>\r\n<\/pre>\n<p>spbootimg splits an Android boot image file into separate files:<\/p>\n<p>* &lt;bootimg-filename&gt;-kernel &#8211; kernel<br \/>\n* &lt;bootimg-filename&gt;-first-ramdisk &#8211; ramdisk<br \/>\n* &lt;bootimg-filename&gt;-second-ramdisk &#8211; only created if it existed in the input boot image file.<br \/>\n* &lt;bootimg-filename-header&gt; &#8211; text file containing constants discovered in the boot image<\/p>\n<p>You can download the source for <a href=\"https:\/\/github.com\/bclary\/bootimg\">spbootimg and pkbootimg<\/a> and build it yourself. I don&#8217;t provide binaries because I do not wish people who do not understand the consequences of their actions to brick their devices.\n<\/p>\n<h2>pkbootimg<\/h2>\n<pre>\r\nusage: pkbootimg\r\n       --kernel <filename>\r\n       --kernel-addr <address>\r\n       --ramdisk <filename>\r\n       --ramdisk-addr <address>\r\n       [ --second <2ndbootloader-filename>]\r\n       [ --cmdline <kernel-commandline> ]\r\n       [ --board <boardname> ]\r\n       [ --pagesize <pagesize> ]\r\n       --second-addr <address>\r\n       --tags-addr <address>\r\n       -o|--output <filename>\r\n<\/pre>\n<p>pkbootimg takes the output of spbootimg: a kernel file, a ramdisk file, an optional ramdisk file; and using the command line, board, page size and address information discovered in the original boot image, packs them into a new boot image which can be flashed onto a device using fastboot.<\/p>\n<h2>default.prop<\/h2>\n<p>Looking at the source for <a href=\"https:\/\/android.googlesource.com\/platform\/system\/core\/+\/android-4.4_r1\/adb\/adb.c\">adb.c<\/a>, we see that at a minimum we need a build of adb where ALLOW_ADBD_ROOT was set and either of the following was set in the ramdisk&#8217;s default.prop:<\/p>\n<pre>\r\n<code>ro.secure=0<\/code>\r\n<\/pre>\n<p>or<\/p>\n<pre>\r\nro.debuggable=1\r\nservice.adb.root=1\r\n<\/pre>\n<p><code>ro.secure=0<\/code> will result in adbd running as root by default. <code>ro.debuggable=1<\/code> and <code>service.adb.root=1<\/code> will allow you to run adbd as root via the <code>adb root<\/code> command.<\/p>\n<p>If your device&#8217;s version of adb was not built with ALLOW_ADBD_ROOT set, you will need to build your own version and place it in the ramdisk at <code>sbin\/adbd<\/code>.<\/p>\n<p>Once you are able to run <code>adb<\/code> as root via <code>adb root<\/code>, you will be able to remount the <code>\/system\/<\/code> directory as writable and can install anything you wish.<\/p>\n<h2>su<\/h2>\n<p>Some of the automation used in mozilla requires the use of a version of the <code>su<\/code> command which has the same command line syntax as <code>sh<\/code>. In particular, we require that <code>su<\/code> support calling commands via <code>su -c \"command args...\"<\/code>. You can possibly build your own version of <code>su<\/code> which will run commands as root without access control or you can use one of the available &#8220;Superuser&#8221; apps which manage access to <code>su<\/code> and provide some degree of security. I&#8217;ve found <a href=\"https:\/\/github.com\/koush\/Superuser\">Koushik Dutta&#8217;s Superuser<\/a> to work well with Android up to 4.4.<\/p>\n<p>If you use Koushik&#8217;s Superuser, you will need at least version 1.0.3.0 and will need to make sure that the <code>install-recovery.sh<\/code> script is properly installed so that Koushik&#8217;s <code>su<\/code> runs as a daemon. This is automatically handled if you install Superuser.apk via a recovery image, but if you install Superuser manually, you will need to make sure to unpack Superuser.apk and manually install:<\/p>\n<ul>\n<li>su to \/system\/xbin\/su<\/li>\n<li>install-recovery.sh to \/system\/etc\/install-recovery.sh<\/li>\n<li>Superuser.apk to \/system\/app\/Superuser.apk<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>After wandering twisty little passages, all alike concerning rooting Android devices I decided the best way forward for devices with unlocked bootloaders was to root via modifying the default.prop values in the boot image. There are a number of different scripts available on various sites which purport to unpack and pack Android boot images, but &hellip; <a href=\"https:\/\/bclary.com\/blog\/2014\/04\/14\/splitting-and-packing-android-boot-images\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Splitting and Packing Android Boot images&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-265","post","type-post","status-publish","format-standard","hentry","category-mozilla-ateam"],"_links":{"self":[{"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/posts\/265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/comments?post=265"}],"version-history":[{"count":5,"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/posts\/265\/revisions"}],"predecessor-version":[{"id":270,"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/posts\/265\/revisions\/270"}],"wp:attachment":[{"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/media?parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/categories?post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bclary.com\/blog\/wp-json\/wp\/v2\/tags?post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}