[U-Boot] Adding new command using existing commands

Ajanta Sarma ajanta26 at cdot.in
Fri Aug 21 13:36:07 CEST 2015


Hi,

I am trying to add one command in U-Boot using set of existing commands.

e.g. adding one command for fusing flash with a newly compiled file.
new command - "fuse_uboot"

used commands:
1. ping (do_ping() call)
2. tftp (do_tftpb() call)
3. protect off (do_protect() call)
4. erase (do_flerase() call)
5. cp.b (do_cp_mem() call)
6. protect on  (do_protect() call)
7. reset (do_reset)

I am copying a section of my code:
addition in common/cmd_mem.c:

extern int      ping_extern(cmd_tbl_t *cmdtp, int flag, int argc, char * const 
argv[]);
extern void     protect_extern(cmd_tbl_t *cmdtp, int flag, int argc, char * const 
argv[]);
extern int      erase_extern(cmd_tbl_t *cmdtp, int flag, int argc, char * const 
argv[]);
static int      do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const 
argv[]);

#if defined(FUSE_UBOOT_FILE)
static int do_fuse_uboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
        int ret = 0, ret1 = 0, ret2 = 1;
        unsigned int f_size = 0;

        char *ping_argv[] = {"ping", NULL, NULL, NULL};
        char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
        char *protect_argv[] = {"protect", NULL, NULL, NULL};
        char *erase_argv[] = {"erase", NULL, NULL, NULL};
        char *cp_argv[] = {"cp.b", NULL, NULL, NULL};

        printf("Fusing U-Boot\n");

        ping_argv[1] = getenv("serverip");
        ret = ping_extern(cmdtp, 0, 2, ping_argv);
        if (ret == 0)
        {
                tftp_argv[1] = "10000";
                tftp_argv[2] = "uboot_new.bin";
                ret1 = (do_tftpb(cmdtp, 0, 3, tftp_argv));
                f_size = getenv("filesize");
                if (ret1 == 0)
                {
                        protect_argv[1] = "off";
                        protect_argv[2] = "1:0-10";
                        protect_extern(cmdtp, 0, 3, protect_argv);

                        erase_argv[1] = "1:0-10";
                        ret2 =  erase_extern(cmdtp, 0, 2, erase_argv);

                        if (ret2 == 0)
                        {
                                cp_argv[1] = "10000";
                                cp_argv[2] = "fe000000";
                                cp_argv[3] = f_size;
                                do_mem_cp(cmdtp, 0, 4, cp_argv);

                                protect_argv[1] = "on";
                                protect_argv[2] = "1:0-10";
                                protect_extern(cmdtp, 0, 3, protect_argv);
                                do_reset(NULL, 0, 0, NULL);
                        }
                        else
                                printf("Flash not erased : ERROR %d\n", ret2);
                }
                else
                        printf("FILE NOT FOUND\n");
        }
        else
                printf("PING FAILED : CHECK NETWORK PARAMETERS !!!\n");

        return 0;
}

U_BOOT_CMD(
        fuse_boot, 1, 0, do_fuse_uboot,
        "fuse uboot file from your TFTP server",
        ""
);
#endif

addition in common/cmd_flash.c:

int erase_extern(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
        int ret;
        ret = do_flerase(cmdtp, 0, 2, argv);
        return ret;
}

void protect_extern(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
        do_protect(cmdtp, 0, 3, argv);
}

addition in common/cmd_net.c:

int ping_extern(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
        int ret;
        ret = do_ping(cmdtp, 0, 2, argv);
        return ret;
}

The problem I am facing: whenever I pass "1:0-10" as protect_argv[2], after calling 
protect_extern(), erase get only "1" as erase_argv[1]. Same goes with every values, 
if arguments are same for both the call second value gets corrupted.

please help me out !!!

Thanks in advance,
Ajanta

Regards,

अजंता शर्मा
रिसर्च इंजिनियर
प्लॅटफॉर्म सॉफ्टवेर ग्रूप
सी-डॉट, बेंगालुरू

Ajanta Sarma
Research Engineer
Platform Software Group
C-DOT Bangalore
Contact - 08025119895
Mobile - 9739778513


Disclaimer:
----------
This email and any files transmitted with it are confidential and intended solely 
for 
the use of the individual or entity to whom they are addressed.  If



More information about the U-Boot mailing list