learning uboot auto switch to stanbdy system in qca4531 cpu

design:

   when uboot load kerne failed,we can switch to stanbdy system;

how to realize:

  when boot fail, we can let uboot env bootKenrelFailCount++, then save to uboot_env partiton.

    watchdog timeout will trigger cpu reset, when bootKernelFailCount bigger than a fixed number

  we can realize switch to stanbdy system

 

reference code:

 

void bootKernelFailProcess(){

        char buf[100]=0;

        char *s;

        int bootKernelFailCount =0;

        s=getenv("bootKernelFailCount");

        bootKernelFailCount =++atoi(s);

        sprintf(buf,"setenv bootKernelFailCount %d", bootKernelFailCount);

        run_command(buf,0);

        run_command("saveenv",0);

}

 

void changeBootslotFunction(){

        char buf[100]=0;

        int bootslot=0;

        s=getenv("bootslot");

        bootslot=atoi(s)^1;

        sprintf(buf,"setenv bootslot %d",bootslot);

        run_command(buf,0);

        run_command("saveenv",0);

}

void bootKernelFailCountDetect(){

        if( atoi(getenv("bootKernelfailCount ")) > 2 ){

                run_command("setenv bootKernelFailCount  0",0);

                changeBootslotFunction();

        }

}

 

posted @ 2019-01-09 17:08  嵌入式实操  阅读(235)  评论(0编辑  收藏  举报