Skip to content

Commit 2a31c9e

Browse files
committed
multirom: core: Improve autoboot to external ROM
* Preserve the name of an external ROM in autoboot * Delay the partitions load to detect the external rom the same way a curr_rom_part is waited Change-Id: I0bb93799093b62d20f8b5a761869f93548f475a0 Signed-off-by: Adrian DC <[email protected]>
1 parent 9dfca08 commit 2a31c9e

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

multirom.c

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ int multirom_default_status(struct multirom_status *s)
592592
s->enable_kmsg_logging = 0;
593593
s->rotation = MULTIROM_DEFAULT_ROTATION;
594594
s->anim_duration_coef = 1.f;
595+
s->auto_boot_name = NULL;
595596

596597
s->fstab = fstab_auto_load();
597598
if(!s->fstab)
@@ -705,6 +706,7 @@ int multirom_load_status(struct multirom_status *s)
705706
char line[1024];
706707
char current_rom[256] = { 0 };
707708
char auto_boot_rom[256] = { 0 };
709+
int auto_boot_len;
708710

709711
char name[64];
710712
char *pch;
@@ -754,24 +756,61 @@ int multirom_load_status(struct multirom_status *s)
754756

755757
fclose(f);
756758

757-
// find USB drive if we're booting from it
758-
if(s->curr_rom_part) // && s->is_second_boot)
759+
// Find USB drive if we're booting from it
760+
auto_boot_len = strlen(s->auto_boot_name);
761+
if (s->curr_rom_part || auto_boot_len > 0)
759762
{
763+
struct multirom_rom *r = NULL;
760764
struct usb_partition *p = NULL;
761765
int tries = 0;
762-
while(!p && tries < 10)
766+
int i;
767+
768+
// Search curr_rom_part
769+
while (s->curr_rom_part && !p && tries < 10)
763770
{
764771
multirom_update_partitions(s);
765772
p = multirom_get_partition(s, s->curr_rom_part);
766773

767-
if(p)
774+
if (p)
768775
{
776+
INFO("current part '%s' found\n", s->curr_rom_part);
769777
multirom_scan_partition_for_roms(s, p);
770778
break;
771779
}
772780

773781
++tries;
774-
ERROR("part %s not found, waiting 1s (%d)\n", s->curr_rom_part, tries);
782+
ERROR("part '%s' not found, waiting 1s (%d)\n", s->curr_rom_part, tries);
783+
sleep(1);
784+
}
785+
786+
// Search auto_boot_rom
787+
tries = 0;
788+
while (auto_boot_len > 0 && !r && tries < 10)
789+
{
790+
multirom_update_partitions(s);
791+
for (i = 0; s->roms && s->roms[i];)
792+
{
793+
if (s->roms[i]->partition)
794+
{
795+
list_rm_at(&s->roms, i, &multirom_free_rom);
796+
i = 0;
797+
}
798+
else ++i;
799+
}
800+
for (i = 0; s->partitions && s->partitions[i]; ++i)
801+
{
802+
multirom_scan_partition_for_roms(s, s->partitions[i]);
803+
}
804+
805+
r = multirom_get_rom(s, s->auto_boot_name, NULL);
806+
if (r)
807+
{
808+
INFO("autoboot rom '%s' found\n", s->auto_boot_name);
809+
break;
810+
}
811+
812+
++tries;
813+
ERROR("rom '%s' not found, waiting 1s (%d)\n", s->auto_boot_name, tries);
775814
sleep(1);
776815
}
777816
}
@@ -781,6 +820,9 @@ int multirom_load_status(struct multirom_status *s)
781820
{
782821
ERROR("Failed to select current rom (%s, part %s), using Internal!\n", current_rom, s->curr_rom_part);
783822
s->current_rom = multirom_get_internal(s);
823+
if (s->curr_rom_part) {
824+
free(s->curr_rom_part);
825+
}
784826
s->curr_rom_part = NULL;
785827
if(!s->current_rom)
786828
{
@@ -832,7 +874,7 @@ int multirom_save_status(struct multirom_status *s)
832874
return -1;
833875
}
834876

835-
multirom_fixup_rom_name(s->auto_boot_rom, auto_boot_name, "");
877+
multirom_fixup_rom_name(s->auto_boot_rom, auto_boot_name, s->auto_boot_name);
836878
multirom_fixup_rom_name(s->current_rom, current_name, INTERNAL_ROM_NAME);
837879

838880
fprintf(f, "current_rom=%s\n", current_name);
@@ -891,10 +933,12 @@ void multirom_dump_status(struct multirom_status *s)
891933
INFO(" hide_internal=%d\n", s->hide_internal);
892934
INFO(" int_display_name=%s\n", s->int_display_name ? s->int_display_name : "NULL");
893935
INFO(" auto_boot_seconds=%d\n", s->auto_boot_seconds);
894-
INFO(" auto_boot_rom=%s\n", s->auto_boot_rom ? s->auto_boot_rom->name : "NULL");
936+
INFO(" auto_boot_rom=%s\n", s->auto_boot_rom ? s->auto_boot_rom->name : s->auto_boot_name);
895937
INFO(" auto_boot_type=%d\n", s->auto_boot_type);
896938
INFO(" curr_rom_part=%s\n", s->curr_rom_part ? s->curr_rom_part : "NULL");
897939
INFO("\n");
940+
INFO(" auto_boot_name=%s\n", s->auto_boot_name);
941+
INFO("\n");
898942

899943
int i;
900944
for(i = 0; s->roms && s->roms[i]; ++i)
@@ -913,6 +957,7 @@ void multirom_free_status(struct multirom_status *s)
913957
{
914958
list_clear(&s->partitions, &multirom_destroy_partition);
915959
list_clear(&s->roms, &multirom_free_rom);
960+
free(s->auto_boot_name);
916961
free(s->curr_rom_part);
917962
free(s->int_display_name);
918963
if (s->fstab) fstab_destroy(s->fstab);
@@ -930,7 +975,7 @@ void multirom_find_usb_roms(struct multirom_status *s)
930975
{
931976
char auto_boot_name[MAX_ROM_NAME_LEN+1];
932977
char current_name[MAX_ROM_NAME_LEN+1];
933-
multirom_fixup_rom_name(s->auto_boot_rom, auto_boot_name, "");
978+
multirom_fixup_rom_name(s->auto_boot_rom, auto_boot_name, s->auto_boot_name);
934979
multirom_fixup_rom_name(s->current_rom, current_name, INTERNAL_ROM_NAME);
935980

936981
// remove USB roms

multirom.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ struct multirom_status
120120
char *curr_rom_part;
121121
struct fstab *fstab;
122122
struct rcadditions rc;
123+
124+
// Runtime variables
125+
char* auto_boot_name;
123126
};
124127

125128
int multirom(const char *rom_to_boot);

0 commit comments

Comments
 (0)