I did not write 2nd init, it was originally made by these genius developers for the Motorola Milestone (first device with locked bootloader, it's the GSM version of the OG Droid) and then the developer CVPCS ported it to the Droid X which also appear to work with all subsequent Motorola phones
What the locked bootloaders do is it has a signature in the boot.img file which contains the kernel (the backbone the system) and something called the ramdisk which contains a bunch of scripts necessary to boot the system and a file called init that Motorola made. Normally with phones that have an unlockable bootloader is they disassemble the boot.img and take the kernel and replace the ramdisk with a custom one for CM and reassemble it and flash it to the phone. However, making a custom boot.img will fail the signature checks and the phone won't boot. So what 2nd init does is it hijacks the boot process and unzips the hijack-boot.zip (which contains our ramdisk that we weren't able to modify) and unzips it after the signature check is completed so we can have a custom ramdisk that allows us to boot CM. It's kinda like a trojan horse but in a good way. Hope this helps : D
Certainly. Thanks.
So what's the bare minimum needed in /system to trick the initramdisk to load 2nd-init? Sure there has to be something in /system that tells the motorola initrd to go ahead and unzip hijack-boot.zip and execute it on every boot, right?
From my understanding is that what 2ndinit does after it has successfully hijacked the init process it will check for
/data/.recovery_mode, if it exists then boot to recovery, if it doesn't then boot to CM. Certainly not as elegant as normal recovery but bearable.
So into development, I think an important question to make my life less miserable is that: Can we make a 2ndinit so that it will pause for a couple of seconds and listen for a certain keystroke (or check if USB is plugged in or whatever we can do conditionally) on boot, if we hold the key down it will boot to recovery, if not it will proceed to CM? That way if I flashed a borked version I could always go to recovery if I mess up in the process of cooking and testing new ROMs. Certainly I don't know if I can bear with sbf_flashing and upgrading and rerooting and bootstrapping every freaking single time I mess up.
Or even easier, if that file does NOT exist then boot into recovery, if that file exists then boot into CM. Now that means if I have a major mess up but still have CWM working, I can simply go to the stock Motorola recovery and format data and it would trigger CWM to come up next time because that would remove the file.
Oh by the way I discovered two very nice tricks:
- Alt Shift Backspace == Alt Control Delete
- The menu for the new stock Motorola recovery won't bring up the menu when we press @ anymore. We have to call the menu by pressing Vol Up + Vol Down.
