Skip to content

Commit 5887eab

Browse files
committed
recovery: add truedualboot support
Change-Id: I80501250ee23146f57009d7968eb65b73e1fceaf
1 parent 918154f commit 5887eab

7 files changed

+316
-3
lines changed

BoardConfig.mk

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ TARGET_USES_SF_BYPASS := true
8989
TARGET_USES_C2D_COMPOSITION := true
9090

9191
BOARD_NATIVE_DUALBOOT := true
92+
BOARD_NATIVE_DUALBOOT_SINGLEDATA := true
9293
TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888"
9394
TARGET_RECOVERY_UI_LIB := librecovery_ui_aries
9495
BOARD_USE_CUSTOM_RECOVERY_FONT := \"roboto_15x24.h\"

device.mk

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ PRODUCT_PACKAGES += \
4242
VisualizationWallpapers \
4343
librs_jni
4444

45+
# Dualboot
46+
PRODUCT_COPY_FILES += \
47+
device/xiaomi/aries/recovery/mount_ext4_default.sh:recovery/root/res/dualboot/mount_ext4_default.sh \
48+
device/xiaomi/aries/recovery/mount_ext4_tdb.sh:recovery/root/res/dualboot/mount_ext4_tdb.sh
49+
4550
PRODUCT_COPY_FILES += \
4651
device/xiaomi/aries/WCNSS_cfg.dat:system/vendor/firmware/wlan/prima/WCNSS_cfg.dat \
4752
device/xiaomi/aries/WCNSS_qcom_cfg.ini:system/etc/wifi/WCNSS_qcom_cfg.ini \

recovery/dualboot.c

+44-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
#include "common.h"
77
#include "recovery_ui.h"
88
#include "mounts.h"
9+
#include "roots.h"
910

1011
extern int ui_menu_level;
1112
extern int ui_root_menu;
1213
static enum dualboot_system selected_system = INVALID_SYSTEM;
14+
static int force_raw_format = 0;
1315

1416
struct partition {
1517
char path[PATH_MAX];
@@ -28,7 +30,7 @@ enum dualboot_system get_selected_system(void) {
2830
}
2931

3032
static int select_system(const char* title) {
31-
char* headers[] = { title, "", NULL };
33+
const char* headers[] = { title, "", NULL };
3234
char* items[] = { "System1", "System2", NULL };
3335
enum dualboot_system chosen_item = -1;
3436

@@ -85,13 +87,13 @@ static int replace_device_node(int num, struct stat* statbuf) {
8587
MountedVolume * mv = find_mounted_volume_by_real_node(part_table[num].path);
8688

8789
if(mv!=NULL && unmount_mounted_volume(mv)!=0) {
88-
LOGE("replace_device_node: could not unmount device!\n");
90+
LOGE("could not unmount device!\n");
8991
return -1;
9092
}
9193

9294
unlink(part_table[num].path);
9395
if(mknod(part_table[num].path, statbuf->st_mode, statbuf->st_rdev)!=0) {
94-
LOGE("replace_device_node: could not create node!\n");
96+
LOGE("could not create node!\n");
9597
return -1;
9698
}
9799

@@ -152,3 +154,42 @@ void dualboot_set_system(enum dualboot_system sys) {
152154
selected_system = sys;
153155
dualboot_setup_env();
154156
}
157+
158+
static int dualboot_mount_dataroot(void) {
159+
int rc = ensure_path_mounted_at_mount_point("/data", MOUNTPOINT_DATAROOT);
160+
if(rc)
161+
LOGE("failed mounting dataroot!\n");
162+
return rc;
163+
}
164+
165+
int dualboot_is_tdb_enabled(void) {
166+
struct stat st;
167+
168+
if(dualboot_mount_dataroot())
169+
return 0;
170+
171+
return lstat(TDB_FILE, &st)==0;
172+
}
173+
174+
void dualboot_set_tdb_enabled(int enable) {
175+
if(dualboot_mount_dataroot())
176+
return;
177+
178+
if(enable) {
179+
FILE * pFile = fopen(TDB_FILE, "w");
180+
if(pFile==NULL) {
181+
LOGE("TrueDualBoot: failed creating file");
182+
return;
183+
}
184+
fclose(pFile);
185+
}
186+
else remove(TDB_FILE);
187+
}
188+
189+
int is_force_raw_format_enabled(void) {
190+
return !!force_raw_format;
191+
}
192+
193+
void set_force_raw_format_enabled(int enabled) {
194+
force_raw_format = enabled;
195+
}

recovery/dualboot.h

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#define MOUNTPOINT_DATAROOT "/data_root"
2+
#define TDB_FILE MOUNTPOINT_DATAROOT "/.truedualboot"
3+
#define PATH_USERDATA_NODE "/dev/block/mmcblk0p26"
4+
#define PATH_USERDATA_NODE_BACKUP "/dev/part_backup_userdata"
5+
16
enum dualboot_system {
27
INVALID_SYSTEM = -1,
38
SYSTEM1,
@@ -9,3 +14,8 @@ void dualboot_show_selection_ui(void);
914
enum dualboot_system get_selected_system(void);
1015
void dualboot_setup_env(void);
1116
void dualboot_set_system(enum dualboot_system sys);
17+
18+
void dualboot_set_tdb_enabled(int enable);
19+
int dualboot_is_tdb_enabled(void);
20+
int is_force_raw_format_enabled(void);
21+
void set_force_raw_format_enabled(int enabled);

recovery/mount_ext4_default.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/system/bin/sh
2+
export PATH=/system/bin:/system/xbin:$PATH
3+
BLOCK_DEVICE=$1
4+
MOUNT_POINT=$2
5+
LOG_FILE="/dev/null"
6+
LOG_LOCATION="/data/.fsck_log/"
7+
8+
# storage log
9+
if [ "${MOUNT_POINT}" == "/storage_int" ]; then
10+
mkdir ${LOG_LOCATION}
11+
busybox find /data/.fsck_log/ -type f -mtime +7 -exec rm {} \;
12+
TIMESTAMP=`date +%F_%H-%M-%S`
13+
LOG_FILE=${LOG_LOCATION}/storage_${TIMESTAMP}.log
14+
fi
15+
16+
# mount partition
17+
if [ -e ${BLOCK_DEVICE} ]; then
18+
mount -t ext4 -o nosuid,nodev,barrier=1,noauto_da_alloc ${BLOCK_DEVICE} ${MOUNT_POINT}
19+
fi
20+
21+
# hide recovery partition
22+
RECOVERY_NODE="$(busybox readlink -f /dev/block/platform/msm_sdcc.1/by-name/recovery)"
23+
busybox mv "${RECOVERY_NODE}" /dev/recovery_moved
24+
busybox mknod -m 0600 "${RECOVERY_NODE}" b 1 3

recovery/mount_ext4_tdb.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/system/bin/sh
2+
export PATH=/system/bin:/system/xbin:$PATH
3+
BLOCK_DEVICE=$1
4+
MOUNT_POINT=$2
5+
LOG_FILE="/dev/null"
6+
LOG_LOCATION="/data/.fsck_log/"
7+
8+
# get syspart-flag from cmdline
9+
set -- $(cat /proc/cmdline)
10+
for x in "$@"; do
11+
case "$x" in
12+
syspart=*)
13+
SYSPART=$(echo "${x#syspart=}")
14+
;;
15+
esac
16+
done
17+
18+
# storage log
19+
if [ "${MOUNT_POINT}" == "/storage_int" ]; then
20+
mkdir ${LOG_LOCATION}
21+
busybox find /data/.fsck_log/ -type f -mtime +7 -exec rm {} \;
22+
TIMESTAMP=`date +%F_%H-%M-%S`
23+
LOG_FILE=${LOG_LOCATION}/storage_${TIMESTAMP}.log
24+
fi
25+
26+
# mount partition
27+
if [ -e ${BLOCK_DEVICE} ]; then
28+
# userdata
29+
if [ "${BLOCK_DEVICE}" == "/dev/block/platform/msm_sdcc.1/by-name/userdata" ];then
30+
if [ "${SYSPART}" == "system" ];then
31+
BINDMOUNT_PATH="/data_root/system0"
32+
elif [ "${SYSPART}" == "system1" ];then
33+
BINDMOUNT_PATH="/data_root/system1"
34+
else
35+
reboot recovery
36+
fi
37+
38+
# mount /data_root
39+
mkdir -p /data_root
40+
chmod 0755 /data_root
41+
mount -t ext4 -o nosuid,nodev,barrier=1,noauto_da_alloc ${BLOCK_DEVICE} /data_root
42+
43+
# bind mount
44+
mkdir -p ${BINDMOUNT_PATH}
45+
chmod 0755 ${BINDMOUNT_PATH}
46+
mount -o bind ${BINDMOUNT_PATH} ${MOUNT_POINT}
47+
48+
# normal mount
49+
else
50+
mount -t ext4 -o nosuid,nodev,barrier=1,noauto_da_alloc ${BLOCK_DEVICE} ${MOUNT_POINT}
51+
fi
52+
fi
53+
54+
# hide recovery partition
55+
RECOVERY_NODE="$(busybox readlink -f /dev/block/platform/msm_sdcc.1/by-name/recovery)"
56+
busybox mv "${RECOVERY_NODE}" /dev/recovery_moved
57+
busybox mknod -m 0600 "${RECOVERY_NODE}" b 1 3

0 commit comments

Comments
 (0)