I wish to boot a partition that can be decided in the U-Boot stage. The process is highlighted below:
I have to compose the U-Boot independent application to implement the logic marked red.
2. U-Boot independent APP
The U-Boot provides a console we can interact with. This section will introduce how to add an independent command to the U-Boot source code project. In the U-Boot project, each U-Boot provided command is defined by U_BOOT_CMD macro in include/command.h.
Attributes:
name: The command name;
maxargs: The maximum of the inputted arguments;
command: The C function is mapped to the command;
usage: Usage message;
...
2.1 Code Base
Assuming the command name is utils_load
Add obj-y += utils_load.o to Makefile in common directory.
#include <common.h>
#include <command.h>
#include <linux/stddef.h>
int do_utils_load(cmd_tbl_t *cmdtp, int flag, int argc, char* const argv[])
{
int ret = 0;
int i = 0;
printf("[INFO] The input is %d\n", argc);
for (i = 0; i < argc; i ++) {
printf("[INFO] the argv[%d] is %s\n", i, argv[i]);
}
finish:
return ret;
}
U_BOOT_CMD(
utils_load,
5,
1,
do_utils_load,
"format : utils_load address",
"example: utils_load 0x80000000"
);
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j16