KittenBot / uf2-meowbit

bootloader for meowbit based on https://github.com/mmoskal/uf2-stm32f
Other
13 stars 7 forks source link

[2.7.5] uf2 files not built due to --carray option #1

Open shazz opened 5 years ago

shazz commented 5 years ago

Hi, There are 2 issues with the uf2conv.py:

python uf2/utils/uf2conv.py --carray build/meowbit/bootloader.bin -o build/meowbit/bootloader.c
Traceback (most recent call last):
  File "uf2/utils/uf2conv.py", line 293, in <module>
    main()
  File "uf2/utils/uf2conv.py", line 269, in main
    outbuf = convert_to_carray(inpbuf)
  File "uf2/utils/uf2conv.py", line 84, in convert_to_carray
    print(len(file_content[i]))
TypeError: object of type 'int' has no len()
make: *** [rules.mk:39: build/meowbit/flasher.uf2] Error 1

To fix them I changed:

def convert_to_carray(file_content):
    outp = "const unsigned char bindata[] __attribute__((aligned(16))) = {"
    for i in range(len(file_content)):
        if i % 16 == 0:
            outp += "\n"
        outp += "0x%02x, " % (file_content[i])
    outp += "\n};\n"
    return outp

and

        if args.output:
            if isinstance(outbuf, str):
                outbuf = str.encode(outbuf)
            write_file(args.output, outbuf)

Else the bootloader.c won't be generated

MinatsuT commented 4 years ago

I have faced the same problem. I found that this error occurs when the installed "python" is python3.

If "python" is python2, as in Ubuntu 18.04, this error does not occur. This seems to be the reason why this error is rarely reported.