[X]关闭

uboot启动菜单栏编写

文档创建者:ぉ沙皮狗的忧伤
浏览次数:3811
最后更新:2019-08-28
1、代码块
#include <common.h>
#include <command.h>
#include <nand.h>



#define USE_USB_DOWN  1
#define USE_TFTP_DOWN 2
#define USE_SD_DOWN   3



void main_menu_usage(char menu_type)
{


    printf("\r\n#####     Boot for MZ7XA-7020 Main Menu    #####\r\n");


    switch (menu_type){

        case USE_USB_DOWN:
            printf("#####     DiMai USB download mode     #####\r\n\n");
        break;
        case USE_TFTP_DOWN:
            printf("#####     DiMai TFTP download mode     #####\r\n\n");
        break;
        case USE_SD_DOWN:
            printf("#####     DiMai SD download mode     #####\r\n\n");
        break;
        default:
            printf("#####     DiMai error download mode     #####\r\n\n");

    }


    printf("[0] One click to download\r\n");
    printf("[1] Download BOOT.bin to qspinor flash\r\n");
    printf("[2] Download system.bit to qspinor flsah\r\n");
    printf("[3] Download kernel(uImage.bin) to qspinor flash\r\n");
    printf("[4] Download Download devicetree to qspinor flash\r\n");
    printf("[5] Download Download ramdisk to qspinor flash\r\n");
    printf("[6] Download YAFFS image (root.bin) to Nand Flash\r\n");
    printf("[7] Download Program to SDRAM and Run it\r\n");
    printf("[8] Boot the system\r\n");
    printf("[9] Format the Nand Flash\r\n");
    printf("[a] Download User Program\r\n");
    printf("Enter your selection: ");
}






void menu_shell(void)
{
    char keyselect;
    char cmd_buf[200];
    int err;
    while (1){
        main_menu_usage(USE_SD_DOWN);
        keyselect = getc();
        printf("%c\n", keyselect);


        switch (keyselect){


            case '0':
                strcpy(cmd_buf,\
                            "sf probe 0 0 0 && " \
                            "sf read ${loadbit_addr} 0x0 ${boot_size} && " \
                            "sf read ${loadbootenv_addr} 0x100000 ${qbootenv_size} && " \
                            "sf read ${kernel_load_address} 0x720000 ${kernel_size} && " \
                            "echo Copying ramdisk... && " \
                            "sf read ${ramdisk_load_address} 0xD40000 ${ramdisk_size} && " \
                            "sf read ${devicetree_load_address} 0xD20000 ${devicetree_size} && " \
                );
                err = run_command_list(cmd_buf, -1, 0);
                if(err != 0){
                    printf(" Download  to qspinor flash faile\r\n");
                }
            break;



            case '1':
                strcpy(cmd_buf,\
                            "sf probe 0 0 0 && " \
                            "sf read ${loadbit_addr} 0x0 ${boot_size} && " \
                );
                err = run_command_list(cmd_buf, -1, 0);
                if(err != 0){
                    printf(" Download BOOT.bin to qspinor flash faile\r\n");
                }
            break;


            case '2':
                strcpy(cmd_buf,\
                            "sf probe 0 0 0 && " \
                            "sf read ${loadbootenv_addr} 0x100000 ${qbootenv_size} && " \
                );
                err = run_command_list(cmd_buf, -1, 0);
                if(err != 0){
                    printf(" Download system.bit to qspinor flsah faile\r\n");
                }
            break;



            case '3':
                strcpy(cmd_buf,\
                            "sf probe 0 0 0 && " \
                            "sf read ${kernel_load_address} 0x720000 ${kernel_size} && " \
                );
                err = run_command_list(cmd_buf, -1, 0);
                if(err != 0){
                    printf("Download kernel to qspinor flash faile\r\n");
                }
            break;




            case '4':
                strcpy(cmd_buf,\
                            "sf probe 0 0 0 && " \
                            "sf read ${devicetree_load_address} 0xD20000 ${devicetree_size} && " \

                );
                err = run_command_list(cmd_buf, -1, 0);
                if(err != 0){
                    printf(" Download devicetree to qspinor flash faile\r\n");
                }
            break;



            case '5':
                strcpy(cmd_buf,\
                            "sf probe 0 0 0 && " \
                            "echo Copying ramdisk... && " \
                            "sf read ${ramdisk_load_address} 0xD40000 ${ramdisk_size} && " \
                );
                err = run_command_list(cmd_buf, -1, 0);
                if(err != 0){
                    printf(" Download ramdisk to qspinor flash faile\r\n");
                }
            break;


            case '6':
                ;
            break;


            case '7':
                ;
            break;


            case '8':
                ;
            break;


            case '9':
                ;
            break;


            case 'q':
                return();
            break;



            default: printf("#####     Enter error, please reenter     #####\r\n\n");
        }

    }
}




static int do_menu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
    menu_shell();
    return 0;
}




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"
);



2、具体相关步骤
    1)、zynq-common.h官方提供的头文件

       zynq_mz7x.h自己定义的头文件(采用米尔提供的头,比米联客提供的详细)


"qbit_size=0x600000\0"  \
    "qbit_addr=0x0120004\0" \
    "qbitsize_addr=0x0120000\0" \
    "qboot_addr=0x000000\0" \
    "qbootenv_addr=0x100000\0" \
    "qbootenv_size=0x020000\0" \
    "qkernel_addr=0x720000\0" \
    "qdevtree_addr=0xD20000\0" \
    "qramdisk_addr=0xD40000\0" \
    "kernel_size=0x600000\0"    \
    "devicetree_size=0x020000\0"    \
    "ramdisk_size=0xC00000\0"    \
    "boot_size=0x100000\0"    \
    "ethaddr=00:0a:35:00:01:22\0"    \
    "kernel_image=uImage\0"    \
    "kernel_load_address=0x2080000\0" \
    "ramdisk_image=uramdisk.image.gz\0"    \
    "ramdisk_load_address=0x4000000\0"    \
    "devicetree_image=devicetree.dtb\0"    \
    "devicetree_load_address=0x2000000\0"    \
    "bitstream_image=system.bit.bin\0"    \
    "boot_image=BOOT.bin\0"    \
    "loadbit_addr=0x100000\0"    \
    "loadbootenv_addr=0x2000000\0" \
    "fdt_high=0x20000000\0"    \
    "initrd_high=0x20000000\0"    \
    "bootenv=uEnv.txt\0" \
    "optargs=hdmi\0" \



     2)、采用qspiboot将BOOT.bin、system.bin、uImage及devicetree.dtb文件从SD卡通过sf命令读到nor_flash中,每次读之前都要使用sf probe 0 0 0  然后在去读,具体实现步骤根据个人需求参考 官方提供头文件及自己定义的头文件     

      3)、文件存放路径:./uboot/cmd/

        文件名:menu.c



        需要配置以下几点:
        vim ./cmd/makefile添加

        
        作用:把menu文件编译进去



        vim ./include/common.h添加

        
        作用:添加到头中方便其它函数调用menu_shell函数



         vim  ./common/autoboot.c

        
        作用:在启动计时完了按下回车键,能直接直接进入到菜单栏界面,具体得自己去看代码


        4)、编译uboot,添加到SD卡,测试

        


         5)、波到QSPI测试启动菜单界面是否一致

      






       6)、遗留问题,因为nor_flash只有16M,ramdisk_image大小却有13M无法烧录到里面,bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}
还未实现,后续。。。。。







发表评论已发布 2

uisrc

发表于 2019-8-28 15:20:00 | 显示全部楼层

加油,你行的
越努力越幸运!加油!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则