• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[Dev] *obsolete* Xperia S Boot Manager v0.1 (devs only for now)

Search This thread

letama

Senior Member
Feb 13, 2008
1,690
2,324
Hello Guys,

Here is my last toy, it's a dual boot system for the xperia S:


It lets you start two different kernels with their associated cpio with a third kernel that handles the boot menu and embeds cwm. It works with any kernel, this is not kexec based. As a demo in the video, I have stock firmware on regular partitions on one and cm9 on the other one with loopbacks on internal storage. I'll experiment later on with partitioning to see if we could have two sets of native partitions to make it more comfortable.

As it it's, it's quite rough, but if anyone has interest in it I will release it as it is and try to improve usability.

This is for devs and advanced users only, you would have to fiddle a lot to get the second build to run, you need an arm toolchain to embed both kernels and you have to modify its cpio.

I'm working on tools to flash kernels directly on device, but they're not ready yet. And ideally, CWM would need to be extended to support two environments. Don't expect quick progress, I don't have much free time to work on this.

Here are some details on how it works:

  1. I trimmed down a stock kernel to remove some fat and add a driver to set a specific memory location.
  2. I embed a small assembly loader with this kernel and its cpio plus the other 2.
  3. The tiny kernel is loaded first, it displays the menu and eventually starts cwm. The menu will set the memory location with the kernel choice, then reboot.
  4. At next reboot, the assembly loader will detect the kernel choice and start the appropriate kernel.

So, in fact, you're booting two times, first the small loader, then the real boot.

It adds some boot time, but it's not dramatic. The advantage is that it's easy to build the loader, it's a simple init. Second advantage, the second kernel is running on a "fresh" start, no left-over in memory, no kexec patch to apply, it works with any kernel. Last, cwm can be embedded with the tiny kernel, so it's finally independent from the build kernel.

First a disclaimer: I'm not responsible if you fry your phone using this, it's very experimental and I'm not 100% sure running a build on loopback won't reduce internal flash lifetime. I don't expect problem, but proceed with caution!

* Updates *

2012-09-07: Trimmed kernel uploaded to gitorious here , branch bootloader_kernel, boot menu (FBMenu, thanks to openAOS for initial release!) source added here.

2012-09-06, more details here :

1) on-device kernel flasher attached (kf_v0.1.zip). It let you flash kernel 1 or kernel 2 directly from device (adb from recovery for instance). You must have previously flashed dual.elf in fastboot!

And again, all of this is highly experimental! Be careful.


syntax:

kf [1|2] kernel_zimage_file cpio_file

Source code at: https://gitorious.org/sony-tools/dual_loader_kf

2) Loader source code uploaded to: https://gitorious.org/sony-tools/sony-tools, in dual directory.

2012-09-04:

If you have a 6.1.A.2.45 stock firmware, you can try the setup displayed in the video:

  1. Download package here (mirror) and extract it on your PC.
  2. Copy the 3 ext4 files at the root of the phone internal storage.
  3. Reboot in fastboot mode
  4. Flash dual.elf in fastboot mode with "fastboot flash boot dual.elf".
  5. Reboot with "fastboot reboot"

You should now have the boot menu at each phone start. If you want to get rid of it, just reflash your original firmware kernel.

Note:
- I'm not sure cwm is working completely properly, I barely tested it.
- it may work with another stock firmware version, but the embedded stock kernel is 6.1.A.2.45 one, I'm not sure how it behaves on other builds.

Don't hesitate to give feedback here!

LeTama
 

Attachments

  • kf_v0.1.zip
    37.8 KB · Views: 236
Last edited:

ttiimm

Senior Member
Dec 23, 2011
197
62
wow, this is very very nice, now we can have the best of stock and cm9, thanks for all your hard work, im sure this is going to go far in the xperia s development community:D
 

mericon

Senior Member
Aug 18, 2011
348
359
Aachen
Thats Realschule great when You allow i will try to implement twrp 2 at an later Version just as an Experiment

Sent from my LT26i using xda premium
 

championswimmer

Inactive Recognized Developer
Oct 22, 2011
5,018
8,446
New Delhi
android.championswimmer.tk
ok so my two cents : -

1. we should NOT flash kernel every time we need to boot into other OS (too much flashing = bad blocks)
2. thus I suggest we need to maintain the same kernel tree for both stock and cm/aosp/aokp kernel. the zImage will be same, but ramdisk will be different ....
3. how will that help ? we will keep a minimalistic ramdisk (containing only bootmanager) on the original kernel.elf. the stock and aosp ramdisk can reside as stock_ramdisk.gz and aosp_ramdisk.gz either inside the ramdisk (if it has space) or inside /system/dual_boot/ and the required ramdisk will be inflated/deflated on the fly as per usage requires something like
Code:
 rm -f -r /sys
rm -f -r tmp 
rm -f -r etc
tar -xf ./stock_ramdisk.gz
for referrence see how CWM runs using chargemon script on locked bootloader
4. we will need our own custom CWM/whatever-recovery-we-want-to-use that shall allow us to flash system1 and system2, data1 and data2, like that....
5. for optimum results i want to suggest to use current system partition as system1 and current data partition as system2, both data partition can be kept as loop devices on the internal sdcard. that will be best for space as well as speed. using any other combination we will have to sacrifice either on speed or on space.


now these are my opinions, and I'll sit down an speak with OP after my exams are over on 17th Sept. I am very much interested on this idea, because it's a win-win situation. People get to use custom firmware alongside stock and devs get more users for their ROMs because there is no risk of non-working hardware as we always have stock on the other partition :)
 

letama

Senior Member
Feb 13, 2008
1,690
2,324
Thanks for your reply championswimmer.

I wasn't clear enough in my message I guess, so to clarify: I'm not flashing kernel each time I boot, the three kernels are flashed once and everything happens in memory. I'm using the whole 20 MB space to fit the three kernels, and my assembly loader jumps in memory to the desired kernel.

Your idea of having a single kernel for all is nice, but afaik, cm differs in kernel from stock, this is not a problem of ramdisk only.

Regarding partition scheme, well, I have no opinion yet, I'd prefer avoid loopbacks if I can repartition, but I'm not sure bootloader will let me do it. If repartition is possible, cwmod handling should be easy and only a matter of launching it while swapping on two recovery.fstab.
 

championswimmer

Inactive Recognized Developer
Oct 22, 2011
5,018
8,446
New Delhi
android.championswimmer.tk
Thanks for your reply championswimmer.

I wasn't clear enough in my message I guess, so to clarify: I'm not flashing kernel each time I boot, the three kernels are flashed once and everything happens in memory. I'm using the whole 20 MB space to fit the three kernels, and my assembly loader jumps in memory to the desired kernel.

Your idea of having a single kernel for all is nice, but afaik, cm differs in kernel from stock, this is not a problem of ramdisk only.

Regarding partition scheme, well, I have no opinion yet, I'd prefer avoid loopbacks if I can repartition, but I'm not sure bootloader will let me do it. If repartition is possible, cwmod handling should be easy and only a matter of launching it while swapping on two recovery.fstab.

Got it
Makes more sense :)

Great job

About repartition... We do have a lot of space in system to partiton into system1 and system2 say....
But splitting data is not good idea
Some people keep.big.games on data which need lot of space
Lets see what happens :)

Will check your current scheme tomorrow
Really like your memory base shifting concept... Pretty neat

Instead of 3 we can still make do with 2 kernels and 3 ramdisk.
We can keep the first kernel for both stock rom as well as the for.bootmanager :p

Sent from my LT26i using xda app-developers app
 

letama

Senior Member
Feb 13, 2008
1,690
2,324
Regarding repartition, my idea was to take space from internal storage, no from data and/or system. We'll see... I hope I won't fry my brand new toy :)

Regarding having two kernels, well, yes, it's possible, but it would mean that one of them is modified to support the driver I use. It would defeats the benefit of running any untouched kernels as it is now. My modified kernel is only 2MB, it's not such a big toll on the whole 20 MB.
 

electrash

Senior Member
Aug 31, 2011
1,837
526
Mali Lošinj - Rijeka
You could get in touch with FXP, doomlord, and binary... They are brains of xperia.

together you can make it more stable, improve it and make it amAzing ;)

Glad to hear this news, i would never sell my phone (AOSP, sony stock rom, cyanogenmod 10)

;)

Sent from my LT26i
 

Forzaferrarileo

Senior Member
Apr 16, 2012
424
434
Rome
All works fine , but a little question , can you share source to allow everyone to integrate the kernel that anyone want ( until dualboot compatible recovery will finished)

P.S. +1 for stylish purple led color :cool:
 
Last edited:

tooktang

Member
Jan 30, 2010
8
9
What a great job!

wowwwww!!!!!! just brilliant!!!!!!!!!!!!!
it looks like the magldr for hd2, which enables a multi-boot!~:good::good::good::good:
 

letama

Senior Member
Feb 13, 2008
1,690
2,324
All works fine , but a little question , can you share source to allow everyone to integrate the kernel that anyone want ( until dualboot compatible recovery will finished)

P.S. +1 for stylish purple led color :cool:

Sure, will do. I need to cleanup the mess a bit before, but it will come soon.

The purple led is from cm9 recovery, can't take credit for that :)
 

-Harsh-

Senior Member
Jul 16, 2012
929
1,094
Rajkot
Awesome work dude !! +1 for the effort :victory:
You guys make our phone more and more lovely !!:D
Keep up the great work !!

I hadn't but now unlocking my bootloader for this !!
As I am on stock .45 i will try experimenting this and give you the feedback :fingers-crossed:
 

JoelChrist_

Senior Member
Jun 18, 2012
188
7
Nijmegen
isn't it a bad idea to keep the data partition the same for both say cm and stock, i had conflicts with cm without wiping data?

Sent with my Sony Xperia S using a little bit of KA magic.
 

letama

Senior Member
Feb 13, 2008
1,690
2,324
Nice work. Maybe we should use LVM for partitions? It doesn't seem like the bootloader will let us write a new partition table.

Well, I just tested repartitionning, it's possible:


Code:
~ # cat /proc/partitions
major minor  #blocks  name

 179        0   31162368 mmcblk0
 179        1       2048 mmcblk0p1
 179        2        512 mmcblk0p2
 179        3      20480 mmcblk0p3
 179        4          1 mmcblk0p4
 179        5        512 mmcblk0p5
 179        6       3072 mmcblk0p6
 179        7       3072 mmcblk0p7
 179        8       3072 mmcblk0p8
 179        9       5120 mmcblk0p9
 179       10       8192 mmcblk0p10
 179       11      16384 mmcblk0p11
 179       12    1048576 mmcblk0p12
 179       13     256000 mmcblk0p13
 179       14    2097152 mmcblk0p14
 179       15   25272312 mmcblk0p15
 179       16     512024 mmcblk0p16
 179       17     256024 mmcblk0p17
 179       18    1023928 mmcblk0p18

Now, is it reasonable to release how, that's another debate :) I'm not sure yet... There is definitely a risk of permanent brick with this.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 30
    Hello Guys,

    Here is my last toy, it's a dual boot system for the xperia S:


    It lets you start two different kernels with their associated cpio with a third kernel that handles the boot menu and embeds cwm. It works with any kernel, this is not kexec based. As a demo in the video, I have stock firmware on regular partitions on one and cm9 on the other one with loopbacks on internal storage. I'll experiment later on with partitioning to see if we could have two sets of native partitions to make it more comfortable.

    As it it's, it's quite rough, but if anyone has interest in it I will release it as it is and try to improve usability.

    This is for devs and advanced users only, you would have to fiddle a lot to get the second build to run, you need an arm toolchain to embed both kernels and you have to modify its cpio.

    I'm working on tools to flash kernels directly on device, but they're not ready yet. And ideally, CWM would need to be extended to support two environments. Don't expect quick progress, I don't have much free time to work on this.

    Here are some details on how it works:

    1. I trimmed down a stock kernel to remove some fat and add a driver to set a specific memory location.
    2. I embed a small assembly loader with this kernel and its cpio plus the other 2.
    3. The tiny kernel is loaded first, it displays the menu and eventually starts cwm. The menu will set the memory location with the kernel choice, then reboot.
    4. At next reboot, the assembly loader will detect the kernel choice and start the appropriate kernel.

    So, in fact, you're booting two times, first the small loader, then the real boot.

    It adds some boot time, but it's not dramatic. The advantage is that it's easy to build the loader, it's a simple init. Second advantage, the second kernel is running on a "fresh" start, no left-over in memory, no kexec patch to apply, it works with any kernel. Last, cwm can be embedded with the tiny kernel, so it's finally independent from the build kernel.

    First a disclaimer: I'm not responsible if you fry your phone using this, it's very experimental and I'm not 100% sure running a build on loopback won't reduce internal flash lifetime. I don't expect problem, but proceed with caution!

    * Updates *

    2012-09-07: Trimmed kernel uploaded to gitorious here , branch bootloader_kernel, boot menu (FBMenu, thanks to openAOS for initial release!) source added here.

    2012-09-06, more details here :

    1) on-device kernel flasher attached (kf_v0.1.zip). It let you flash kernel 1 or kernel 2 directly from device (adb from recovery for instance). You must have previously flashed dual.elf in fastboot!

    And again, all of this is highly experimental! Be careful.


    syntax:

    kf [1|2] kernel_zimage_file cpio_file

    Source code at: https://gitorious.org/sony-tools/dual_loader_kf

    2) Loader source code uploaded to: https://gitorious.org/sony-tools/sony-tools, in dual directory.

    2012-09-04:

    If you have a 6.1.A.2.45 stock firmware, you can try the setup displayed in the video:

    1. Download package here (mirror) and extract it on your PC.
    2. Copy the 3 ext4 files at the root of the phone internal storage.
    3. Reboot in fastboot mode
    4. Flash dual.elf in fastboot mode with "fastboot flash boot dual.elf".
    5. Reboot with "fastboot reboot"

    You should now have the boot menu at each phone start. If you want to get rid of it, just reflash your original firmware kernel.

    Note:
    - I'm not sure cwm is working completely properly, I barely tested it.
    - it may work with another stock firmware version, but the embedded stock kernel is 6.1.A.2.45 one, I'm not sure how it behaves on other builds.

    Don't hesitate to give feedback here!

    LeTama
    2
    Will donation makes thing faster? ;)

    :)

    No, not really, killing my boss and my wife would be far more efficient!

    More seriously, I made some progress this weekend, I now have cwmod working for both kernels and I was a bit busy preparing few roms and documentation to show how to adapt a rom.

    I should release everything soon, probably in a new thread as I forgot to reserve few posts on this one.
    2
    This is not strictly the right way, but it will do ok:

    Code:
    dd if=/dev/zero of=data_cm9.ext4 bs=1024 count=512000
    mkfs.ext4 data_cm9.ext4

    Say y when mkfs.ext4 prompts for confirmation. Change count (512M here) to the size you want, that's how I did for my release.

    But to to do it really properly, there are some options to set, and ext4 shouldn't fill completely the image file. Archos does it this way:

    mkfs.ext4 -v -b 4096 data_cm9.ext4 (512000 / 4 - 4)

    (you have to compute the value, not use the expression like this)

    then

    tune2fs -c -1 -i 0 -m 1 data_cm9.ext4

    I didn't check how it's configured on Sony ext4 yet. The 4 blocks at the end are certainly there though.
    1
    All work's fine but can any one tell me complete path of internal storage ;)

    where can i paste that 3 files :)

    help ....:D

    root of internal storage = main folder , so put the files into internal storage (it's recognized by the phone as sdcard)
    1
    All work's fine but can any one tell me complete path of internal storage ;)
    where can i paste that 3 files :)

    You mean with adb ?

    you can do:

    adb push system_cm9.ext4 /mnt/sdcard/
    adb push data_cm9.ext4 /mnt/sdcard/
    adb push cache_cm9.ext4 /mnt/sdcard/

    Or if you have mtp working, just open phone icon, then "Internal Storage" on your PC and copy files there.