Skip to content

Commit 3703df5

Browse files
committed
recovery: add support for switching bootmode
Change-Id: I8bc5770baae7a1342bedb8eddeb651a31f12f1b5
1 parent 5887eab commit 3703df5

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

recovery/dualboot.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum dualboot_system get_selected_system(void) {
2929
return selected_system;
3030
}
3131

32-
static int select_system(const char* title) {
32+
int dualboot_select_system(const char* title) {
3333
const char* headers[] = { title, "", NULL };
3434
char* items[] = { "System1", "System2", NULL };
3535
enum dualboot_system chosen_item = -1;
@@ -123,7 +123,7 @@ void dualboot_setup_env(void) {
123123
}
124124

125125
void dualboot_show_selection_ui(void) {
126-
int sys = select_system("Select System to manage:");
126+
int sys = dualboot_select_system("Select System to manage:");
127127
if(sys!=GO_BACK) selected_system = sys;
128128
}
129129

recovery/dualboot.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ enum dualboot_system {
99
SYSTEM2
1010
};
1111

12+
int dualboot_select_system(const char* title);
1213
void dualboot_init(void);
1314
void dualboot_show_selection_ui(void);
1415
enum dualboot_system get_selected_system(void);

recovery/recovery_ui.c

+62
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,65 @@ void device_truedualboot_after_load_volume_table() {
267267
v->blk_device = PATH_USERDATA_NODE_BACKUP;
268268
}
269269
}
270+
271+
static int set_bootmode(char* bootmode) {
272+
// open misc-partition
273+
FILE* misc = fopen("/dev/block/platform/msm_sdcc.1/by-name/misc", "wb");
274+
if (misc == NULL) {
275+
printf("Error opening misc partition.\n");
276+
return -1;
277+
}
278+
279+
// write bootmode
280+
fseek(misc, 0x1000, SEEK_SET);
281+
if(fputs(bootmode, misc)<0) {
282+
printf("Error writing bootmode to misc partition.\n");
283+
return -1;
284+
}
285+
286+
// close
287+
fclose(misc);
288+
return 0;
289+
}
290+
291+
static int get_bootmode(char* bootmode) {
292+
// open misc-partition
293+
FILE* misc = fopen("/dev/block/platform/msm_sdcc.1/by-name/misc", "rb");
294+
if (misc == NULL) {
295+
printf("Error opening misc partition.\n");
296+
return -1;
297+
}
298+
299+
// read bootmode
300+
fseek(misc, 0x1000, SEEK_SET);
301+
if(fgets(bootmode, 13, misc)==NULL) {
302+
printf("Error reading bootmode from misc partition.\n");
303+
return -1;
304+
}
305+
306+
// close
307+
fclose(misc);
308+
return 0;
309+
}
310+
311+
void device_choose_bootmode(void) {
312+
int sys = dualboot_select_system("Set bootmode:");
313+
if(sys==GO_BACK) return;
314+
315+
if(sys==SYSTEM1)
316+
set_bootmode("boot-system0");
317+
else if(sys==SYSTEM2)
318+
set_bootmode("boot-system1");
319+
}
320+
321+
int device_get_bootmode(char* bootmode_name) {
322+
char* sysnum = 0;
323+
324+
char bootmode[13];
325+
get_bootmode(&bootmode);
326+
if(strcmp(bootmode, "boot-system1")==0)
327+
sysnum = 1;
328+
329+
sprintf(bootmode_name, "active system: %d", sysnum+1);
330+
return 0;
331+
}

0 commit comments

Comments
 (0)