为了防止进入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
--> 默认的 password 为 geenovo
--> 如果设置了环境变量 ubootpwd,则密码为ubootpwd的值。
比如 setenv ubootpwd 888888,那password是 888888
4、在相应的配置文件中添加,如:include/configs/eud7141.h
#define CONFIG_UBOOT_PWD
5、rebuild 即可。