bouffalolab / bouffalo_sdk

BouffaloSDK is the IOT and MCU software development kit provided by the Bouffalo Lab Team, supports all the series of Bouffalo chips. Also it is the combination of bl_mcu_sdk and bl_iot_sdk
Apache License 2.0
349 stars 123 forks source link

Flash tool difference #93

Closed sakumisu closed 1 year ago

sakumisu commented 1 year ago

Abstract

For now we have these flashtools:

Devcube has mcu and iot, mcu is only used to flash firmware, iot is used to flash boot2/mfg/user bin/dts/toml, clock and flash config are set in devcube, and generates whole bin( firmware + bootheader) at last.

Flashcube is only used to flash bin with address, no other functions, and firmware must have bootheader, other bins no need.So it is very easier to use. How to write ini please see https://bl-mcu-sdk.readthedocs.io/zh_CN/latest/get_started/flash_prog.html.

Use

We should know that new firmware = old firmware (without bootheader) + bootheader = whole img bin generated by devcube

Old firmware (without bootheader)

Please do not use flashcube(gui or cmd), use devcube instead.

Old firmware (with bootheader)

You can use devcube or flashcube(gui or cmd), if you use bl808 multi groups , please use devcube

New firmware (with bootheader)

Use flashcube(gui or cmd)

cjacker commented 1 year ago

After BLFlashCommand added and the commit [update][board] enable fw header for new flash tool . it result in:

My Questions:

BLFlashCommand error output:

./BLFlashCommand --interface uart --port /dev/ttyACM0 --chipname bl702 --config ./flash_prog_cfg.ini
['./BLFlashCommand', '--interface', 'uart', '--port', '/dev/ttyACM0', '--chipname', 'bl702', '--config', './flash_prog_cfg.ini']
[10:27:10.357] - Serial port is /dev/ttyACM0
[10:27:10.357] - ==================================================
[10:27:10.359] - Program Start
[10:27:10.359] - ========= eflash loader cmd arguments =========
[10:27:10.360] - serial port is /dev/ttyACM0
[10:27:10.360] - chiptype: bl702
[10:27:10.360] - cpu_reset=False
[10:27:10.377] - ========= Interface is uart =========
[10:27:10.377] - Eflash load bin file: /home/cjacker/bouffalo_flash_cube/chips/bl702/eflash_loader/eflash_loader_32m.bin
[10:27:10.377] - ========= load eflash_loader.bin =========
[10:27:10.377] - Load eflash_loader.bin via uart
[10:27:10.377] - ========= image load =========
[10:27:10.389] - default set DTR high
[10:27:10.490] - usb serial port
[10:27:10.541] - clean buf
[10:27:10.542] - send sync
[10:27:10.753] - ack is b'4f4b464c0201'
[10:27:10.784] - shake hand success
[10:27:10.794] - get_boot_info
[10:27:10.798] - data read is b'0100020700000000931d000027000004000043575c4cb97c'
[10:27:10.798] - ========= ChipID: 000043575c4cb97c =========
[10:27:10.798] - last boot info: None
[10:27:10.798] - sign is 0 encrypt is 0
[10:27:10.798] - [Errno 2] No such file or directory: '/home/cjacker/bouffalo_flash_cube/chips/bl702/eflash_loader/eflash_loader_32m.bin'
Traceback (most recent call last):
  File "libs/base/bflb_img_loader.py", line 941, in img_load_process
  File "libs/base/bflb_img_loader.py", line 802, in img_load_main_process
FileNotFoundError: [Errno 2] No such file or directory: '/home/cjacker/bouffalo_flash_cube/chips/bl702/eflash_loader/eflash_loader_32m.bin'
[10:27:10.800] - Load helper bin time cost(ms): 422.57763671875
[10:27:10.800] - {"ErrorCode": "0003","ErrorMsg":"BFLB LOAD HELP BIN FAIL"}
[10:27:10.802] - Burn Retry
[10:27:10.802] - Burn return with retry fail
sakumisu commented 1 year ago

ALL are officiial. If bflb-mcu-tool removed bootheader and other functions, it is BLFlashCommand

sakumisu commented 1 year ago

bin has ignored by .gitignore.

cjacker commented 1 year ago

Simple questions:

I build a simple led_blink project as usual with git master, the result is 'sipeed_rv_debugger_plus_blink.bin'.

sakumisu commented 1 year ago

please see doc.

Fishwaldo commented 1 year ago

Can I suggest you setup GitHub actions to build all the examples with different Chips and then sync from internal via pull requests instead. Then you can catch build errors before they break things for everyone?

Also, can you start tagging releases so we can pick stable commits?

sakumisu commented 1 year ago

sipeed_rv_debugger_plus_blink.bin add bootheader then you can use new flash tool.

cjacker commented 1 year ago

It not works at all, as I mentioned above, the 'eflash_loader_32m.bin' is missing, where can I find it?

$ make flash COMX=/dev/ttyACM0
./../../tools/bflb_tools/bouffalo_flash_cube/BLFlashCommand \
--interface=uart \
--baudrate=2000000 \
--port=/dev/ttyACM0 \
--chipname=bl702 \
--cpu_id= \
--config=flash_prog_cfg.ini
['./../../tools/bflb_tools/bouffalo_flash_cube/BLFlashCommand', '--interface=uart', '--baudrate=2000000', '--port=/dev/ttyACM0', '--chipname=bl702', '--cpu_id=', '--config=flash_prog_cfg.ini']
[11:01:17.957] - Serial port is /dev/ttyACM0
[11:01:17.958] - ==================================================
[11:01:17.960] - Program Start
[11:01:17.960] - ========= eflash loader cmd arguments =========
[11:01:17.961] - serial port is /dev/ttyACM0
[11:01:17.961] - chiptype: bl702
[11:01:17.962] - cpu_reset=False
[11:01:17.980] - ========= Interface is uart =========
[11:01:17.980] - Eflash load bin file: /home/cjacker/bl_mcu_sdk/tools/bflb_tools/bouffalo_flash_cube/chips/bl702/eflash_loader/eflash_loader_32m.bin
[11:01:17.980] - ========= load eflash_loader.bin =========
[11:01:17.980] - Load eflash_loader.bin via uart
[11:01:17.980] - ========= image load =========
[11:01:17.993] - default set DTR high
[11:01:18.093] - usb serial port
[11:01:18.144] - clean buf
[11:01:18.145] - send sync
[11:01:18.356] - ack is b'4f4b464c0201'
[11:01:18.386] - shake hand success
[11:01:18.397] - get_boot_info
[11:01:18.399] - data read is b'0100020700000000931d000027000004000043575c4cb97c'
[11:01:18.400] - ========= ChipID: 000043575c4cb97c =========
[11:01:18.400] - last boot info: None
[11:01:18.400] - sign is 0 encrypt is 0
[11:01:18.400] - [Errno 2] No such file or directory: '/home/cjacker/bl_mcu_sdk/tools/bflb_tools/bouffalo_flash_cube/chips/bl702/eflash_loader/eflash_loader_32m.bin'
Traceback (most recent call last):
  File "libs/base/bflb_img_loader.py", line 941, in img_load_process
  File "libs/base/bflb_img_loader.py", line 802, in img_load_main_process
FileNotFoundError: [Errno 2] No such file or directory: '/home/cjacker/bl_mcu_sdk/tools/bflb_tools/bouffalo_flash_cube/chips/bl702/eflash_loader/eflash_loader_32m.bin'
[11:01:18.400] - Load helper bin time cost(ms): 419.472900390625
[11:01:18.400] - {"ErrorCode": "0003","ErrorMsg":"BFLB LOAD HELP BIN FAIL"}
[11:01:18.402] - Burn Retry
[11:01:18.402] - Burn return with retry fail
sakumisu commented 1 year ago

I have said it is ignored by gitignore.

sakumisu commented 1 year ago

Please update commit.

cjacker commented 1 year ago

Please update commit.

OK. Thanks for your on-line support.

I noticed you just commit in all bin files. after "git pull" again, it works now.

Please consider to provide 'BLFlashCommand' and bootloaders' source codes when your time is available.

sakumisu commented 1 year ago

Flash tool involved security, so we cannot release source code, sorry.

cjacker commented 1 year ago

OK, finally I figured out how to deal with new firmware with blisp and bflb-mcu-tool.

new firmware add a 4k(0x1000) size section '.fw_header' at the start of final elf, and it can be stripped by :

tail -c +4097 new_firmware.bin > old_firmware.bin
cjacker commented 1 year ago

Flash tool involved security, so we cannot release source code, sorry.

Close source of 'bin' files should be OK. For BLFlashCommand, is it also have something related to security?

Only binary release will cause some issues, for example, if the user's working env is ARM or RISCV.

Update: After a quick try, The 'BLFlashCommand' is a pyinstaller package and can be extracted/decompiled without any issue. All private libs in PYZ package can be extracted/decompiled, such as :

 'libs.base.bl616.bootheader_cfg_keys': (0, 838883, 1950),
 'libs.base.bl616.chiptype_patch': (0, 840833, 184),
 'libs.base.bl616.cklink_load_cfg': (0, 841017, 204),
 'libs.base.bl616.flash_select_do': (0, 841221, 2351),
 'libs.base.bl616.img_create_do': (0, 843572, 8536),
 'libs.base.bl616.jlink_load_cfg': (0, 852108, 204),
 'libs.base.bl616.openocd_load_cfg': (0, 852312, 207),
 'libs.base.bl702': (3, 852519, 52),
 'libs.base.bl702.bootheader_cfg_keys': (0, 852571, 1277),
 'libs.base.bl702.chiptype_patch': (0, 853848, 427),
 'libs.base.bl702.cklink_load_cfg': (0, 854275, 207),
 'libs.base.bl702.flash_select_do': (0, 854482, 1141),
 'libs.base.bl702.img_create_do': (0, 855623, 4982),
 'libs.base.bl702.jlink_load_cfg': (0, 860605, 206),
 'libs.base.bl702.openocd_load_cfg': (0, 860811, 208),
 'libs.base.bl702l': (3, 861019, 52),
 'libs.base.bl702l.bootheader_cfg_keys': (0, 861071, 1445),
 'libs.base.bl702l.chiptype_patch': (0, 862516, 427),
 'libs.base.bl702l.cklink_load_cfg': (0, 862943, 208),
 'libs.base.bl702l.flash_select_do': (0, 863151, 2362),
 'libs.base.bl702l.img_create_do': (0, 865513, 5173),
 'libs.base.bl702l.jlink_load_cfg': (0, 870686, 207),
 'libs.base.bl702l.openocd_load_cfg': (0, 870893, 209),

I think it's meaningless to close the source codes of BLFlashCommand.

BLFlashCommand.py screenshot-2023-02-27-13-02-36

bl616 bootheader_cfg_keys.py screenshot-2023-02-27-13-01-56 .

sakumisu commented 1 year ago

OK, finally I figured out how to deal with new firmware with blisp and bflb-mcu-tool.

new firmware have a section '.fw_header' added to final elf and from the building process output:

Image Offset:0x1000

The '.fw_header' section could be removed by objcopy? but I did not try.

using blisp with '-l 0x1000' and blfb-mcu-tool with '--addr 0x1000', these tool can program new firmware correctly and works.

because these tool use whole bin, so the same with new flash tool.

gamelaster commented 1 year ago

@cjacker blisp should accept those images with boot header via IOT command, although, this will probably change in future, as blisp needs some refactoring together with CLI commands API change, to be able to properly address requirements of multi-core chips (BL808)

cjacker commented 1 year ago

@cjacker blisp should accept those images with boot header via IOT command, although, this will probably change in future, as blisp needs some refactoring together with CLI commands API change, to be able to properly address requirements of multi-core chips (BL808)

Thanks.

-l addr is applied for iot command, write command seemd has no this option.

sakumisue commented 1 year ago

Can I suggest you setup GitHub actions to build all the examples with different Chips and then sync from internal via pull requests instead. Then you can catch build errors before they break things for everyone?

Also, can you start tagging releases so we can pick stable commits?

I want to add tag after rf releases.This will be the start of sdk2.0.

cjacker commented 1 year ago

The aim of BLFlashCommand is good since it integrated with bl_mcu_sdk and 'make flash' works very well.

But a question here, do we really need these different flash tools? especially they all seems have the same core codebase.

Here are some suggestions :

Or

After that, we have a most opensource CLI tool and a pyinstaller packaged close source GUI tool. both have same features and can be replaced each other.

It eliminated all confusions, save a lot of time to maintain different projects, save a lot of time to educate users, save a lot of time to write too many documents, and everybody can improve the CLI tool if they want.

Please consider it.

sakumisu commented 1 year ago

No simple, sorry.

sakumisu commented 1 year ago

Use our mcu sdk please use new flash tool, thanks.

cjacker commented 1 year ago

Use our mcu sdk please use new flash tool, thanks.

Today's update occupied about 70M+ disk space since all binaries bflb tools updated.

So request again, please consider open part of the source codes of BLFlashCommand, at least send a release to pypi some day just like bflb-mcu-tool and iot-tool.

And I really suggest you can read this tutorial I wrote recently when your time is available , and maybe you will be able to understand why so many choices make us confused from the users/customers/developers perspective.

https://github.com/cjacker/opensource-toolchain-bouffalo-lab