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

📄 rockbox_flash.c

📁 编译后直接运行的MP3播放器全部C语言源代码 一个包含FAT文件系统、系统引导 Boot、FLASH Driver等内容的
💻 C
📖 第 1 页 / 共 2 页
字号:
    read += sizeof(tImageHeader); /* to be programmed, but not part of the                                     file */    do    {        for (i=0; i<read; i++)        {            if (pos[i] != sector[i])            {                failures++;            }        }                pos += SECTORSIZE;        read = rb->read(fd, sector, (size > SECTORSIZE) ? SECTORSIZE : size);        /* payload for next sector */        size -= read;    } while (read);        rb->close(fd);        return failures;}/***************** User Interface Functions *****************/int WaitForButton(void){    int button;        do    {        button = rb->button_get(true);    } while (button & BUTTON_REL);        return button;}/* helper for DoUserDialog() */void ShowFlashInfo(tFlashInfo* pInfo, tImageHeader* pImageHeader){    char buf[32];    if (!pInfo->manufacturer)    {        rb->lcd_puts_scroll(0, 0, "Flash: M=?? D=??");    }    else    {        if (pInfo->size)        {            rb->snprintf(buf, sizeof(buf), "Flash size: %d KB",                         pInfo->size / 1024);            rb->lcd_puts_scroll(0, 0, buf);        }        else        {            rb->lcd_puts_scroll(0, 0, "Unsupported chip");        }            }    if (pImageHeader)    {        rb->snprintf(buf, sizeof(buf), "Image at %d KB",                     ((UINT8*)pImageHeader - FB) / 1024);        rb->lcd_puts_scroll(0, 1, buf);    }    else    {        rb->lcd_puts_scroll(0, 1, "No image found!");    }}/* Kind of our main function, defines the application flow. */#ifdef HAVE_LCD_BITMAP/* recorder version */void DoUserDialog(char* filename, bool show_greet){    tImageHeader ImageHeader;    tFlashInfo FlashInfo;    static char buf[MAX_PATH];    int button;    int rc; /* generic return code */    UINT32 space, aligned_size, true_size;    UINT8* pos;    int memleft;        rb->lcd_setfont(FONT_SYSFIXED);    /* "allocate" memory */    sector = rb->plugin_get_buffer(&memleft);    if (memleft < SECTORSIZE) /* need buffer for a flash sector */    {        rb->splash(HZ*3, true, "Out of memory");        return; /* exit */    }    pos = (void*)GetSecondImage();    rc = GetFlashInfo(&FlashInfo);    ShowFlashInfo(&FlashInfo, (void*)pos);    rb->lcd_update();    if (FlashInfo.size == 0) /* no valid chip */    {        rb->splash(HZ*3, true, "Not flashable");        return; /* exit */    }    else if (pos == 0)    {        rb->splash(HZ*3, true, "No image");        return; /* exit */    }        if (show_greet)    {        rb->lcd_puts(0, 3, "using file:");        rb->lcd_puts_scroll(0, 4, filename);         rb->lcd_puts(0, 6, "[F1] to check file");        rb->lcd_puts(0, 7, "other key to exit");        rb->lcd_update();        if (WaitForButton() != BUTTON_F1)        {            return;        }        rb->lcd_clear_display();    }    rb->lcd_puts(0, show_greet ? 0 : 3, "Checking...");    rb->lcd_update();    space = FlashInfo.size - (pos-FB + sizeof(ImageHeader));    /* size minus start */        rc = CheckImageFile(filename, space, &ImageHeader, pos);    if (rc != eOK)    {        rb->lcd_clear_display(); /* make room for error message */        show_greet = true; /* verbose */    }    rb->lcd_puts(0, show_greet ? 0 : 3, "Checked:");    switch (rc) {        case eOK:            rb->lcd_puts(0, show_greet ? 0 : 4, "File OK.");            break;    case eNotUCL:            rb->lcd_puts(0, 1, "File not UCL ");            rb->lcd_puts(0, 2, "compressed.");            rb->lcd_puts(0, 3, "Use uclpack --2e");            rb->lcd_puts(0, 4, " --10 rockbox.bin");            break;    case eWrongAlgorithm:            rb->lcd_puts(0, 1, "Wrong algorithm");            rb->lcd_puts(0, 2, "for compression.");            rb->lcd_puts(0, 3, "Use uclpack --2e");            rb->lcd_puts(0, 4, " --10 rockbox.bin");            break;    case eFileNotFound:            rb->lcd_puts(0, 1, "File not found:");            rb->lcd_puts_scroll(0, 2, filename);            break;    case eTooBig:            rb->lcd_puts(0, 1, "File too big,");            rb->lcd_puts(0, 2, "won't fit in chip.");            break;    case eTooSmall:            rb->lcd_puts(0, 1, "File too small.");            rb->lcd_puts(0, 2, "Incomplete?");            break;    case eReadErr:            rb->lcd_puts(0, 1, "File read error.");            break;    case eMultiBlocks:            rb->lcd_puts(0, 1, "File invalid.");            rb->lcd_puts(0, 2, "Blocksize");            rb->lcd_puts(0, 3, " too small?");            break;    default:            rb->lcd_puts(0, 1, "Check failed.");            break;    }    if (rc == eOK)    {    /* was OK */        rb->lcd_puts(0, 6, "[F2] to program");        rb->lcd_puts(0, 7, "other key to exit");    }    else    { /* error occured */        rb->lcd_puts(0, 6, "Any key to exit");    }    rb->lcd_update();    button = WaitForButton();    if (rc != eOK || button != BUTTON_F2)    {        return;    }        true_size = ImageHeader.size;    aligned_size = ((sizeof(tImageHeader) + true_size + SECTORSIZE-1) &                    ~(SECTORSIZE-1)) - sizeof(tImageHeader); /* round up to                                                                next flash                                                                sector */    ImageHeader.size = aligned_size; /* increase image size such that we reach                                        the next sector */        rb->lcd_clear_display();    rb->lcd_puts_scroll(0, 0, "Programming...");    rb->lcd_update();    rc = ProgramImageFile(filename, pos, &ImageHeader, UCL_HEADER, true_size);    if (rc)    {   /* errors */        rb->lcd_clear_display();        rb->snprintf(buf, sizeof(buf), "%d errors", rc);        rb->lcd_puts(0, 0, "Error:");        rb->lcd_puts(0, 1, "Programming fail!");        rb->lcd_puts(0, 2, buf);        rb->lcd_update();        button = WaitForButton();    }        rb->lcd_clear_display();    rb->lcd_puts_scroll(0, 0, "Verifying...");    rb->lcd_update();    rc = VerifyImageFile(filename, pos, &ImageHeader, UCL_HEADER, true_size);    rb->lcd_clear_display();    if (rc == 0)    {        rb->lcd_puts(0, 0, "Verify OK.");    }    else    {        rb->snprintf(buf, sizeof(buf), "%d errors", rc);        rb->lcd_puts(0, 0, "Error:");        rb->lcd_puts(0, 1, "Verify fail!");        rb->lcd_puts(0, 2, buf);        rb->lcd_puts(0, 3, "Use safe image");        rb->lcd_puts(0, 4, "if booting hangs:");        rb->lcd_puts(0, 5, "F1 during power-on");    }    rb->lcd_puts(0, 7, "Any key to exit");    rb->lcd_update();    WaitForButton();}#else /* #ifdef HAVE_LCD_BITMAP *//* Player version */void DoUserDialog(char* filename, bool show_greet){    tImageHeader ImageHeader;    tFlashInfo FlashInfo;    static char buf[MAX_PATH];    int button;    int rc; /* generic return code */    UINT32 space, aligned_size, true_size;    UINT8* pos;    int memleft;    /* "allocate" memory */    sector = rb->plugin_get_buffer(&memleft);    if (memleft < SECTORSIZE) /* need buffer for a flash sector */    {        rb->splash(HZ*3, true, "Out of memory");        return; /* exit */    }    pos = (void*)GetSecondImage();    rc = GetFlashInfo(&FlashInfo);    if (show_greet)    {        ShowFlashInfo(&FlashInfo, (void*)pos);        WaitForButton();    }    if (FlashInfo.size == 0) /* no valid chip */    {        rb->splash(HZ*3, true, "Not flashable");        return; /* exit */    }    else if (pos == 0)    {        rb->splash(HZ*3, true, "No image");        return; /* exit */    }        if (show_greet)    {        rb->snprintf(buf, sizeof(buf), "File: %s", filename);        rb->lcd_puts_scroll(0, 0, buf);        rb->lcd_puts_scroll(0, 1, "[Menu] to check file, other key to exit");        if (WaitForButton() != BUTTON_MENU)        {            return;        }        rb->lcd_clear_display();    }    rb->lcd_puts(0, 0, "Checking...");    space = FlashInfo.size - (pos-FB + sizeof(ImageHeader));    /* size minus start */        rc = CheckImageFile(filename, space, &ImageHeader, pos);    rb->lcd_puts(0, 0, "Checked:");    switch (rc) {        case eOK:            rb->lcd_puts(0, 1, "File OK.");            rb->sleep(HZ*1);            break;    case eNotUCL:            rb->lcd_puts_scroll(0, 1, "File not UCL compressed.");            break;    case eWrongAlgorithm:            rb->lcd_puts_scroll(0, 1, "Wrong compression algorithm.");            break;    case eFileNotFound:            rb->lcd_puts_scroll(0, 1, "File not found.");            break;    case eTooBig:            rb->lcd_puts_scroll(0, 1, "File too big.");            break;    case eTooSmall:            rb->lcd_puts_scroll(0, 1, "File too small. Incomplete?");            break;    case eReadErr:            rb->lcd_puts_scroll(0, 1, "File read error.");            break;    case eMultiBlocks:            rb->lcd_puts_scroll(0, 1, "File invalid. Blocksize too small?");            break;    default:            rb->lcd_puts_scroll(0, 1, "Check failed.");            break;    }    if (rc == eOK)    {    /* was OK */        rb->lcd_clear_display();        rb->lcd_puts_scroll(0, 0, "[ON] to program,");        rb->lcd_puts_scroll(0, 1, "other key to exit.");    }    else    { /* error occured */        WaitForButton();        rb->lcd_clear_display();        rb->lcd_puts_scroll(0, 0, "Flash failed.");        rb->lcd_puts_scroll(0, 1, "Any key to exit.");    }    button = WaitForButton();    if (rc != eOK || button != BUTTON_ON)    {        return;    }        true_size = ImageHeader.size;    aligned_size = ((sizeof(tImageHeader) + true_size + SECTORSIZE-1) &                    ~(SECTORSIZE-1)) - sizeof(tImageHeader); /* round up to                                                                next flash                                                                sector */    ImageHeader.size = aligned_size; /* increase image size such that we reach                                        the next sector */        rb->lcd_clear_display();    rb->lcd_puts_scroll(0, 0, "Programming...");    rc = ProgramImageFile(filename, pos, &ImageHeader, UCL_HEADER, true_size);    if (rc)    {   /* errors */        rb->lcd_clear_display();        rb->snprintf(buf, sizeof(buf), "%d errors", rc);        rb->lcd_puts_scroll(0, 0, "Programming failed!");        rb->lcd_puts_scroll(0, 1, buf);        button = WaitForButton();    }        rb->lcd_clear_display();    rb->lcd_puts_scroll(0, 0, "Verifying...");    rc = VerifyImageFile(filename, pos, &ImageHeader, UCL_HEADER, true_size);    rb->lcd_clear_display();    if (rc == 0)    {        rb->lcd_puts(0, 0, "Verify OK.");    }    else    {        rb->snprintf(buf, sizeof(buf), "Verify fail! %d errors", rc);        rb->lcd_puts_scroll(0, 0, buf);        rb->lcd_puts_scroll(0, 1, "Use safe image if booting hangs: [Menu] during power-on");        button = WaitForButton();    }}#endif /* not HAVE_LCD_BITMAP *//***************** Plugin Entry Point *****************/enum plugin_status plugin_start(struct plugin_api* api, void* parameter){    char* filename;    bool show_greet;    /* this macro should be called as the first thing you do in the plugin.       it test that the api version and model the plugin was compiled for       matches the machine it is running on */    TEST_PLUGIN_API(api);    if (parameter == NULL)    {        filename = DEFAULT_FILENAME;        show_greet = true;    }    else    {        filename = (char*) parameter;         show_greet = false;    }        rb = api; /* copy to global api pointer */    /* now go ahead and have fun! */    DoUserDialog(filename, show_greet);    return PLUGIN_OK;}#endif /* #ifndef SIMULATOR */

⌨️ 快捷键说明

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