This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C6657 串口固化DSP



您好,TI的专家;

    现在我想通过串口升级DSP程序,整个流程已经实现,不过没加载起来,发现写到flash的值和转换的dat文件不一样。

    1.通过论坛提供的转换工具转换的dat文件是字符类型的,不是16进制文件?

    2.查了下可不可以用winhex工具强制把dat文件转成16进制文件?或者Ti官方有没有类似的工具?

    3.如果方法2不行,是不是只能参照spi nor writer工程把dat文件转换一遍?

  • 是论坛哪里的转换工具?flash烧写程序本身没问题吧?
  • 你好 你的实现了没有?分享一下啊!非常感谢!我一直用nor flash 加载正确。
  • -output格式有intel/ti...各种的hex格式,你要熟悉hex的格式再转换成bin,附送个intel格式的hex转bin,不过这个是使用位flash模拟8位的,你需要把位扩展干掉.

    源码在笔记本上,稍候放上来.
  • #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <string.h>

    #define msg printf
    #define DEF_APP_FOOSET 0x20000//128KB, user defined inut value in argv[4] should match with boot loader's requirement.
    #define BL_OFFSET 0x1000//4KB
    #define DIR //"./"

    typedef enum {
    preamble = ':',
    separator = '\n',
    dataType = '0',
    eofType = '1',
    rebaseType = '4'
    } ihexConst;

    #define IHEX_SZ_MAX 0x20
    #define BYTE_HEX_SZ 2
    #define DB_BYTE_SZ 2
    typedef uint8_t Hex;
    typedef struct {
    Hex preamble;
    Hex size[BYTE_HEX_SZ];
    Hex offset[DB_BYTE_SZ * BYTE_HEX_SZ];
    Hex type[BYTE_HEX_SZ];
    Hex payload[IHEX_SZ_MAX * DB_BYTE_SZ];
    Hex checksum[BYTE_HEX_SZ];
    Hex separator;
    Hex rsvd[8];
    } IHexRecord;

    #define hex2b(hex) ((hex <= '9') ? (hex & 0xf) : (hex - 'A' + 10))

    static __inline uint8_t hex2byte(const Hex* hex) {
    register uint8_t h = *hex++;
    register uint8_t b = hex2b(h) << 4;
    h = *hex;
    b |= hex2b(h);
    return b;
    }

    static __inline uint16_t hex2db(register const Hex* hex, char be) {
    register uint16_t db;
    if (be) {
    db = hex2byte(hex) << 8;
    db |= hex2byte(hex + BYTE_HEX_SZ);
    } else {
    db = hex2byte(hex);
    db |= hex2byte(hex + BYTE_HEX_SZ) << 8;
    }
    return db;
    }

    static __inline void hex2nBytes(register const Hex* hex, register int16_t n, register uint8_t* bytes) {
    while(--n >= 0) {
    *bytes++ = hex2byte(hex);
    hex += BYTE_HEX_SZ;
    }
    }


    static void b2s(uint8_t* buf, int8_t sz) {
    if (sz == 0) return;

    while (--sz >= 0) {
    *(buf + ((sz << 1) + 1)) = *(buf + sz);
    *(buf + (sz << 1)) = 0xff;
    }
    }

    #define USE_APP (mask&1)
    #define USE_UP (mask&2)
    #define BE (mask&4)
    #define EXT_BIT (mask&8)
    int main(int argc, char* argv[]) {
    /* help info. */
    if (argc == 1) {
    printf("usage:\n"
    "\thex2bin image.bin mask(ext-16 | BE | use updater.hex | app.hex) 65536(|...align)\n"
    "\tconvert .hex file of bootloader, updater & app(if they are used) to image.bin with assigned endian & ext.\n");
    return -1;
    }


    /* action check. */
    unsigned mask = (unsigned)(atol(argv[2]));
    char be = BE;
    char ext = EXT_BIT;
    unsigned appOffset = USE_APP
    ? ((argc == 4) ? (unsigned)(atol(argv[3])) : DEF_APP_FOOSET)
    : 0;
    if (ext) appOffset <<= 1;
    printf("convert bootloader.hex updater.hex(%c) & app.hex(%c, with %d offset) to %s with %s endian & %s bit extension.\n",
    USE_UP ? 'Y' : 'N', USE_APP ? 'Y' : 'N', appOffset, argv[1], be ? "big" : "little", ext ? "8-16" : "no");


    /* boot loader */

    printf("convert boot loader...\n");
    char* file = DIR"bootloader.hex";
    FILE* ifp = fopen(file, "r");
    if (NULL == ifp) {
    perror(NULL);
    msg("\thex file %s not exist!\n", file);
    return -2;
    }

    file = argv[1];
    FILE* ofp = fopen(file, "w");
    if (NULL == ofp) {
    msg("\tcreat output file %s failed!\n", file);
    perror(NULL);
    return -3;
    }

    IHexRecord ihex;
    uint32_t rbase = 0;
    uint16_t roff;
    int8_t rsz;
    char rt;

    uint32_t fsz = 0;//file size

    uint8_t dummy[IHEX_SZ_MAX * 2];
    do {
    (void)fgets((char*)&ihex, sizeof(IHexRecord), ifp);
    if (preamble != ihex.preamble) {
    printf("invalid preamble %x-%c in file.\n", ihex.preamble, ihex.preamble);
    return -4;
    }
    rt = ihex.type[1];

    if (rt == dataType) {
    rsz = hex2byte(&ihex.size[0]);
    if (rsz > IHEX_SZ_MAX) {
    printf("invalid record size: %x.\n", rsz);
    return -5;
    }
    roff = hex2db(&ihex.offset[0], be);
    hex2nBytes(&ihex.payload[0], rsz, &dummy[0]);
    if (ext) {
    b2s(&dummy[0], rsz);
    rsz <<= 1;
    }
    fwrite(&dummy, rsz, 1, ofp);
    fsz += rsz;
    } else if(rt == rebaseType) {
    rbase = (uint32_t)(hex2db(&ihex.payload[0], be) << 16);
    printf("\tebase @%x:", rbase);
    }

    msg(".");fflush(stdout);
    } while (rt != eofType);
    msg("\n\t%d size for bootloader.\n", fsz);

    unsigned rest = (ext ? (BL_OFFSET << 1) : BL_OFFSET) - fsz;
    memset(&dummy[0], 0xff, sizeof(dummy));
    fwrite(&dummy, rest % sizeof(dummy), 1, ofp);
    fsz += (rest % sizeof(dummy));

    rest &= ~(sizeof(dummy) - 1);
    fsz += rest;
    for (rest /= sizeof(dummy); rest != 0; rest--)
    fwrite(&dummy, sizeof(dummy), 1, ofp);

    fclose(ifp);


    /* updater & app to bin */
    ....
    }
  • 您好,谢谢您的工具,自己也写了个dat转bin的小工具,先将就用着,等等把这系列的工具整理一下,不能老用bat处理。
  • 感谢分享!
  • 感谢分享!

  • 您好,方便将您的源码分享出来吗?我最近也在做这方面的内容,谢谢,我的邮箱zy979228369@hotmail.com
  • 您好,请问您实现C6657串口固话Nor Flash程序了吗,能否分享一下方法和源码,我最近也在做这方面的内容,我的邮箱yly1991@mail.ustc.edu.cn,非常感谢!

  • 您好,请问您实现C6657串口固话Nor Flash程序了吗,能否分享一下方法和源码,我最近也在做这方面的内容,我的邮箱yly1991@mail.ustc.edu.cn,非常感谢!

  • 没有实现了!
  • 给你发邮件,发不过去,你加我qq:979228369吧