Firefly Open Source Community

   Login   |   Register   |
New_Topic
Print Previous Topic Next Topic

Dual boot on Firefly-RK3288

10

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
10

Dual boot on Firefly-RK3288

Posted at 1/10/2015 14:02:54      View:10227 | Replies:4        Print      Only Author   [Copy Link] 1#

Brief introduction

As we all know the Firefly-RK3288 supported by Ubuntu and Android. So it’s excellent to realize the dual boot on Firefly.

Now let’s take a look at the dual boot on Firefly-RK3288.


Recovery mode

There is a recovery mode on Android. It runs independent image including the kernel and initramfs in recovery partitionThis partition is the best place for Linux.


Partition

Let’s take a look at the partition on Android. You can get the information by CMDLINE in parameter file.

  1. FIRMWARE_VER:4.4.2
  2. MACHINE_MODEL:rk30sdk
  3. MACHINE_ID:007
  4. MANUFACTURER:RK30SDK
  5. MAGIC: 0x5041524B
  6. ATAG: 0x60000800
  7. MACHINE: 3066
  8. CHECK_MASK: 0x80
  9. PWR_HLD: 0,0,A,0,1
  10. #KERNEL_IMG: 0x62008000
  11. #FDT_NAME: rk-kernel.dtb
  12. #RECOVER_KEY: 1,1,0,20,0
  13. CMDLINE:console=ttyFIQ0 androidboot.hardware=rk30board androidboot.console=ttyFIQ0 board.ap_has_alsa=0 init=/init initrd=0x62000000,0x00800000 mtdparts=rk29xxnand:0x00002000@0x00002000(uboot),0x00002000@0x00004000(misc),0x00008000@0x00006000(resource),0x00008000@0x0000e000(kernel),0x00010000@0x00016000(boot),0x00010000@0x00026000(recovery),0x0001a000@0x00036000(backup),0x00040000@0x00050000(cache),0x00002000@0x00090000(kpanic),0x00180000@0x00092000(system),0x00002000@0x00212000(metadata),0x00200000@0x00214000(userdata),0x00020000@0x00414000(radical_update),-@0x00434000(user)
Copy the code

The CMDLINE will be sent to kernel. The “mtdparts” indicates the partition, the format shows as the follow.

  1. 0x00002000@0x00002000(uboot)
  2.   Size                offset        partition name
  3. The unit is 512 bytes (i.e. traditional disk sector size).
Copy the code

The partition information above turn into a table shows as below

Size(Byte)

Partition name

4M

uboot

4M

misc

16M

resource

16M

kernel

32M

boot

32M

recovery

52M

backup

128M

cache

4M

kpanic

768M

system

4M

metadata

1G

userdata

64M

radical_update

Full size-2152M

user


  • Uboot: this is used to store the stage two of u-boot. The Firefly-RK3288 uses the eMMC instead the flash, so u-boot needn’t to be divided into two stage. That explains why the uboot partition is not used on Firefly.
  • Misc: This partition is used to control the boot mode. The following will introduce about this.
  • Resource: store the boot pictures and the information about Device Tree.
  • Kernel: storage for kernel.
  • Boot: storage for initramfs of normal boot. Note that, while OTA upgrade, both  boot partition and recovery partition store the initramfs, the kernel partition doesn’t work at this moment.
  • Recovery: storage for kernel and initramfs which enter recovery mode needs.
  • Backup: It’s designed by Rockchip and used for backup image storage. However, it’s useless for Firefly-RK3288.
  • Cache: cache partition for Android.
  • Kpanic: the kernel panic for Android.
  • System: the system partition for Android.(mount point is  /system)
  • Metadata: metadata partition of Rockchip. Unknown function.
  • Userdata: data partition of Android(mount point is /data)
  • Radical_update: the update partition of Rockchip. Unknown function.
  • User: internal storage partition(mount point is /mnt/sdcard)

In order to boot Linux from Android, we need to add a “linuxroot” partition to store root file system of Linux. We choose to replace the radical_update partition and give 3G for this partition so as to be compatible.

1G

userdata

3136M

linuxroot

Full size-5224M

user



Modify the parameter file and set the CMDLINE as below.

  1. CMDLINE:console=ttyFIQ0 androidboot.hardware=rk30board androidboot.console=ttyFIQ0 board.ap_has_alsa=0 root=/dev/block/mtd/by-name/linuxroot rw rootfstype=ext4 init=/sbin/init initrd=0x62000000,0x00800000 mtdparts=rk29xxnand:0x00002000@0x00002000(uboot),0x00002000@0x00004000(misc),0x00008000@0x00006000(resource),0x00008000@0x0000e000(kernel),0x00010000@0x00016000(boot),0x00010000@0x00026000(recovery),0x0001a000@0x00036000(backup),0x00040000@0x00050000(cache),0x00002000@0x00090000(kpanic),0x00180000@0x00092000(system),0x00002000@0x00212000(metadata),0x00200000@0x00214000(userdata),0x00620000@0x00414000(linuxroot),-@0x00a34000(user)
Copy the code

How to boot Linux.

Then, we will talk about how to boot Linux. Due to the Linux is stored in recovery disk, so boot Linux equal to enter the recovery mode. Here are some ways to get to this point.

1. Unplug USB cable, press the revocery key on Firefly and turn on it.(no mater first power on, reboot or press the reset key). This way is temporary switch. If you don’t press the recovery key next time will not reach to the recovery mode(boot Linux).

2. Restore the factory setting in the Android setting. Actrually, restore factory setting function has been remove from Android. If hasn’t been remove, this may help you boot Linux.

3. Firelfy-RK3288 add an switch system option at the shutdown menu(click the shutdown button at the bottom of the screen) for Android.

4. Flash the rkst/Image/misc.img of SDK to misc partition.


Step 2 to 4 are switch to recovery mode through write misc partition. This is a way to boot Linux for Android.

You can check the content of misc.img using hexdump command.

  1. $ hexdump -C rkst/Image/misc.img
  2. 00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
  3. *
  4. 00004000  62 6f 6f 74 2d 72 65 63  6f 76 65 72 79 00 00 00  |boot-recovery...|
  5. 00004010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
  6. *
  7. 00004040  72 65 63 6f 76 65 72 79  0a 2d 2d 77 69 70 65 5f  |recovery.--wipe_|
  8. 00004050  61 6c 6c 00 00 00 00 00  00 00 00 00 00 00 00 00  |all.............|
  9. 00004060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
  10. *
  11. 0000c000
Copy the code

From the massage above, you can see the first 16K(0x4000)Byte are 0, and are followed by a “boot-recovery”, “recovery”and “--wipe_all” command.

Boot bootloader(means  u-boot) will read the content from this partition. If boot the “boot-recovery”,that will load the recovery partition.


First boot
Although remove the restore factory setting function from Android, the initial setting still necessary.
We add a symbol file “/firstboot”to Linux root file system. Once detect this file is exist while boot the Linux,the system will take this boot as the first boot and will do the follow initial setting.

  • Expand the root file system using resize2fs and fix size of the file system.
  • Format the userdata partition
  • Format the cache partition
  • Format the metadata partition
  • Format the user partition
  • Delet the symble file “/firstboot”
  • Back to the Android system.

See “etc/rc.local”for More realization details.

  1. /usr/local/bin/mtd-by-name.sh

  2. if [ -e /firstboot ]; then
  3.     echo "======Expanding the rootfs..."
  4.     resize2fs /dev/block/mtd/by-name/linuxroot
  5.     if [ -e /dev/block/mtd/by-name/userdata ]; then
  6.         echo "=======Formatting userdata(/data)..."
  7.         mkfs.ext4 /dev/block/mtd/by-name/userdata

  8.         echo "=======Formatting metadata(/metadata)..."
  9.         mkfs.ext4 /dev/block/mtd/by-name/metadata

  10.         echo "=======Formatting cache(/cache)..."
  11.         mkfs.ext4 /dev/block/mtd/by-name/cache

  12.         echo "=======Formatting user(/sdcard)..."
  13.         mkfs.vfat /dev/block/mtd/by-name/user

  14.         # reboot to android
  15.         dd if=/dev/zero of=/dev/block/mtd/by-name/misc bs=16k count=3
  16.         rm -f /firstboot
  17.         sync
  18.         reboot
  19.     fi
  20.     rm -f /firstboot
  21. fi
Copy the code

How to switch Linux from Android
Write a script to format the misc partition and reboot. Then you can switch back to Linux.

  1. sudo dd if=/dev/zero of=/dev/block/mtd/by-name/misc bs=16k count=3
  2. sudo reboot
Copy the code
The script is /usr/local/bin/b2android.sh.

Reply

Use props Report

46

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
46
Posted at 1/10/2015 16:59:00        Only Author  2#

Yeah!!!?

This is a great 3ad!!! Thanks a lot for these details. I think that now I can grab some info about how to manage the parameter file!! And this is what i was searching for!!

Thanks a lot Andy!





Reply

Use props Report

240

Credits

0

Prestige

0

Contribution

intermediate

Rank: 3Rank: 3

Credits
240
Posted at 1/16/2015 01:57:20        Only Author  3#
Andy, again you have answered many of my questions, other than the "dual Boot".  Thanks for the tutorial on the parameter.
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