Two days ago I hard-bricked my phone. Today I un-bricked it.

I bought my first smartphone a couple of weeks ago. I had selected a 3.5 years old model - a Mi A1 32GB - through the store’s website. It was being sold at a clearance price of about $120. Its Chinese sibling Mi 5X with twice as much storage cost $20 more. I intended to re-flash the phone (I had learnt about LineageOS shortly before that), so I chose the cheaper model for two reasons:

  1. LineageOS claimed support for the A1 but not 5X. Other sources stated that hardware-wise the two models were identical, the difference only being that A1 had stock Android whereas 5X came with MIUI China variant. Therefore, the list of supported devices on LineageOS’s website could contain 5X implicitly, yet it was safer to stay within the explicitly stated spec.

  2. I was aware of the risk of ending up with a bricked device, so minimizing the potential loss seemed prudent.

I headed for the main store of the chain only to find out that the last A1 was waiting for its buyer in the store on the other side of the city. They had the 5X, though. Time is money, and this was definitely not the case worth sticking to the original plan. So I picked up the 5X, in strong belief that it is just a disguised A1.

The phone had a global version of MIUI 8. I didn’t immediately get down to replacing it with LineageOS. The new device served as a tool and I was going to use it for work as is until hitting its limits. The primary function of the device was to provide me with internet connection (I also had a more expensive and less convenient backup option via a USB 3G modem). And in several days I got an Android project, in which the phone could be utilized as a native testing platform. It turned out, however, that the OS refused to install APKs from unknown sources, and the attempts to enable the settings which would allow that failed in a strange way. It is clear now that a Mi 5X with a global MIUI is not an official configuration by Xiaomi. It is rather a hacked set-up by 3rd party retailers. Combined with Xiaomi’s security measures, it made the device not very well suited for development. Given that the client had provided the source package only for the armeabi-v7a platform, testing the builds in the emulator on the laptop was not a good option. The time of trying LineageOS had come.

And then it turned out that 5X was not an A1 from the point of view of available ROMs. I don’t know to what extent A1 and 5X have identical hardware. After all no two phones, even of the same model, are identical - they have to have different serial numbers and IMEIs, at the least. But even if A1 and 5X differ only in such seemingly insignificant things as product code, Android doesn’t care. Android is not like Linux. Given support for various components of an x86 platform, Linux works on a wide variety of configurations, automatically discovering available hardware and accomodating itself to the system it is running on. You don’t have to build a separate kernel for each model of a x86 laptop or desktop PC. One build of Linux (and Windows too!) runs on them all equally well. In the Android world that is not the case. Maybe the root cause is that the ARM platforms are not standardized like x86/x86_64. Or maybe the fragmentation of the Android ecosystem comes from the OEMs’ or carriers’ desire to vendor-lock their devices to their own customized Android variants. Alternatively, it is possible that smartphones, as originally inferior devices in terms of hardware capabilities, could not afford the luxury of a “bloated” general-purpose OS that contains every possible driver and support for dealing with various hardware setups. Android is such an OS as long as we talk about source code. But when it is being built/compiled, it must be configured/optimized for a particular device. And it won’t run on a device that looks different, even if only by name!

While hitting and overcoming various issues in installation and ROM-flashing procedures I soft-bricked my device several times. That happened mostly in expected ways and restoring the phone to the more-or-less original state from a backup made me feel more confident. Of course, there were also minutes of some uneasiness:

  1. On my first restore from backup I found that the phone doesn’t accept my PIN. That was not a big deal, since wiping the data on the device from the recovery mode reset it to factory state. But that meant that I had to go through the phone setup process after every restore. Fortunately, a quick search lead to an amendment in the restore procedure which removed the PIN. I took advantage of it several times, but while preparing the next full backup I made sure that the screen lock was disabled.

  2. While in semi-blind search mode, I once changed the recovery ROM to an earlier version. By the time I got the next soft-bricked state the memory of that action had somewhat faded out, and I couldn’t understand why my backup (made by a more recent version of the recovery software) didn’t show up in the “Restore” view.

I now realize that I was lucky that the instructions from the LineageOS installation guide didn’t work out of the box and that my search for workarounds discovered hints in the right order. Otherwise I would have soft-bricked my device without having made a full backup at a stage when I didn’t yet understand how it all works. Such a soft-brick doesn’t seem a big problem for the current me, but then I would have been left without a possibility of learning by trial and error. Though, maybe, then I would have no other choice than to systematically study the guides on xda-developers (which I haven’t yet done) and would arrive at a more solid understanding of the mechanics of the Android boot process, flashing, etc, and would have avoided the hard-brick. I don’t know.

Whatever, the LineageOS image downloaded from the official website didn’t boot so I thought that maybe I better try to build an image myself. The expectation was that going through the build process would shed some light on some subtleties beyond my current - very superficial - understanding of Android, whereupon I would be able to come up with required tweaks myself. How naive I had been then!

The decision to build LineageOS on my own was made while the device was in soft-bricked state. I don’t remember for sure why I couldn’t unbrick it, but likely it was due to the recovery ROM mismatch issue mentioned above. So I was left without the primary access to the internet and had to rely on the backup option. It turned out that merely downloading the Android sources was beyond my patience. When it became clear that the expected completion time and total traffic consumption of the process could not be predicted, I interrupted it and went to sleep.

In the morning, I was able to figure out the issue and unbrick my phone. But I was ripe for deciding that I had made enough effort on my own and turning for help on the #lineageos IRC channel was justified. This was the first time when I encountered a relatively harsh response (after I was told that Mi 5X was not supported but kept asking questions). In any case, the short chat was useful since the LineageOS guys directed me to the XDA-developers forum, which is a more appropriate place for such type of inquiries.

Following received advice I started looking for another custom AOSP-based OS that supports 5X. I found one (Havoc-OS) but the attempt to install it on my device also failed with a new type of soft-bricked state that couldn’t be fixed using my backup. With a good many people doing for several years what I was up to for just a few days, finding a solution to that situation was not so difficult either.

Finally, I discovered that enthusiasts at XDA-developers had created tools for converting A1 ROMs to 5X ROMs. With the help of those tools I managed to install and boot LineageOS on my device. But the sound was broken! And though my task was about video encoding and playback, the issues with the sound slowed down video playback to an extent that I considered unacceptable for work. That’s why I re-flashed the phone to its original MIUI 8 and then tried changing the OS to AndroidOne (A1’s native OS).

The install seemingly worked, since the phone booted up. However the first time set-up of AndroidOne required internet connection (how silly!). There was no wifi, and the OS reluctantly - and stupidly - offered to use mobile connection without providing a chance to configure the APN. The process was stuck so I turned off the phone thinking that there was a problem with the modem firmware. I decided to flash the device with all of the images contained in the A1 ROM. And got a hard-brick! The phone responded to all attempts to boot it in recovery or fastboot mode only with some vibration. I had overwritten the bootloader with a version that refused to work on my device!

Fortunately, a device can be recovered from such a state using a more complex procedure. The back cover must be removed, two special pins on the motherboard must be shorted and the phone must be powered up via the USB cable connected to a PC running special software. Then the device can be flashed in a so called emergency download (EDL) mode. Removing the back cover using my fingernails and a Victorinox knife was quite a challenge (the phone now has some scars on it). It took multiple attempts to enter the EDL mode. Keeping the test points shorted while plugging in the USB connector was not an easy task either. I was not sure that the Linux version of the EDL software was supposed to work, but I kept trying. Should the battery be connected or not? Should the EDL software be started before or after the phone is connected? Maybe I should run it as root? And then suddenly I saw some output on the laptop’s screen. It worked! It was doing something! The process seemingly completed but the phone only rebooted in the familiar fastboot mode, whereas I expected the phone to be fully flashed with MIUI China ROM (native ROM for Mi 5X that I downloaded for the lack of any other choice). Whatever, fastboot screen is already better than a hard-brick. I flashed the same ROM via fastboot and my device was no longer a brick! Chinese (non-global) version of MIUI is not what I am happy to have on my phone, but at least theoretically it should be possible to restore it to the backed up state.

Overall, flashing my 5X was not a smooth experience though it was an interesting - I’d rather say, an adventurous - one. Had I got an A1 I would be a less knowledgeable person now.

Update 2021-01-20

MIUI China didn’t last long on my 5X. I restored it to the original state with MIUI Global. Then hard-bricked it again. This time unbricking it took much less effort (removing the back hull using a plastic tool like shown on YouTube was so much easier). Now the phone has AndroidOne with video recording not working. But it enabled me to complete my contract, albeit three days past the due date.