{"id":967,"date":"2020-09-07T00:57:56","date_gmt":"2020-09-06T21:57:56","guid":{"rendered":"https:\/\/blog.andresgomez.org\/?p=967"},"modified":"2020-09-07T22:31:18","modified_gmt":"2020-09-07T19:31:18","slug":"installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-1-5-downgrading-sonys-stock-firmware","status":"publish","type":"post","link":"https:\/\/blog.andresgomez.org\/es\/2020\/09\/07\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-1-5-downgrading-sonys-stock-firmware\/","title":{"rendered":"Installing LineageOS in the Sony Xperia XZ2 Compact Dual (in GNU\/Linux) 1\/5: Downgrading Sony&#8217;s Stock Firmware"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">WARNING<\/h2>\n\n\n\n<p>I have no responsibility whatsoever if this guideline causes any harm to your device. The intention of these posts are solely as personal notes for myself. Follow them at your own risk.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">WARNING<\/h2>\n\n\n\n<p>Through these steps I will unlock the phone&#8217;s bootloader, erasing all data. This includes the DRM keys stored in the Trim Area (TA) partition. I&#8217;ll attempt backing them up but, as of today, there is no way of restoring them to the previous state nor knowing if the actual backup is usable at all.<\/p>\n\n\n\n<p>Without these DRM keys, several audio and video proprietary functionality provided by Sony <a rel=\"noreferrer noopener\" href=\"https:\/\/developer.sony.com\/develop\/open-devices\/get-started\/unlock-bootloader\" data-type=\"URL\" data-id=\"https:\/\/developer.sony.com\/develop\/open-devices\/get-started\/unlock-bootloader\" target=\"_blank\">won&#8217;t be available<\/a> <strong>including some camera post-processing features<\/strong>, color gamut profiles, white balance, noise reduction, X-Reality Video Enhancement, DSEE HX, ClearAudio+, and Widevine L1 support for HD Netflix.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why<\/h2>\n\n\n\n<p>I want to have a phone running Free Software with the possibility of using all the major apps out there. That means, <a href=\"https:\/\/sailfishos.org\/\" data-type=\"URL\" data-id=\"https:\/\/sailfishos.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">unfortunately<\/a>, some kind of Android flavor. I also want a small phone and, since I&#8217;m a Spaniard living in Finland, I&#8217;d like that my phone has dual SIM capability. Until now I was using a <a rel=\"noreferrer noopener\" href=\"https:\/\/www.gsmarena.com\/xiaomi_redmi_2-6884.php\" data-type=\"URL\" data-id=\"https:\/\/www.gsmarena.com\/xiaomi_redmi_2-6884.php\" target=\"_blank\">Xiaomi Redmi 2<\/a> but, after years of usage, I cannot squeeze it any more. I&#8217;d also love to have a decent camera, if possible.<\/p>\n\n\n\n<p>After quite some research, my conclusion is that the only real alternative that ticks (most of) the boxes is the <a rel=\"noreferrer noopener\" href=\"https:\/\/developer.sony.com\/develop\/open-devices\/get-started\/unlock-bootloader\" data-type=\"URL\" data-id=\"https:\/\/developer.sony.com\/develop\/open-devices\/get-started\/unlock-bootloader\" target=\"_blank\">Sony Xperia XZ2 Compact Dual<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preconditions<\/h2>\n\n\n\n<p>I&#8217;ll be doing all the stems in a Debian Buster GNU\/Linux distribution on a x86_64 platform.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Downgrading the stock firmware<\/h2>\n\n\n\n<p>If you have read the warning above, you now know that installing LineageOS implies unlocking the bootloader. In turn, this means wiping the TA partition and losing the DRM keys, which will cause several advanced audio and video features to get lost forever.<\/p>\n\n\n\n<p>We want to keep the hope that, at least, we would be able to restore this functionality. This means that we want to backup the TA partition. Doing that without actually unlocking the bootloader is not really possible &#8230; unless you exploit a security bug.<\/p>\n\n\n\n<p>The Sony firmwares build 52.1.A.0.618 contains one such kernel bug. Therefore, first thing, downgrading the current firmware in the device to use the one affected.<\/p>\n\n\n\n<p>As a previous step, I downloaded the firmware that was running in my device at the time: 8324_Customized NOBA_1313-6167_52.1.A.3.49_R4C<\/p>\n\n\n\n<p>For downloading the up to date firmware I used the <a rel=\"noreferrer noopener\" href=\"https:\/\/xperifirm.com\/download\/xperifirm-v5-4-0\/\" data-type=\"URL\" data-id=\"https:\/\/xperifirm.com\/download\/xperifirm-v5-4-0\/\" target=\"_blank\">XperiFirm<\/a> program:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ apt install mono-complete\nroot$ cert-sync \/etc\/ssl\/certs\/ca-certificates.crt\nroot$ certmgr -ssl -m https:\/\/software.sonymobile.com\n(Entered Y twice when asked)\n$ mono XperiFirm.exe<\/pre>\n\n\n\n<p>Then, I selected the <strong>Xperia XZ2 Compact<\/strong> <em>Apollo<\/em>: <strong>H8324<\/strong> <em>dual<\/em> phone and downloaded the <strong>Nordic Combined<\/strong> available firmware.<\/p>\n\n\n\n<p>Now, I downloaded and extracted the exploitable <a rel=\"noreferrer noopener\" href=\"https:\/\/androidfilehost.com\/?fid=4349826312261814156\" data-type=\"URL\" data-id=\"https:\/\/androidfilehost.com\/?fid=4349826312261814156\" target=\"_blank\">H8324-52.1.A.0.618<\/a> firmware for the Xperia XZ2 Compact Dual and followed <a rel=\"noreferrer noopener\" href=\"https:\/\/forum.xda-developers.com\/xperia-xz2-compact\/how-to\/guide-downgrade-xz2-commpact-android-10-t4071111\" data-type=\"URL\" data-id=\"https:\/\/forum.xda-developers.com\/xperia-xz2-compact\/how-to\/guide-downgrade-xz2-commpact-android-10-t4071111\" target=\"_blank\">this guide<\/a> to install it into the phone without unlocking the bootloader.<\/p>\n\n\n\n<p>We want to use the <a href=\"http:\/\/www.flashtool.net\" data-type=\"URL\" data-id=\"http:\/\/www.flashtool.net\" target=\"_blank\" rel=\"noreferrer noopener\">Flashtool<\/a> to create a <em>bundle<\/em> with the parts of the firmware we are going to use.<\/p>\n\n\n\n<p>I downloaded the <a rel=\"noreferrer noopener\" href=\"http:\/\/www.flashtool.net\/downloads_linux.php\" data-type=\"URL\" data-id=\"http:\/\/www.flashtool.net\/downloads_linux.php\" target=\"_blank\">latest version<\/a> of the tool (0.9.29.0 at the time) and tried to launch it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ DISPLAY=:0.0 .\/FlashTool\nRunning as root.\nError: dl failure on line 603\nError: failed \/home\/tanty\/personal\/sony_xperia_xz2c\/flashtool\/FlashTool\/x10flasher_native\/jre\/lib\/server\/libjvm.so, because \/lib\/x86_64-linux-gnu\/libm.so.6: version `GLIBC_2.29' not found (required by \/home\/tant\ny\/personal\/sony_xperia_xz2c\/flashtool\/FlashTool\/x10flasher_native\/jre\/lib\/server\/libjvm.so)<\/pre>\n\n\n\n<p>Bad news &#8230; it seems this version was compiled against a different C toolchain? Let&#8217;s use an older version then. <a rel=\"noreferrer noopener\" href=\"https:\/\/androidfilehost.com\/?fid=4349826312261625499\" data-type=\"URL\" data-id=\"https:\/\/androidfilehost.com\/?fid=4349826312261625499\" target=\"_blank\">0.9.27.0<\/a> it is.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ DISPLAY=:0.0 .\/FlashTool\nRunning as root.\nUsed java home : \/usr\n03\/057\/2020 16:57:14 - INFO - &lt;- This level is successfully initialized\n(Flashtool:8027): GLib-CRITICAL **: 16:57:14.971: g_base64_encode_step: assertion 'in != NULL' failed\n(Flashtool:8027): GLib-CRITICAL **: 16:57:14.971: g_base64_encode_step: assertion 'in != NULL' failed\n...<\/pre>\n\n\n\n<p>Voil\u00e1!<\/p>\n\n\n\n<p>In the UI, we select <em>Tools -&gt; Bundles -&gt; FILESET Decrypt<\/em>. In the popping up Window we browse to the folder containing the exploitable firmware: <em>H8324_Customized FR_1313-2469_52.1.A.0.618_R2C<\/em>. There, we choose the 3 zip files that it contains and move it from the left side to the right side in the window and click <em>Convert<\/em>.<\/p>\n\n\n\n<p>Once it has finished, we want to skip creating the bundle by just pressing <em>Cancel<\/em> in the next window. We have finished using <em>flastool<\/em>.<\/p>\n\n\n\n<p>In the exploitable firmware directory we now have a new folder called <em>decrypted<\/em>. We want to delete some files there:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ rm decrypted\/*ta\nroot$ rm decrypted\/boot\/*ta<\/pre>\n\n\n\n<p>Before we proceed to flash, we need to add some rules to the <em>udev<\/em> system in our computer so it can identify the Xperia phone:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ echo 'SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"0fce\", ATTRS{idProduct}==\"*\", MODE=\"0777\"' &gt; \/etc\/udev\/rules.d\/51-sony.rules\nroot$ service udev restart<\/pre>\n\n\n\n<p>Now, we want to use another tool to flash these files into the phone: <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/newflasher\/newflasher\" data-type=\"URL\" data-id=\"https:\/\/github.com\/newflasher\/newflasher\" target=\"_blank\">newflasher<\/a>. I <a rel=\"noreferrer noopener\" href=\"https:\/\/forum.xda-developers.com\/attachment.php?attachmentid=5087455&amp;d=1598550416\" data-type=\"URL\" data-id=\"https:\/\/forum.xda-developers.com\/attachment.php?attachmentid=5087455&amp;d=1598550416\" target=\"_blank\">downloaded<\/a> the latest v36 version, extracted, placed the executable in the <em>decrypted<\/em> folder from the previous step:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ mv newflasher.x64 decrypted\nroot$ cd decrypted\nroot$ chmod +x newflasher.x64<\/pre>\n\n\n\n<p>Last thing is setting the phone into <em>flashmode<\/em>.<\/p>\n\n\n\n<p>First, let&#8217;s enable developer mode in the phone: <em>Settings -&gt; About phone<\/em>, and hit several times the <em>Build number<\/em> field until it states that you have become a developer. Then, go to <em>Settings -&gt; System -&gt; Advanced -&gt; Developer options<\/em> and switch on the <em>USB debugging<\/em> option.<\/p>\n\n\n\n<p>Now, power down the phone. Once off, press and hold <kbd>Volume Down<\/kbd> and connect the USB cable that is connected to the computer in the other end. The led of the phone turns on and stays on. It is now into flashmode. Let&#8217;s flash:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ .\/newflasher.x64\n\n[...]\n\nReboot mode at the end of flashing:\ntypa 'a' for reboot to android, type 'f' for reboot to fastboot, type 's' for reboot to same mode, type 'p' for poweroff, and press ENTER.\na\n\n[...]\n\nOptional step! Type 'y' and press ENTER if you want dump trim area, or type 'n' and press ENTER to skip.\nDo in mind this doesn't dump drm key since sake authentifiction is need for that! But it is recommend to have dump in case hard brick!\nn\n\n[...]\n\nRecommended step to skip this! Type 'y' and press ENTER if you want flash persist partition, or type 'n' and press ENTER to skip.\nMore info https:\/\/forum.xda-developers.com\/xperia-xz1-compact\/help\/android-attest-key-lost-bootloader-t3829945\nn\n\n[...]\n\nDevice is put now out of flash mode.\nSent command: Sync\nWaiting sync to finish\u2026\n\u2026\u2026\u2026\u2026\u2026\u2026 done\nSent command: continue.\nDone.\nClosing device.<\/pre>\n\n\n\n<p>Notice the questions and the answers. After a while, the phone will complete its reboot and we will be able to verify that the running firmware is the one flashed.<\/p>\n\n\n\n<p>That all by now, next step: <a href=\"https:\/\/blog.andresgomez.org\/2020\/09\/08\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-2-5-backing-up-the-trim-area-ta-partition\/\" data-type=\"URL\" data-id=\"https:\/\/blog.andresgomez.org\/2020\/09\/08\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-2-5-backing-up-the-trim-area-ta-partition\/\" target=\"_blank\" rel=\"noreferrer noopener\">backing up the TA partition<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WARNING I have no responsibility whatsoever if this guideline causes any harm to your device. The intention of these posts are solely as personal notes for myself. Follow them at your own risk. WARNING Through these steps I will unlock &hellip; <a href=\"https:\/\/blog.andresgomez.org\/es\/2020\/09\/07\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-1-5-downgrading-sonys-stock-firmware\/\">Sigue leyendo <span class=\"meta-nav\">&rarr;<\/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":[4,6,7,20],"tags":[],"class_list":["post-967","post","type-post","status-publish","format-standard","hentry","category-english","category-free-software","category-general","category-mobile"],"_links":{"self":[{"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/posts\/967"}],"collection":[{"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/comments?post=967"}],"version-history":[{"count":13,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/posts\/967\/revisions"}],"predecessor-version":[{"id":997,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/posts\/967\/revisions\/997"}],"wp:attachment":[{"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/media?parent=967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/categories?post=967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/tags?post=967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}