uboot 添加密码保护实现方法

为了防止进入uboot下读取nand flash的内容,在进入uboot命令行之前,需要输入密码,并且该密码可通过设置环境"ubootpwd"的值来修改,若不存在该环境变量,则使用默认密码(代码中写死的)。


uboot中实现方式如下:

1、进入uboot的根目录。

2、在common/main.c文件中,修改int readline (const char *const prompt);函数。

--> 在readline函数的开头位置添加内容如下

#ifdef CONFIG_UBOOT_PWD
	char pwd[64];
	char c;
	int index;
	static int bPwd = 1;
	while (bPwd){
		puts ("### Please input uboot password: ###\n");
		index = 0;
		while ((c = getc()) != '\r'){
			if (c == 8) /* Backspace */
			{
				if (index > 0){
					printf ("\b \b");
					index--;
				}
				continue;
			}
//			else if (c == 3){ /* Ctrl + c */
//				do_reset();
//			}
			putc('*');
			pwd[index] = c;
			index++;
		}
		pwd[index] = '\0';
		putc ('\n');
		char *s;
		s = getenv ("ubootpwd");
		if (!s){
			s = "geenovo";
		}
		if (!strcmp (pwd, s)){
			bPwd = 0;
		}
	}
#endif


3、uboot密码保护使用方法。
--> 默认的 password 为 geenovo
--> 如果设置了环境变量 ubootpwd,则密码为ubootpwd的值。
比如 setenv ubootpwd 888888,那password是 888888


4、在相应的配置文件中添加,如:include/configs/eud7141.h
#define CONFIG_UBOOT_PWD

5、rebuild 即可。


  • 2
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值