main_loop()函数做的都是与具体平台无关的工作,主要包括初始化启动次数限制机制、设置软件版本号、打印启动信息、解析命令等。
1)设置启动次数有关参数。在进入main_loop()函数后,首先是根据配置加载已经保留的启动次数,并且根据配置判断是否超过启动次数。代码如下:
295 void main_loop (void)  
296 {  
297 #ifndef CFG_HUSH_PARSER  
298   static char lastcommand[CFG_CBSIZE] = { 0, };  
299   int len;  
300   int rc = 1;  
301   int flag;  
302 #endif  
303   
10 304 #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)  
11 305   char *s;  
12 306   int bootdelay;  
13 307 #endif  
14 308 #ifdef CONFIG_PREBOOT  
15 309   char *p;  
16 310 #endif  
17 311 #ifdef CONFIG_BOOTCOUNT_LIMIT  
18 312   unsigned long bootcount = 0;  
19 313   unsigned long bootlimit = 0;  
20 314   char *bcs;  
21 315   char bcs_set[16];  
22 316 #endif /* CONFIG_BOOTCOUNT_LIMIT */  
23 317   
24 318 #if defined(CONFIG_VFD) && defined(VFD_TEST_LOGO)  
25 319   ulong bmp = 0;    /* default bitmap */  
26 320   extern int trab_vfd (ulong bitmap);  
27 321   
28 322 #ifdef CONFIG_MODEM_SUPPORT  
29 323   if (do_mdm_init)  
30 324     bmp = 1;  /* alternate bitmap */  
31 325 #endif  
32 326   trab_vfd (bmp);  
33 327 #endif  /* CONFIG_VFD && VFD_TEST_LOGO */  
34 328   
35 329 #ifdef CONFIG_BOOTCOUNT_LIMIT  
36 330   bootcount = bootcount_load();         // 加载保存的启动次数  
37 331   bootcount++;                          // 启动次数加1  
38 332   bootcount_store (bootcount);          // 更新启动次数  
39 333   sprintf (bcs_set, "%lu", bootcount);  // 打印启动次数  
40 334   setenv ("bootcount", bcs_set);  
41 335   bcs = getenv ("bootlimit");  
42 336   bootlimit = bcs ? simple_strtoul (bcs, NULL, 10) : 0;  
43                                             // 转换启动次数字符串为UINT类型  
44 337 #endif /* CONFIG_BOOTCOUNT_LIMIT */ 
329337行是启动次数限制功能,启动次数限制可以被用户设置一个启动次数,然后保存在Flash存储器的特定位置,当到达启动次数后,U-Boot无法启动。该功能适合一些商业产品,通过配置不同的License限制用户重新启动系统。