Firefly Open Source Community

   Login   |   Register   |
New_Topic
Print Previous Topic Next Topic

New Boot Partition for Dual-Boot

543

Credits

19

Prestige

15

Contribution

advanced

Rank: 4

Credits
543

New Boot Partition for Dual-Boot

Posted at 3/5/2016 11:17:30      View:4528 | Replies:3        Print      Only Author   [Copy Link] 1#
Android support the following boot modes:
1. reboot loader
2. reboot recovery

It means that we can also switch the system when dual booting in a diffent way.
Ubuntu booting can be installed in a new independent partition named ramfs instead of the Recovery partition.
So here I describe how to add ramfs boot mode for Ubuntu.

Please add all the patches manually as the locations will differ in every SDK.

Adding the boot mode
Linux kernel patch
  1. diff --git a/arch/arm/mach-rockchip/common.c b/arch/arm/mach-rockchip/common.c
  2. index 510e4da..e91fa64 100755
  3. --- a/arch/arm/mach-rockchip/common.c
  4. +++ b/arch/arm/mach-rockchip/common.c
  5. @@ -264,6 +264,9 @@ void rockchip_restart_get_boot_mode(const char *cmd, u32 *flag, u32 *mode)
  6.                 else if (!strcmp(cmd, "charge")) {
  7.                         *flag = SYS_LOADER_REBOOT_FLAG + BOOT_CHARGING;
  8.                         *mode = BOOT_MODE_CHARGE;
  9. +               }else if(!strcmp(cmd, "ramfs")){
  10. +                       *flag = SYS_LOADER_REBOOT_FLAG + BOOT_RAMFS;
  11. +                       *mode = BOOT_MODE_RAMFS;
  12.                 }
  13.         } else {
  14.                 if (is_panic)
  15. diff --git a/arch/arm/mach-rockchip/loader.h b/arch/arm/mach-rockchip/loader.h
  16. index bf2cd47..819e277 100644
  17. --- a/arch/arm/mach-rockchip/loader.h
  18. +++ b/arch/arm/mach-rockchip/loader.h
  19. @@ -17,6 +17,7 @@ enum {
  20.      BOOT_FASTBOOT,   /* enter fast boot mode */
  21.      BOOT_SECUREBOOT_DISABLE,
  22.      BOOT_CHARGING,   /* enter charge mode */
  23. +    BOOT_RAMFS,
  24.      BOOT_MAX         /* MAX VALID BOOT TYPE.*/
  25. };

  26. diff --git a/include/linux/rockchip/common.h b/include/linux/rockchip/common.h
  27. index 006d52d..0a10625 100644
  28. --- a/include/linux/rockchip/common.h
  29. +++ b/include/linux/rockchip/common.h
  30. @@ -52,6 +52,7 @@ int rockchip_cpu_disable(unsigned int cpu);
  31. #define BOOT_MODE_PANIC                        7
  32. #define BOOT_MODE_WATCHDOG             8
  33. #define BOOT_MODE_TSADC                        9
  34. +#define BOOT_MODE_RAMFS                      10

  35. int rockchip_boot_mode(void);
  36. void __init rockchip_boot_mode_init(u32 flag, u32 mode);
  37. diff --git a/include/uapi/linux/reboot.h b/include/uapi/linux/reboot.h
  38. index 09d056d..28e4c51 100644
  39. --- a/include/uapi/linux/reboot.h
  40. +++ b/include/uapi/linux/reboot.h
  41. @@ -33,6 +33,7 @@
  42. #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
  43. #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
  44. #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
  45. +#define        LINUX_REBOOT_CMD_RESTART_RAMFS  0xEEEEEEEE

  46. diff --git a/kernel/sys.c b/kernel/sys.c
  47. index b1a203d..3147ab5 100644
  48. --- a/kernel/sys.c
  49. +++ b/kernel/sys.c
  50. @@ -505,6 +505,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,

  51.         mutex_lock(&reboot_mutex);
  52.         switch (cmd) {
  53. +       case LINUX_REBOOT_CMD_RESTART_RAMFS:
  54. +               kernel_restart("ramfs");
  55.         case LINUX_REBOOT_CMD_RESTART:
  56.                 kernel_restart(NULL);
  57.                 break;
Copy the code
U-Boot patch
  1. diff --git a/board/rockchip/common/config.h b/board/rockchip/common/config.h
  2. index 37d287a..9347fe0 100755
  3. --- a/board/rockchip/common/config.h
  4. +++ b/board/rockchip/common/config.h
  5. @@ -188,6 +188,7 @@ enum {
  6.         BOOT_FASTBOOT,   
  7.         BOOT_SECUREBOOT_DISABLE,
  8.         BOOT_CHARGING,
  9. +       BOOT_RAMFS,
  10.         BOOT_MAX         /* MAX VALID BOOT TYPE.*/
  11. };

  12. diff --git a/board/rockchip/common/rkboot/fastboot.c b/board/rockchip/common/rkboot/fastboot.c
  13. index 4bb8c28..c3f47f0 100755
  14. --- a/board/rockchip/common/rkboot/fastboot.c
  15. +++ b/board/rockchip/common/rkboot/fastboot.c
  16. @@ -120,6 +120,10 @@ enum fbt_reboot_type board_fbt_get_reboot_type(void)
  17.                         case BOOT_CHARGING:
  18.                                 frt = FASTBOOT_REBOOT_CHARGE;
  19.                                 break;
  20. +                       case BOOT_RAMFS:
  21. +                               frt = FASTBOOT_REBOOT_RAMFS;
  22. +                               break;
  23. +
  24.                         default:
  25.                                 printf("unsupport rk boot type %d\n", reboot_mode);
  26.                                 break;
  27. @@ -479,6 +483,12 @@ void board_fbt_preboot(void)
  28.                 board_fbt_request_start_fastboot();
  29.         }
  30. #endif
  31. +       else if (frt == FASTBOOT_REBOOT_RAMFS) {
  32. +               #ifdef CONFIG_CMD_BOOTRK
  33. +               char *const boot_cmd[] = {"bootrk", "ramfs"};
  34. +               do_bootrk(NULL, 0, ARRAY_SIZE(boot_cmd), boot_cmd);
  35. +               #endif
  36. +       }
  37.         else {
  38.                 FBTDBG("\n%s: check misc command.\n", __func__);
  39.                 /* unknown reboot cause (typically because of a cold boot).
  40. diff --git a/include/fastboot.h b/include/fastboot.h
  41. index 7b8508b..d6b8f1f 100755
  42. --- a/include/fastboot.h
  43. +++ b/include/fastboot.h
  44. @@ -238,6 +238,7 @@ enum fbt_reboot_type {
  45.         FASTBOOT_REBOOT_RECOVERY_WIPE_DATA,     /* recovery and wipe data */
  46.         FASTBOOT_REBOOT_FASTBOOT,               /* android fastboot */
  47.         FASTBOOT_REBOOT_CHARGE,                 /* charge */
  48. +       FASTBOOT_REBOOT_RAMFS,
  49. };
Copy the code
Adding the new boot partition

  1. diff --git a/board/rockchip/common/rkboot/fastboot.c b/board/rockchip/common/rkboot/
  2. index f77fa2c..39e4b69 100755
  3. --- a/board/rockchip/common/rkboot/fastboot.c
  4. +++ b/board/rockchip/common/rkboot/fastboot.c
  5. @@ -218,6 +218,10 @@ void board_fbt_boot_failed(const char* boot)
  6.                 printf("try to start backup\n");
  7.                 char *const boot_cmd[] = {"bootrk", BACKUP_NAME};
  8.                 do_bootrk(NULL, 0, ARRAY_SIZE(boot_cmd), boot_cmd);
  9. +       } else if (!memcmp(BACKUP_NAME, boot, sizeof(BACKUP_NAME))) {
  10. +               printf("try to start ramfs\n");
  11. +               char *const boot_cmd[] = {"bootrk", RAMFS_NAME};
  12. +               do_bootrk(NULL, 0, ARRAY_SIZE(boot_cmd), boot_cmd);
  13.         }
  14. #endif
  15.         printf("try to start rockusb\n");
  16. diff --git a/board/rockchip/common/rkloader/rkimage.h b/board/rockchip/common/rkload
  17. index 812055f..a2d2855 100755
  18. --- a/board/rockchip/common/rkloader/rkimage.h
  19. +++ b/board/rockchip/common/rkloader/rkimage.h
  20. @@ -144,6 +144,7 @@ typedef struct tag_second_loader_hdr
  21. #define RESOURCE_NAME   "resource"
  22. #define LOGO_NAME       "logo"
  23. #define FACTORY_NAME    "factory"
  24. +#define RAMFS_NAME      "ramfs"


  25. int rkimage_load_image(rk_boot_img_hdr *hdr, const disk_partition_t *boot_ptn, \
Copy the code
Then also add the ramfs partition to your partition file
Please use your own partition file, this is just an example
  1. CMDLINE: console=ttyS2 root=LABEL=linuxroot rw rootfstype=ext4 init=/sbin/init mtdparts=rk29xxnand:0x00002000@0x00002000(uboot),0x00002000@0x00004000(trust),0x00008000@0x00006000(resource),0x00010000@0x0000E000(ramfs),-@0x0001E000(linuxroot)
Copy the code

Now you can flash the linux-boot.img image to ramfs partition instead of Recovery partition and still keep the Android Recovery or flash TWRP Recovery to it while still dual-booting
Will also need to add ramfs partition info to the first screen of AndroidTool v2.35

I hope Firefly Team will implement this into their next dual-boot firmware to have an extra partition for dual-booting.


Reply

Use props Report

403

Credits

10

Prestige

12

Contribution

intermediate

Rank: 3Rank: 3

Credits
403
Posted at 3/7/2016 14:58:57        Only Author  2#
Wow, that's a triple booting

We currently have a solution of extracting Android recovery image flashed in "backup" partition and booting it, when the Linux initrd in "recovery" partition checks that no special flag is resident in "misc" partition.

Your solution is more complete. We'll evaluate it.
Reply

Use props Report

403

Credits

10

Prestige

12

Contribution

intermediate

Rank: 3Rank: 3

Credits
403
Posted at 3/7/2016 15:02:56        Only Author  3#
And what're the commands of switch OS between Android and Linux?
Reply

Use props Report

543

Credits

19

Prestige

15

Contribution

advanced

Rank: 4

Credits
543
Posted at 3/8/2016 01:40:47        Only Author  4#
Last edited by dewet In 3/8/2016 01:43 Editor
busybee Posted at 3/7/2016 15:02
And what're the commands of switch OS between Android and Linux?

From Android - reboot ramfs
From Linux - reboot android
No special scripts are needed to change misc.img to boot to another partition.
As easy as that.
Can also put into a script if needed then it will look like eg. reboot.sh script for Android:

#!/bin/sh

Reboot --ramfs $@

Then something like that can also be put on Firefly power menu to boot to Linux.
If turned off from Linux and device turned on again will automatically boot to Android again since misc.img is empty. But can change the misc.img also if needed to have extra string instead of 'recovery' maybe then 'ramfs' or something so it automatically boots to Linux like Firefly is currently doing to make it permanent if needed.

When Marshmallow firmware is released for Firefly then people can also install TWRP recovery and flash Xposed framework that don't currently work on Lollipop firmware then 2 partitions - recovery, and ramfs will be needed for users.
Reply

Use props Report

You need to log in before you can reply Login | Register

This forum Credits Rules

Quick Reply Back to top Back to list