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. - FIRMWARE_VER:4.4.2
- MACHINE_MODEL:rk30sdk
- MACHINE_ID:007
- MANUFACTURER:RK30SDK
- MAGIC: 0x5041524B
- ATAG: 0x60000800
- MACHINE: 3066
- CHECK_MASK: 0x80
- PWR_HLD: 0,0,A,0,1
- #KERNEL_IMG: 0x62008000
- #FDT_NAME: rk-kernel.dtb
- #RECOVER_KEY: 1,1,0,20,0
- 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.
- 0x00002000@0x00002000(uboot)
- Size offset partition name
- 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
- 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.
Modify the parameter file and set the CMDLINE as below. - 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. - $ hexdump -C rkst/Image/misc.img
- 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
- *
- 00004000 62 6f 6f 74 2d 72 65 63 6f 76 65 72 79 00 00 00 |boot-recovery...|
- 00004010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
- *
- 00004040 72 65 63 6f 76 65 72 79 0a 2d 2d 77 69 70 65 5f |recovery.--wipe_|
- 00004050 61 6c 6c 00 00 00 00 00 00 00 00 00 00 00 00 00 |all.............|
- 00004060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
- *
- 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. - /usr/local/bin/mtd-by-name.sh
-
- if [ -e /firstboot ]; then
- echo "======Expanding the rootfs..."
- resize2fs /dev/block/mtd/by-name/linuxroot
- if [ -e /dev/block/mtd/by-name/userdata ]; then
- echo "=======Formatting userdata(/data)..."
- mkfs.ext4 /dev/block/mtd/by-name/userdata
-
- echo "=======Formatting metadata(/metadata)..."
- mkfs.ext4 /dev/block/mtd/by-name/metadata
-
- echo "=======Formatting cache(/cache)..."
- mkfs.ext4 /dev/block/mtd/by-name/cache
-
- echo "=======Formatting user(/sdcard)..."
- mkfs.vfat /dev/block/mtd/by-name/user
-
- # reboot to android
- dd if=/dev/zero of=/dev/block/mtd/by-name/misc bs=16k count=3
- rm -f /firstboot
- sync
- reboot
- fi
- rm -f /firstboot
- 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.
- sudo dd if=/dev/zero of=/dev/block/mtd/by-name/misc bs=16k count=3
- sudo reboot
Copy the code The script is /usr/local/bin/b2android.sh.
|