I.MX6 天嵌 E9 U-boot menu hacking

时间:2021-04-15 09:22:23
/************************************************************************************
 *                      I.MX6 天嵌 E9 U-boot menu hacking
 * 说明:
 *     天嵌在U-boot中添加了自己的选择menu,想看一下怎么实现的。
 *
 *                                                  2016-8-5 深圳 南山平山村 曽剑锋
 ***********************************************************************************/


void start_armboot (void)
{
    ......
    /* main_loop() can return to retry autoboot, if so just run it again. */
    e9_board_lcd_poweron(0);
    for (;;) {
        main_loop ();         ---------------------------------------------+
    }                                                                      |
                                                                           |
    /* NOTREACHED - no way out of command loop except booting */           |
}                                                                          |
                                                                           |
void main_loop (void)           <------------------------------------------+
{

    ......
    /*
     * Main Loop for Monitor Command Processing
     */
#ifdef CONFIG_CMD_MENU
    run_command("menu", 0);                   ----------+
#endif                                                  |
    ......                                              |
}                                                       |
                                                        |
U_BOOT_CMD(                                             |
    menu,   3,  0,  do_menu,                  <---------+-----------------+
    "display a menu, to select the items to do something",                |
    "\n"                                                                  |
    "\tdisplay a menu, to select the items to do something"               |
);                                                                        |
                                                                          |
int do_menu (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])    <-----+
{                                          ---------+
    menu_shell();                                   |
    return 0;                                       |
}                                                   |
                                                    |
void menu_shell(void)                      <--------+
{
    char keyselect;
    char cmd_buf[512];
    char *ptmp;
    do
    {
        printf("\r\n#####     Boot for IMX6 Main Menu    #####\r\n");
        printf("[1]boot from emmc\n");
        printf("[2]boot from sdcard\n");
        printf("[3]boot from tftp\n");
        printf("[5]download from sdcard\n");
        printf("[0]setting boot args\n");
        printf("[q]exit to command mode\n");
        printf("Enter your selection: ");
        keyselect = getc();
        printf("%c\n", keyselect);
        switch (keyselect)
        {
#if 0
            case '1':
                if(refresh_bootargs("emmc")==0)
                    run_command("booti mmc3",0);
            break;
            case '2':
                if(refresh_bootargs("sdcard")==0)
                    run_command("booti mmc1",0);
            break;
            case '3':
                if(refresh_bootargs("tftp_nfs")==0)
                {
                    ptmp = getenv("kernelimgname");
                    sprintf(cmd_buf,"tftp 0x10800000 %s;bootm 0x10800000",ptmp);
                    run_command(cmd_buf,0);
                }
            break;
            case '0':
                do_boot_para_setting(NULL);
            break;
            case '5':
                sprintf(cmd_buf,"booti mmc1 recovery",ptmp);
                run_command(cmd_buf,0);
            break;
#endif
            case '1':
            ptmp = getenv("bootcmd");
            if(strcmp(ptmp,"run bootcmd_mmc_ubuntu") == 0)
                run_command("run bootcmd_mmc_ubuntu", 0);
            else if (strcmp(ptmp,"run bootcmd_mmc_android") == 0)
                run_command("run bootcmd_mmc_android", 0);
            else
                run_command("run bootcmd_mmc_linux", 0);
            break;
            case '2':

            break;
            case '3':
                run_command("run bootcmd_net", 0);
            break;
            case '0':
                do_boot_para_setting(NULL);           -------------+
            break;                                                 |
            case '5':                                              |
                sprintf(cmd_buf,"run bootargs_base_andorid;        |
                        booti mmc1 recovery",ptmp);                |
                run_command(cmd_buf,0);                            |
            break;                                                 |
                                                                   |
        }                                                          |
                                                                   |
    }                                                              |
    while ((keyselect != 'q') && (keyselect != 'Q'));              |
}                                                                  |
                                                                   |
static int do_boot_para_setting(char *pbuf)           <------------+
{
    int i;
    char c;

    do
    {
        printf("\r\n##### param setting #####\r\n");
        printf("[1]setting nfs args\n");
        printf("[2]setting tftp args\n");
        printf("[3]setting display args\n");
        printf("[4]setting default boot\n");
        printf("[s]save setting\n");
        printf("[q]quit\n");
        printf("Enter your selection: ");
        c = getc();
        printf("%c\n", c);
        switch (c)
        {
        case '1':
            do_nfs_para_setting(NULL);
            break;
        case '2':
            do_tftp_para_setting(NULL);
            break;
        case '3':
            do_disp_para_setting(NULL);         -------------+
            break;                                           |
        case '4':                                            |
            do_media_para_setting(NULL);                     |
            break;                                           |
        case 's':                                            |
            run_command("saveenv", 0);                       |
            break;                                           |
        }                                                    |
    }                                                        |
    while (c != 'q');                                        |
}                                                            |
                                                             |
static int do_disp_para_setting(char *pbuf)     <------------+
{
    lcd_menu_shell();            -----------+
    return 0;                               |
}                                           |
                                            |
void lcd_menu_shell()            <----------+
{
    char c;
    char cmd_buf[256];
    char cmd_buf_all[256];
    int need_renew = 0;
    while (1)
    {
        lcd_menu_usage();
        c = getc();
        printf("%c\n", c);
        if ((c == '1'))
        {
            sprintf(cmd_buf, " video=mxcfb0:");
            if (lcd_setting(&cmd_buf[strlen(cmd_buf)]) != 0)
            {
                strcat(cmd_buf, " video=mxcfb1:off video=mxcfb2:off fbmem=48M");
                sprintf(cmd_buf_all, "setenv displayArgs %s", cmd_buf);
                run_command(cmd_buf_all, 0);
            }
        }
        else if (c == '2')
        {
            for (;;)
            {
                printf("\r\n##### display select for android #####\r\n");
                printf("[1] 800*600 for LVDS->VGA \r\n");
                printf("[2] 1024*768 for FPC->VGA \r\n");    // video=mxcfb0:dev=lcd,if=RGB24,TQ-VGA_1024768,bpp=32 video=mxcfb1:dev=hdmi,1280x720M@60,if=RGB24,bpp=32 video=mxcfb2:off fbmem=28M,48M
                printf("[3] 1280*768 for FPC->VGA\r\n");    //video=mxcfb1:dev=lcd,if=RGB24,TQ-VGA_1280768,bpp=32 video=mxcfb0:dev=hdmi,1280x720M@60,if=RGB2em4,bpp=32 video=mxcfb2:off fbmem=28M,48M
                printf("[4] 1360*768 for FPC->VGA\r\n");    //video=mxcfb1:dev=lcd,if=RGB24,TQ-VGA_1360768,bpp=32 video=mxcfb0:dev=hdmi,1280x720M@60,if=RGB2em4,bpp=32 video=mxcfb2:off fbmem=28M,48M
                printf("[5] 1920*1080 for FPC->VGA\r\n");    //video=mxcfb1:dev=lcd,if=RGB24,TQ
                printf("[6] 1366*768 for LVDS->VGA \r\n");
                printf("[7] 1920*1080 for LVDS (need 2 lvds ports) \r\n");
                printf("[q] quit \r\n");
                printf("Enter your selection: ");
                c = getc();
                printf("%c\n", c);
                if (c == '1')
                {
                    sprintf(cmd_buf_all, "dev=ldb,TQ-ldb_800600,if=RGB666,bpp=32 ldb=dul0");
                    sprintf(cmd_buf_all, "setenv displayArgs %s", cmd_buf);
                    run_command(cmd_buf_all, 0);
                    break;
                }
                else if (c == '2')
                {
                    sprintf(cmd_buf_all, "setenv displayArgs video=mxcfb0:dev=lcd,if=RGB24,TQ-VGA_1024768,bpp=32 video=mxcfb1:dev=hdmi,1280x720M@60,if=RGB24,bpp=32 video=mxcfb2:off fbmem=28M,48M");
                    run_command(cmd_buf_all, 0);
                    break;
                }
                else if (c == '3')
                {
                    sprintf(cmd_buf_all, "setenv displayArgs video=mxcfb1:dev=lcd,if=RGB24,TQ-VGA_1280768,bpp=32 video=mxcfb0:dev=hdmi,1280x720M@60,if=RGB24,bpp=32 video=mxcfb2:off fbmem=28M,48M");
                    run_command(cmd_buf_all, 0);
                    break;
                }
                else if (c == '4')
                {
                    sprintf(cmd_buf_all, "setenv displayArgs video=mxcfb1:dev=lcd,if=RGB24,TQ-VGA_1360768,bpp=32 video=mxcfb0:dev=hdmi,1280x720M@60,if=RGB24,bpp=32 video=mxcfb2:off fbmem=28M,48M");
                    run_command(cmd_buf_all, 0);
                    break;
                }
                else if (c == '5')
                {
                    sprintf(cmd_buf_all, "setenv displayArgs video=mxcfb1:dev=lcd,if=RGB24,TQ-VGA_19201080,bpp=32 video=mxcfb0:dev=hdmi,1280x720M@60,if=RGB24,bpp=32 video=mxcfb2:off fbmem=28M,48M");
                    run_command(cmd_buf_all, 0);
                    break;
                }
                else if (c == '6')
                {
                    sprintf(cmd_buf_all, "setenv displayArgs video=mxcfb0:dev=ldb,LDB-XGA,if=RGB666,bpp=32 ldb=dul0 video=mxcfb1:dev=hdmi,1280x720M@60,if=RGB24,bpp=32 video=mxcfb2:off fbmem=28M,48M");
                    run_command(cmd_buf_all, 0);
                    break;
                }
                else if (c == '7')
                {
                    sprintf(cmd_buf_all, "setenv displayArgs video=mxcfb0:dev=ldb,LDB-1080P60,if=RGB24,bpp=32 ldb=spl0 video=mxcfb1:dev=hdmi,1280x720M@60,if=RGB24,bpp=32 video=mxcfb2:off fbmem=28M,48M");
                    run_command(cmd_buf_all, 0);
                    break;
                }
                else if (c == 'q')
                {
                    break;
                }
                printf("ill param\n");
            }
        }
        else if(c == '3')
        {//video=mxcfb0:dev=ldb,TQ-ldb_1024768,if=RGB666 ldb=sep1
            sprintf(cmd_buf_all, "setenv displayArgs video=mxcfb0:dev=ldb,TQ-ldb_1024768,if=RGB666 ldb=sep1");
            run_command(cmd_buf_all, 0);
        }
        else if(c == 's')
        {
            run_command("saveenv", 0);
        }
        else if (c == 'q')
        {
            break;
        }
    }
}