Beispiel #1
0
uint8_t bootmgr_boot_sd(void)
{
    bootmgr_set_lines_count(0);
    bootmgr_set_fills_count(0);

    char *path = (char*)malloc(200);
    if(selected == 2)
    {
        bootmgr_printf(-1, 20, WHITE, "Booting from SD-card...");
        sprintf(path, "/sdroot/multirom/rom");
    }
    else
    {
        sprintf(path, "/sdroot/multirom/backup/%s", backups[selected-5]);
        bootmgr_printf(-1, 20, WHITE, "Booting \"%s\"...", backups[selected-5]);
    }

    selected = -1;
    bootmgr_draw();

    char *p = (char*)malloc(200);
    char *s = (char*)malloc(50);
    sprintf(p, "%s/boot", path);
    bootmgr_import_boot(p);

    char * mount_args[] = { NULL, "ext4", p, s, "bind" };

    // /system
    sprintf(p, "%s/system", path);
    strcpy(s, "/system");
    if(do_mount(5, mount_args) < 0)
    {
        bootmgr_printf(-1, 20, WHITE, "Mount %s failed", mount_args[2]);
        bootmgr_draw();
        return 0;
    }

    // /data
    sprintf(p, "%s/data", path);
    strcpy(s, "/data");
    do_mount(5, mount_args);

    // /cache
    sprintf(p, "%s/cache", path);
    strcpy(s, "/cache");
    do_mount(5, mount_args);

    free(p);
    free(s);
    free(path);

    return 1;
}
Beispiel #2
0
uint8_t bootmgr_toggle_ums(void)
{
    bootmgr_printf(-1, 21, WHITE, "%sabling USB mass storage...", ums_enabled ? "dis" : "en");
    bootmgr_draw();

    sync();

    static const char* gadget_files[] =
    {
        "/sys/devices/platform/msm_hsusb/gadget/lun0/file",
        "/sys/devices/platform/usb_mass_storage/lun0/file",
        NULL
    };

    FILE *f = NULL;

    uint8_t i = 0;
    for(; gadget_files[i] != NULL && f == NULL; ++i)
        f = fopen(gadget_files[i], "w+");

    if(!f)
    {
        bootmgr_erase_text(21);
        return 0;
    }

    if(!ums_enabled)
    {
        bootmgr_toggle_sdcard(1, 1);
        fputs(SD_FAT_BLOCK, f);
        bootmgr_printf(-1, 20, WHITE, "USB mass storage enabled");
        bootmgr_printf(-1, 21, WHITE, "Press \"search\" again to exit");
    }
    else
    {
        fputc(0, f);
        bootmgr_erase_text(20);
        bootmgr_erase_text(21);
        bootmgr_toggle_sdcard(0, 1);
    }
    fclose(f);

    bootmgr_display->bg_img = ums_enabled;
    bootmgr_draw();

    ums_enabled = !ums_enabled;
    return 1;
}
Beispiel #3
0
void tetris_init()
{
    tetris_set_defaults();
    
    pieces = (tetris_piece***)malloc(sizeof(tetris_piece*)*TETRIS_W);
    uint16_t y, z;
    for(y = 0; y < TETRIS_W; ++y)
    {
        pieces[y] = (tetris_piece**)malloc(sizeof(tetris_piece*)*TETRIS_H);
        for(z = 0; z < TETRIS_H; ++z)
            pieces[y][z] = NULL;
    }

    pthread_mutex_init(tetris_draw_mutex, NULL);
    t_tetris = (pthread_t*)malloc(sizeof(pthread_t));
    pthread_create(t_tetris, NULL, tetris_thread, NULL);

    bootmgr_display->bg_img = 0;
    bootmgr_set_lines_count(0);
    bootmgr_set_fills_count(0);
    bootmgr_print_fill(9,                      29,  TETRIS_W*BLOCK_SIZE+1, 1,                     WHITE, TETRIS_BORDER_TOP);
    bootmgr_print_fill(9,                      29,  1,                     TETRIS_H*BLOCK_SIZE+1, WHITE, TETRIS_BORDER_LEFT);
    bootmgr_print_fill(TETRIS_W*BLOCK_SIZE+10, 29,  1,                     TETRIS_H*BLOCK_SIZE+1, WHITE, TETRIS_BORDER_RIGHT);
    bootmgr_print_fill(9,                      470, TETRIS_W*BLOCK_SIZE+1, 1,                     WHITE, TETRIS_BORDER_BOTTOM);

    tetris_print_score();
    tetris_print_batt();
    bootmgr_printf(243, 1, WHITE, "Next");
    bootmgr_printf(243, 2, WHITE, "piece:");
    bootmgr_printf(10+((220 - 21*8)/2), 15, WHITE, "Press \"Home\" to start");
    bootmgr_draw();
}
Beispiel #4
0
void bootmgr_do_sleep(char on)
{
    if(sleep_mode == on)
        return;

    FILE *file = fopen("/sys/power/state", "w");
    fputs(on ? "mem" : "on", file);
    fclose(file);

    usleep(500000);

    bootmgr_fill_fb_black();
    fb_update(&fb);

    usleep(100000);

    bootmgr_draw();

    sleep_mode = on;

    if(!on)
    {
        bootmgr_reset_input_iters();
        force_update_time = 1;
    }
}
int bootmgr_touch_sd_exit(void)
{
    selected = -1;
    bootmgr_set_lines_count(0);
    bootmgr_set_fills_count(0);
    bootmgr_display->bg_img = 1;
    bootmgr_phase = BOOTMGR_MAIN;
    bootmgr_draw();
    bootmgr_set_time_thread(1);
    return TCALL_NONE;
}
int bootmgr_touch_sd_down(void)
{
    if(!total_backups)
        return TCALL_NONE;
    if(selected == 2 || (!backups_has_active && selected == total_backups+4))
        bootmgr_select(5);
    else if(selected == total_backups+4)
            bootmgr_select(2);
    else
        bootmgr_select(selected+1);
    bootmgr_draw();
    return TCALL_NONE;
}
int bootmgr_touch_sd_up()
{
    if(!total_backups)
        return TCALL_NONE;
    if(selected == 2 || (!backups_has_active && selected == 5))
        bootmgr_select(total_backups+4);
    else if(selected == 5)
        bootmgr_select(2);
    else
        bootmgr_select(selected-1);
    bootmgr_draw();
    return TCALL_NONE;
}
Beispiel #8
0
void *bootmgr_time_thread(void *cookie)
{
    time_t tm;

    char status[50];
    int8_t hours;
    int8_t mins;
    int battery;

    const uint16_t update_val = settings.show_seconds ? 10 : 600;
    uint16_t timer = update_val;

    while(bootmgr_time_run)
    {
        if(sleep_mode)
        {
            usleep(500000);
            continue;
        }

        if(timer == update_val || force_update_time)
        {
            time(&tm);

            battery = bootmgr_get_battery_pct();
            bootmgr_get_file(battery_status, status, 50);

            // Timezone lame handling
            hours = (tm%86400/60/60) + settings.timezone;
            mins = tm%3600/60 + settings.timezone_mins;

            if     (mins >= 60) { mins -= 60; ++hours; }
            else if(mins < 0)   { mins = 60 - mins; --hours; }

            if     (hours >= 24) hours -= 24;
            else if(hours < 0)   hours = 24 + hours;

            if(settings.show_seconds)
                bootmgr_printf(0, 0, WHITE, "%2u:%02u:%02u    Battery: %u%%, %s", hours, mins, tm%60, battery, status);
            else
                bootmgr_printf(0, 0, WHITE, "%2u:%02u         Battery: %u%%, %s", hours, mins, battery, status);

            bootmgr_draw();
            timer = 0;
            force_update_time = 0;
        }
        usleep(100000);
        ++timer;
    }
    return NULL;
}
Beispiel #9
0
void tetris_exit()
{
    run_thread = 0;
    pthread_join(t_tetris, NULL);
    free(t_tetris);

    pthread_mutex_destroy(tetris_draw_mutex);

    tetris_clear(1);

    bootmgr_display->bg_img = 1;
    bootmgr_set_lines_count(0);
    bootmgr_set_fills_count(0);
    bootmgr_phase = BOOTMGR_MAIN;
    bootmgr_draw();
}
Beispiel #10
0
void *bootmgr_time_thread(void *cookie)
{
    time_t tm;

    char pct[5];
    char status[50];
    int8_t hours;
    int8_t mins;

    const uint16_t update_val = settings.show_seconds ? 10 : 600;
    uint16_t timer = update_val;

    while(bootmgr_time_run)
    {
        if(timer == update_val)
        {
            time(&tm);
            bootmgr_get_file(battery_pct, &pct, 4);
            char *n = strchr(&pct, '\n');
            *n = NULL;
            bootmgr_get_file(battery_status, &status, 50);

            // Timezone lame handling
            hours = (tm%86400/60/60) + settings.timezone;
            mins = tm%3600/60 + settings.timezone_mins;

            if     (mins >= 60) { mins -= 60; ++hours; }
            else if(mins < 0)   { mins = 60 - mins; --hours; }

            if     (hours >= 24) hours -= 24;
            else if(hours < 0)   hours = 24 + hours;

            if(settings.show_seconds)
                bootmgr_printf(0, 0, WHITE, "%2u:%02u:%02u    Battery: %s%%, %s", hours, mins, tm%60, &pct, &status);
            else
                bootmgr_printf(0, 0, WHITE, "%2u:%02u         Battery: %s%%, %s", hours, mins, &pct, &status);

            bootmgr_draw();
            timer = 0;
        }
        usleep(100000);
        ++timer;
    }
    return NULL;
}
Beispiel #11
0
void bootmgr_boot_internal(void)
{
    bootmgr_printf(-1, 25, WHITE, "Booting from internal memory...");
    bootmgr_draw();
}
Beispiel #12
0
void bootmgr_start(int charger)
{
    settings.default_boot_sd = (char*)malloc(256);
    bootmgr_load_settings();
    bootmgr_init_display();

    bootmgr_set_brightness(settings.brightness);

    int key = 0;
    int8_t last_selected = -1;
    int8_t last_phase = -1;
    uint8_t key_pressed = (settings.timeout_seconds == -1);
    int16_t timer = settings.timeout_seconds*10;
    uint16_t x, y;
    uint8_t touch;
    selected = -1;

    pthread_t t_input;
    pthread_create(&t_input, NULL, bootmgr_input_thread, NULL);
    bootmgr_set_time_thread(1);

    bootmgr_selected = settings.default_boot;

    if(charger && (settings.charger_settings & CHARGER_AUTO_START))
    {
        char status[50];
        bootmgr_get_file(battery_status, status, 50);
        if(strstr(status, "Charging") == status)
        {
            key_pressed = 1;
            bootmgr_charger_init();
        }
    }
    disable_lg_charger = (settings.charger_settings & CHARGER_DISABLE_LG);

    while(bootmgr_run)
    {
        if(last_selected != bootmgr_selected)
        {
            bootmgr_draw();
            last_selected = bootmgr_selected;
        }

        if(last_phase != bootmgr_phase)
        {
            bootmgr_setup_touch();
            bootmgr_draw();
            last_phase = bootmgr_phase;
        }

        key = bootmgr_get_last_key();
        touch = bootmgr_get_last_touch(&x, &y);
        if(key != -1 || touch)
        {
            if(!key_pressed)
            {
                bootmgr_erase_text(25);
                bootmgr_draw();
                key_pressed = 1;
            }

            if(bootmgr_handle_key(key))
                break;

            if(touch && !sleep_mode)
            {
                key = bootmgr_check_touch(x, y);
                if(key & TCALL_EXIT_MGR)
                    break;
            }
        }

        usleep(100000);
        if(!key_pressed)
        {
            if(timer%10 == 0)
            {
                bootmgr_printf(-1, 25, WHITE, "Boot from %s in %us", bootmgr_selected == 0 ? "internal mem" : "SD card", timer/10);
                bootmgr_draw();
            }

            if(--timer <= 0)
            {
                bootmgr_erase_text(25);
                if(bootmgr_selected == 0)
                {
                    bootmgr_boot_internal();
                    break;
                }
                else
                {
                    if(bootmgr_boot_sd_auto())
                        break;
                }
                key_pressed = 1;
            }
        }
    }
    bootmgr_exit();
}
Beispiel #13
0
uint8_t bootmgr_show_rom_list(void)
{
    bootmgr_set_time_thread(0);
    bootmgr_phase = BOOTMGR_SD_SEL;
    bootmgr_display->bg_img = 0;
    bootmgr_printf(-1, 20, WHITE, "Mounting sd-ext...");
    bootmgr_draw();

    if(!backups_loaded)
    {
        // mknod
        mknod(SD_EXT_BLOCK, (0666 | S_IFBLK), makedev(179, 2));

        //mkdir
        mkdir("/sdroot", (mode_t)0775);
        uid_t uid = decode_uid("system");
        gid_t gid = decode_uid("system");
        chown("/sdroot", uid, gid);

        //mount
        static const char *mount_args[] = { NULL, "ext4", SD_EXT_BLOCK, "/sdroot" };
        int res = do_mount(4, mount_args);
        if(res < 0)
        {
            bootmgr_printf(-1, 20, WHITE, "Failed to mount sd-ext!");
            bootmgr_printf(-1, 21, WHITE, "Press back to return.");
            return 0;
        }

        DIR *dir = opendir("/sdroot/multirom/backup");
        if(dir)
        {
            struct dirent * de = NULL;
            while ((de = readdir(dir)) != NULL)
            {
                if (de->d_name[0] == '.')
                    continue;
                backups[total_backups] = (char*)malloc(128);
                strcpy(backups[total_backups++], de->d_name);

                if(total_backups >= BOOTMGR_BACKUPS_MAX-1)
                    break;
            }
            closedir(dir);
            backups[total_backups] = NULL;
        }
        dir = opendir("/sdroot/multirom/rom");
        if(dir)
            backups_has_active = 1;
    }

    backups_loaded = 1;

    bootmgr_printf(0, 0, (0x3F << 11), "Select ROM to boot. Press back to return");
    if(backups_has_active)
    {
        bootmgr_printf(0, 2, WHITE, "Current active ROM");
        bootmgr_select(2);
    }
    bootmgr_printf(0, 4, (0x3F << 11), "Backup folder:");

    uint16_t i = 0;
    for(; i <= 25 && i < total_backups; ++i)
        bootmgr_printf(0, i + 5, WHITE, "%s", backups[i]);

    if(total_backups)
    {
        if(!backups_has_active)
        {
            bootmgr_printf(-1, 2, WHITE, "No active ROM");
            bootmgr_select(5);
        }
        bootmgr_erase_text(20);
    }
    // Useless to print this, because it will be deleted immediately
    //else if(backups_has_active)
    //    bootmgr_printf(-1, 19, WHITE, "No backups present.");
    else
    {
        bootmgr_printf(-1, 20, WHITE, "No active ROM nor backups present.");
        bootmgr_printf(-1, 21, WHITE, "Press \"back\" to return");
    }

    while(bootmgr_get_last_key() != -1); // clear key queue
    while(bootmgr_get_last_touch(&i, &i));     // clear touch queue
    if(!total_backups && backups_has_active)
        return bootmgr_boot_sd();
    bootmgr_draw();
    return 0;
}
Beispiel #14
0
uint8_t bootmgr_handle_key(int key)
{
    if(sleep_mode)
    {
        bootmgr_do_sleep(0);
        return 0;
    }

    switch(bootmgr_phase)
    {
        case BOOTMGR_MAIN:
        {
            switch(key)
            {
                case KEY_VOLUMEDOWN:
                {
                   if(++bootmgr_selected == 4)
                       bootmgr_selected = 0;
                   break;
                }
                case KEY_VOLUMEUP:
                {
                   if(--bootmgr_selected == -1)
                       bootmgr_selected = 3;
                   break;
                }
                case KEY_BACK:
                    bootmgr_printf(-1, 25, WHITE, "Rebooting...");
                    bootmgr_draw();
                    __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, "recovery");
                    return 1;
                case KEY_END:
                {
                    bootmgr_do_sleep(!sleep_mode);
                    break;
                }
                case KEY_POWER:
                {
                    reboot(RB_POWER_OFF);
                    return 1;
                }
                case KEY_MENU:
                {
                    switch(bootmgr_selected)
                    {
                        case 0: bootmgr_boot_internal(); return 1;
                        case 1:
                            if(bootmgr_show_rom_list())
                                return 1;
                            break;
                        case 2: bootmgr_touch_ums();    break;
                        case 3: bootmgr_touch_misc(); break;
                    }
                    break;
                }
                case KEY_SEARCH:
                {
                    bootmgr_charger_init();
                    break;
                }
                default: break;
            }
            break;
        }
        case BOOTMGR_SD_SEL:
        {
            switch(key)
            {
                case KEY_VOLUMEDOWN:
                    bootmgr_touch_sd_down();
                    break;
                case KEY_VOLUMEUP:
                    bootmgr_touch_sd_up();
                    break;
                case KEY_MENU:
                    return bootmgr_boot_sd();
                case KEY_BACK:
                    bootmgr_touch_sd_exit();
                    break;
                default:break;
            }
            break;
        }
        case BOOTMGR_TETRIS:
        {
            tetris_key(key);
            break;
        }
        case BOOTMGR_UMS:
        {
            if(key != KEY_SEARCH)
                break;
            bootmgr_touch_exit_ums();
            break;
        }
        case BOOTMGR_CHARGER: return bootmgr_charger_key(key);
        case BOOTMGR_MISC:    return bootmgr_misc_key(key);
    }
    return 0;
}
Beispiel #15
0
void bootmgr_start()
{
    bootmgr_load_settings();
    bootmgr_init_display();

    bootmgr_set_brightness(settings.brightness);

    int key = 0;
    int8_t last_selected = -1;
    int8_t last_phase = -1;
    uint8_t key_pressed = (settings.timeout_seconds == -1);
    int16_t timer = settings.timeout_seconds*10;
    uint16_t x, y;
    uint8_t touch;
    selected = -1;

    pthread_t t_input;
    pthread_create(&t_input, NULL, bootmgr_input_thread, NULL);
    bootmgr_set_time_thread(1);

    while(bootmgr_run)
    {
        if(last_selected != bootmgr_selected)
        {
            bootmgr_draw();
            last_selected = bootmgr_selected;
        }

        if(last_phase != bootmgr_phase)
        {
            bootmgr_setup_touch();
            bootmgr_draw();
            last_phase = bootmgr_phase;
        }

        key = bootmgr_get_last_key();
        touch = bootmgr_get_last_touch(&x, &y);
        if(key != -1 || touch)
        {
            if(!key_pressed)
            {
                bootmgr_erase_text(25);
                bootmgr_draw();
                key_pressed = 1;
            }

            if(bootmgr_handle_key(key))
                break;

            if(touch)
            {
                key = bootmgr_check_touch(x, y);
                if(key & TCALL_EXIT_MGR)
                    break;
            }
        }

        usleep(100000);
        if(!key_pressed)
        {
            if(timer%10 == 0)
            {
                bootmgr_printf(-1, 25, WHITE, "Boot from internal mem in %us", timer/10);
                bootmgr_draw();
            }

            if(--timer <= 0)
            {
                bootmgr_boot_internal();
                break;
            }
        }
    }
    bootmgr_exit();
}
Beispiel #16
0
uint8_t bootmgr_handle_key(int key)
{
    switch(bootmgr_phase)
    {
        case BOOTMGR_MAIN:
        {
            switch(key)
            {
                case KEY_VOLUMEDOWN:
                {
                   if(++bootmgr_selected == 4)
                       bootmgr_selected = 0;
                   break;
                }
                case KEY_VOLUMEUP:
                {
                   if(--bootmgr_selected == -1)
                       bootmgr_selected = 3;
                   break;
                }
                case KEY_BACK:
                    bootmgr_printf(-1, 25, WHITE, "Rebooting...");
                    bootmgr_draw();
                case KEY_POWER:
                    bootmgr_close_framebuffer();
                    bootmgr_input_run = 0;
                    reboot(key == KEY_POWER ? RB_POWER_OFF : RB_AUTOBOOT);
                    return 1;
                case KEY_MENU:
                {
                    switch(bootmgr_selected)
                    {
                        case 0: bootmgr_boot_internal(); return 1;
                        case 1:
                            if(bootmgr_show_rom_list())
                                return 1;
                            break;
                        case 2: bootmgr_touch_ums();    break;
                        case 3: bootmgr_touch_tetris(); break;
                    }
                    break;
                }
                default:break;
            }
            break;
        }
        case BOOTMGR_SD_SEL:
        {
            switch(key)
            {
                case KEY_VOLUMEDOWN:
                    bootmgr_touch_sd_down();
                    break;
                case KEY_VOLUMEUP:
                    bootmgr_touch_sd_up();
                    break;
                case KEY_MENU:
                    return bootmgr_boot_sd();
                case KEY_BACK:
                    bootmgr_touch_sd_exit();
                    break;
                default:break;
            }
            break;
        }
        case BOOTMGR_TETRIS:
        {
            tetris_key(key);
            break;
        }
        case BOOTMGR_UMS:
        {
            if(key != KEY_SEARCH)
                break;
            bootmgr_touch_exit_ums();
            break;
        }
    }
    return 0;
}