hi3516a的uboot自动升级相关问题的解决

一.uboot命令行加密

实现uboot 进入命令行,需要输入密码功能。

  • 1.设置环境变量
    在include/configs/hi3516a.h文件中
    #define CONFIG_UBOOT_PWD

  • 2.加密函数
    common/main.c

在int readline (const char *const prompt)函数中添加下面代码

*time :2016.3.25
*func :command line add passwd
*auther : liu
*******************************/
        #ifdef CONFIG_UBOOT_PWD
        char pwd[64];
        char c;
        int index;
        static int bPwd = 1;
        while (bPwd)
        {
                puts ("password: ");
                index = 0;
                while ((c = getc()) != '\r')
                {
                        if (c == 8) // Backspace
                        {
                                if (index > 0)
                                {
                                        printf ("\b \b");
                                        index--;
                                }
                                continue;
                        }
                        putc('*');
                        pwd[index] = c;
                        index++;
                }
                pwd[index] = '\0';
                putc ('\n');
                char *s;
                s = getenv ("ubootpwd");
                if (!s)
                {
                        s = "123456";
                }
                if (!strcmp (pwd, s))
                {
                        bPwd = 0;
                }
         }
        #endif

二.升级过程中led指示问题

实现功能:
正在升级中(从内存拷贝到spi flash中):led闪5下
升级失败:led以 2次/s的频率闪
升级成功:关闭led

*time :2016.3.23
*func :on led
*name :liusir
*********************************************************************/
#define GPIO12_CON (*((volatile unsigned int *)0x200F01AC))//GPIO控制寄存器
#define GPIO12_DIR (*((volatile unsigned int *)0x20200400))//GPIO方向寄存器
#define GPIO12_DAT (*((volatile unsigned int *)0x20200004))//GPIO数据寄存器

void led_on(void)//on led
{
        GPIO12_CON &= ~(0x3);
        GPIO12_DIR |= 0x1;
        GPIO12_DAT |= 0x1;
}

void led_off(void)//off led
{
        GPIO12_CON &= ~(0x3);
        GPIO12_DIR |= 0x1;
        GPIO12_DAT &= ~(0x1);
}

void led_flash()//write flash  failed run
{
        GPIO12_CON &= ~(0x3);
        while(1)
        {
                GPIO12_DAT &= 0x0;
                udelay(2500000);
                GPIO12_DAT |= 0X1;
                udelay(2500000);
        }
}


for (int i = 0; i < 6; ++i)// write flash run
{
        led_off();
        udelay(100000);
        led_on();
        udelay(100000);
}

三.版本检测问题防止重复升级

  • 1.设置环境变量

include/configs/hi3516a.h

#define CONFIG_FIRMWAREVER      //"3516A_uboot_20160328"
#define CONFIG_KERNELVER        //"3516A_kernel_20160328"
#define CONFIG_ROOTFSVER        //"3516A_rootfs_20160328"
#define CONFIG_APPFSVER         //"3516A_appfs_20160328"
#define CONFIG_CONFSVER         //"3516A_confs_20160328"
  • 2.common/env_common.c
/**************************
*time : 2016.3.23
****************************/
#ifdef CONFIG_FIRMWAREVER
        "firmware_ver=" CONFIG_FIRMWAREVER              "\0"
#endif
#ifdef CONFIG_KERNELVER
        "kernel_ver="   CONFIG_FIRMWAREVER              "\0"
#endif
#ifdef CONFIG_ROOTFSVER
        "rootfs_ver="   CONFIG_FIRMWAREVER              "\0"
#endif
#ifdef CONFIG_APPFSVER
        "appfs_ver="    CONFIG_FIRMWAREVER              "\0"
#endif
#ifdef CONFIG_CONFSVER
        "confs_ver="    CONFIG_FIRMWAREVER              "\0"
#endif
/*******************************************/

注意:如果想让该环境变量未设置之前print打印不显示的话,该段可以省略不加

  • 3.检测版本是否相同(auto_update.c )
    原理:通过对比版本号这个环境变量是否相同来决定是否升级。
/****************************************
*time : 2016.3.25
*func : check version
*name : liu
****************************************/
 static int check_version(int i)
 {
        char *env_img[AU_MAXFILES] = {
                "firmware_ver",
                "kernel_ver",
                "rootfs_ver",
                "appfs_ver",
                "confs_ver"
        };

        const image_header_t *hdr;
        hdr = (image_header_t *)LOAD_ADDR;

        char *old_ver = getenv(env_img[i]);//get image version env
        if (NULL == old_ver)
        {
                printf("get env failed!\n");
                return 0;
        }

        char *new_ver = image_get_name(hdr);//get image name
        if (!(strcmp((const char*)new_ver,(const char*)old_ver))) //compare version name
        {
                printf("The version had been the new version!\n" );
                return 1;
        }

        printf("-------------updating---------------- %s\n",hdr->ih_name);
        setenv(env_img[j],image_get_name(hdr));//save new version env
        printf("the envriment have been save\n");

        return 0;
 }
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值