您的位置:首页 > 其它

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

2016-04-08 20:03 351 查看

一.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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: