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

📄 fl_wrt.c

📁 Sharp LH7A400 BSP平台无关部分的代码,有很高的参考价值,尤其是系统架构设计上,设计成移植度很高的BSP.
💻 C
📖 第 1 页 / 共 2 页
字号:
                /* Next block */
                block++;
            }

            printf("\n");
            fclose(pfile);
        }
        else
        {
            /* Cannot find input file */
            printf("Error - cannot open file %s\n", filename);
            status = -1;
        }
    }
    else
    {
        /* Not a valid FLASH offset address */
        printf("Not a valid FLASH offset address - program addresses "
            "must be on a block boundary - use -l option to generate "
            "a list of block addresses\n");
        status = -1;
    }

    return status;
}

/***********************************************************************
 *
 * Function: dispstats
 *
 * Purpose: Display programming parameters
 *
 * Processing:
 *     Display FLASH programming parameters if the query flag is set.
 *
 * Parameters:
 *     show: If set to 0, the FLASH program display will not be shown
 *
 * Outputs: None
 *
 * Returns:Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void dispstats(INT_32 show)
{
    if (show != 0)
    {
        printf("FLASH base address:        0x%08x\n",
            (INT_32) flashbase);
        printf("FLASH program address:     0x%08x\n",
            (flashbase + flashoffset));
        printf("FLASH size (bytes):        %d\n", flashsize);
        printf("Number of FLASH blocks:    %d\n",
            cfi_get_block_count());
        printf("Verify after write:        ");
        if (verify == 1)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
        printf("Erase entire device:       ");
        if (erase == 1)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
        printf("File to FLASH:             \n");
        printf("    %s\n", filename);
    }
}

/***********************************************************************
 *
 * Function: main
 *
 * Purpose: Main entry point
 *
 * Processing:
 *     Set the default states of the FLASH programming variables. Loop
 *     through all the passed arguments to the main() program (except
 *     the filename), overwriting the default states of the FLASH
 *     variables based ont the parsed arguments. If no errors occurred
 *     during parsing or the help display wasn't shown, then perform
 *     functions to program FLASH.
 *
 * Parameters:
 *     argc: Number of arguments passed through main
 *     argv: Pointer to the list of arguments passed through main
 *
 * Outputs: None
 *
 * Returns: (-1) on failure, otherwise 0.
 *
 * Notes: None
 *
 **********************************************************************/
INT_32 main(INT_32 argc, CHAR *argv[])
{
    CHAR tmp;
    BOOL_32 listblks;
    UNS_32 block;
    INT_32 idx = 1, exitmode = 0, status = 0;
    INT_32 requestbase = 1, requestoffset = 1, interactive = 1;

    /* Setup defaults */
    flashsize = 0;
    verify = 0;
    erase = 0;
    query = 0;
    flashbase = 0;
    flashoffset = 0;
    listblks = FALSE;

    /* Argument parsing loop - this assumes the last argument is the
       filename that will be programmed into FLASH */
    while ((idx < (argc - 1)) && (exitmode == 0))
    {
        switch (argv[idx][1])
        {
            case 'v':
                /* Enable verify after write */
                verify = 1;
                break;

            case 'h':
                /* Display options help and exit program */
                showhelp();
                exitmode = 1;
                break;

            case 'q':
                /* Display programming info */
                query = 1;
                break;

            case 'e':
                /* Erase entire FLASH device prior to programming */
                erase = 1;
                break;

            case 'd':
                /* Disable interactive prompts */
                interactive = 0;
                break;

            case 'l':
                /* Display a list of block addresses */
                listblks = TRUE;
                break;

            case 'b':
                /* Set FLASH device base address */
                flashbase = atol(&argv[idx][3]);
                requestbase = 0;
                break;

            case 'o':
                /* Set FLASH programming offset */
                flashoffset = atol(&argv[idx][3]);
                requestoffset = 0;
                break;

            default:
                /* Unknown option, exit */
                printf("Error - invalid option\n");
                exitmode = 1;
                status = -1;
                showhelp();
                break;
        }

        idx++;
    }

    /* Only continue if not in exitmode */
    if (exitmode == 0)
    {
        /* Display programming information banner */
        printf("\n\nARM AXD Flash Programming Utility for the "
            "SDK7A400 EVB\n\n");

        /* If interactive, check address and offset */
        if (interactive == 1)
        {
            /* Get base address and offset for device */
            flashgetaddroffs();
        }

        /* Make sure that FLASH exists at base address */
        status = flashdetect();

        if ((listblks == TRUE) && (status == 0))
        {
            block = 0;
            while (block < cfi_get_block_count())
            {
                printf("Block %d at address 0x%08x\n", block,
                        cfi_get_block_address(block));
                block++;
            }

            exitmode = 1;
        }
        else if (status == 0)
        {
            /* Get filename of image to program into FLASH */
            strcpy(filename, argv[idx]);

            flashsize = cfi_getdevsize();
            dispstats(1);

            /* Make sure user wants to overwrite FLASH */
            printf("Are you sure you want to program FLASH (y/n)?");
            exitmode = -1;
            while (exitmode == -1)
            {
                tmp = getchar();
                if ((tmp == 'y') || (tmp == 'Y'))
                {
                    exitmode = 0;
                }
                else if ((tmp == 'n') || (tmp == 'N'))
                {
                    exitmode = 1;
                }
            }
        }

        if (exitmode == 0)
        {
            /* Query the FLASH device to get it's geometry */
            status = flashdetect();
            if (status == 0)
            {
                flashsize = cfi_getdevsize();
                if (interactive == 0)
                {
                    /* Only display programming parameters if they were
                       not perviously displayed */
                    dispstats(query);
                }

                /* Erase entire device if needed */
                if (erase == 1)
                {
                    flasherasedevice();
                }

                /* Program device */
                status = flashprogram();

                /* Display error message if status isn't 0 */
                if (status != 0)
                {
                    printf("Error programming FLASH!\n");
                }
                else
                {
                    printf("FLASH programming completed\n");
                    if (verify == 1)
                    {
                        printf("FLASH verify not yet implemented.\n");
                    }
                }
            }
            else
            {
                printf("FLASH not detected at address 0x%08x\n",
                    flashbase);
            }
        }
    }

    cfi_exitprog_mode((UNS_32 *) flashbase);

    return status;
}

⌨️ 快捷键说明

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