⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dn.c

📁 motorola 针对coldfire 5275 评估板的Dbug bootloader源程序
💻 C
字号:
/*
 * File:        dn.c
 * Purpose:     Network download command for dBUG
 *
 * Notes:
 */
#include "src/include/dbug.h"
#include "src/uif/uif.h"
#include "src/uif/net/net.h"

#ifdef DBUG_NETWORK

/********************************************************************/

extern ADDRESS md_last_address;

extern ADDRESS disasm_last_address;

extern void
download_coff (void);

extern int
dn_download_srecord (int);

extern int
download_elf (int);

extern void
download_image (ADDRESS);

/* The one and only network interface */
extern NIF nif1;

/********************************************************************/
void
uif_cmd_dn (int argc, char **argv)
{
    /*
     * This routine downloads ELF, COFF or S-records via TFTP.
     */
    IP_ADDR Server;
    int offset_to_addr, dltype, curarg;
    ADDRESS image_addr;
    int success, typeset, board_dltype;
    char fnbuf[80];
    char *fn, *p;

    /* Get/set initial/default values */
    uif_dlio = UIF_DLIO_NETWORK;
    offset_to_addr = 0;
    image_addr = (ADDRESS)__USER_SPACE;
    dltype = board_get_filetype();
    fn = NULL;
    curarg = 1;
    typeset = FALSE;

    /* 'argv' is NULL when autoboot-ing */
    if (argv == NULL)
        goto do_download;

    /*
     * Parse apart the arguments to see if we are forcing
     * download of a certain file type, and then parse
     * arguments according to that filetype.
     */

    if (argv[curarg] != NULL)
    {
        /*
         * First things first.  Test the first argument to see if
         * it is an option.  If it is, then see if it is forcing
         * one of the supported download filetypes, and then proceed
         * to parse the arguments according to that filetype.
         */
        if (argv[curarg][0] == '-')
        {
            switch (argv[curarg][1])
            {
                case 's':
                case 'S':
                    /*
                     * Parse arguments needed for S-Records
                     */
                    ++curarg;
                    typeset = TRUE;
                    goto parse_srec_arg;
                case 'c':
                case 'C':
                    /*
                     * Parse arguments needed for COFF
                     */
                    ++curarg;
                    typeset = TRUE;
                    goto parse_coff_arg;
                case 'e':
                case 'E':
                    /*
                     * Parse arguments needed for ELF
                     */
                    ++curarg;
                    typeset = TRUE;
                    goto parse_elf_arg;
                case 'i':
                case 'I':
                    /*
                     * Parse arguments needed for Image
                     */
                    ++curarg;
                    typeset = TRUE;
                    goto parse_image_arg;
                default:
                    break;
            }
        }
    }
    else
    {
        goto do_download;
    }

    switch (dltype)
    {
        case UIF_DLIO_SREC:
            goto parse_srec_arg;
        case UIF_DLIO_COFF:
            goto parse_coff_arg;
        case UIF_DLIO_ELF:
            goto parse_elf_arg;
        case UIF_DLIO_IMAGE:
            image_addr = (ADDRESS)__USER_SPACE;
            goto parse_image_arg;
        default:
            break;
    }
    goto do_download;

    parse_srec_arg:
        dltype = UIF_DLIO_SREC;
        while (curarg < argc)
        {
            if (argv[curarg][0] == '-')
            {
                switch (argv[curarg][1])
                {
                    case 'o':
                    case 'O':
                        if (++curarg < argc)
                        {
                            offset_to_addr =
                                get_value(argv[curarg],&success,BASE);
                            if (!success)
                            {
                                printf(INVALUE,argv[curarg]);
                                return;
                            }
                        }
                        else
                        {
                            printf("Error:  Offset not specified!\n");
                            return;
                        }
                        break;
                    default:
                        printf("Error:  Invalid option:  %s\n",argv[curarg]);
                        return;
                }
            }
            else
            {
                fn = argv[curarg];
            }

            ++curarg;
        }
        printf("Offset:  %#08X\n",offset_to_addr);
        goto do_download;

    parse_coff_arg:
        dltype = UIF_DLIO_COFF;
        while (curarg < argc)
        {
            switch (argv[curarg][0])
            {
                case '-':
                    printf("Error:  Invalid option:  %s\n",argv[curarg]);
                    return;
                default:
                    fn = argv[curarg];
                    break;
            }
            ++curarg;
        }
        goto do_download;

    parse_elf_arg:
        dltype = UIF_DLIO_ELF;
        while (curarg < argc)
        {
            switch (argv[curarg][0])
            {
                case '-':
                    printf("Error:  Invalid option:  %s\n",argv[curarg]);
                    return;
                default:
                    fn = argv[curarg];
                    break;
            }
            ++curarg;
        }
        goto do_download;

    parse_image_arg:
        dltype = UIF_DLIO_IMAGE;
        while (curarg < argc)
        {
            if (argv[curarg][0] == '-')
            {
                switch (argv[curarg][1])
                {
                    case 'a':
                    case 'A':
                        if (++curarg < argc)
                        {
                            image_addr =
                                get_value(argv[curarg],&success,BASE);
                            if (!success)
                            {
                                printf(INVALUE,argv[curarg]);
                                return;
                            }
                            if (!board_dlio_vda(image_addr))
                            {
                        printf("Error:  Invalid download address:  %#08X\n",
                                image_addr);
                                return;
                            }
                        }
                        else
                        {
                            printf("Error:  Address not specified!\n");
                            return;
                        }
                        break;
                    default:
                        printf("Error:  Invalid option:  %s\n",argv[curarg]);
                        return;
                }
            }
            else
            {
                fn = argv[curarg];
            }

            ++curarg;
        }
        printf("Address:  %#08X\n",image_addr);
        goto do_download;


    do_download:

    if (!board_dlio_init())
        return;

    /* Initialize network stack */
    net_init();

    /*
     * Valid filename
     */
    if (fn == NULL)
    {
        board_get_filename(fnbuf);
        fn = &fnbuf[0];
    }

    /*
     * If file type not explicitly specified, extract from filename
     */
    if (typeset == FALSE)
    {
        p = &fn[strlen(fn)];
        while ((*p != '.') && (p != fn))
            --p;
        if (*p == '.')
            ++p;
        if (strncasecmp(p,"SREC",3) == 0)
            dltype = UIF_DLIO_SREC;
        if (strncasecmp(p,"ELF",3) == 0)
            dltype = UIF_DLIO_ELF;
        if (strncasecmp(p,"COFF",3) == 0)
            dltype = UIF_DLIO_COFF;
        if (strncasecmp(p,"BIN",3) == 0)
            dltype = UIF_DLIO_IMAGE;
        if ((board_dltype = board_dlio_filetype(fn,p)) != UIF_DLIO_UNKNOWN)
            dltype = board_dltype;
    }

    board_get_server((unsigned char *)Server);

    printf("Downloading ");
    switch (dltype)
    {
        case UIF_DLIO_IMAGE:
            printf("Image"); break;
        case UIF_DLIO_SREC:
            printf("S-Record"); break;
        case UIF_DLIO_COFF:
            printf("COFF"); break;
        case UIF_DLIO_ELF:
            printf("ELF"); break;
        default:
            printf("Unknown"); break;
    }
    printf(" '%s' from %d.%d.%d.%d\n",
        fn,
        Server[0],
        Server[1],
        Server[2],
        Server[3]
    );

    success = TRUE;

    /*
     * Perform the TFTP download here....
     */
    switch (dltype)
    {
        case UIF_DLIO_IMAGE:
            if (tftp_read(&nif1, fn, Server))
            {
                download_image(image_addr);
                tftp_end(TRUE);
            }
            break;
        case UIF_DLIO_SREC:
            if (tftp_read(&nif1, fn, Server))
            {
                tftp_end(dn_download_srecord(offset_to_addr));
            }               
            break;
        case UIF_DLIO_COFF:
            if (tftp_read(&nif1, fn, Server))
            {
                download_coff();
                tftp_end(TRUE);
            }
            break;
        case UIF_DLIO_ELF:
            if(tftp_read(&nif1,fn,Server))
            {
                if (download_elf(1) != 1)
                    break;
                
                if(tftp_read(&nif1,fn,Server))
                {
                    tftp_end(download_elf(2));
                }
            }
            break;
        default:
            break;
    }

    board_dlio_done();
    cpu_cache_flush();

    disasm_last_address = cpu_pc_get();
    md_last_address = cpu_pc_get();
}

/********************************************************************/

#endif /* #ifdef DBUG_NETWORK */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -