Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash tool difference #93

Closed
sakumisu opened this issue Feb 24, 2023 · 22 comments
Closed

Flash tool difference #93

sakumisu opened this issue Feb 24, 2023 · 22 comments

Comments

@sakumisu
Copy link

sakumisu commented Feb 24, 2023

Abstract

For now we have these flashtools:

  • devcube gui, devcube cmd (bflb_mcu_tool/bflb_iot_tool)
  • flashcube gui, flashcube cmd (blflashcommand)

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)

@sakumisue sakumisue pinned this issue Feb 24, 2023
@cjacker
Copy link

cjacker commented Feb 27, 2023

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

  • flashing with blisp and bflb-mcu-tool completely broken. it also broken all tutorials, howtos, etc...
  • BLFlashCommand not works as expected, the error as below, report missing "eflash_loader_32m.bin".
  • There is no source codes released for BLFlashCommand and various eflash_loader.elf, etc...

My Questions:

  • Is it really good to commit so many binaries and break all known open-source solutions?
  • Is 'bflb-mcu-tool' also official program tool? How is it different from 'BLFlashCommand'? which is maintained and supported by official in deed?

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
Copy link
Author

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

@sakumisu
Copy link
Author

bin has ignored by .gitignore.

@cjacker
Copy link

cjacker commented Feb 27, 2023

Simple questions:

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

  • how can I process this bin file to program it with 'blisp' or 'bflb-mcu-tool' ? it can programmed as before, but not works.
  • how can I program it with 'BLFlashCommand'? the detail usage needed.

@sakumisu
Copy link
Author

please see doc.

@Fishwaldo
Copy link
Contributor

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
Copy link
Author

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

@cjacker
Copy link

cjacker commented Feb 27, 2023

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
Copy link
Author

I have said it is ignored by gitignore.

@sakumisu
Copy link
Author

Please update commit.

@cjacker
Copy link

cjacker commented Feb 27, 2023

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
Copy link
Author

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

@sakumisu sakumisu reopened this Feb 27, 2023
@cjacker
Copy link

cjacker commented Feb 27, 2023

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
Copy link

cjacker commented Feb 27, 2023

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
Copy link
Author

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
Copy link
Contributor

@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
Copy link

cjacker commented Feb 27, 2023

@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
Copy link
Contributor

sakumisue commented Feb 27, 2023

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.

@bouffalolab bouffalolab deleted a comment from sakumisu Feb 27, 2023
@sakumisu sakumisu changed the title Note: Flash with new command tool or devcube>=1.8.2 Flash tool difference Mar 7, 2023
@cjacker
Copy link

cjacker commented Mar 7, 2023

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 :

  • bflb-iot-tool and bflb-mcu-tool can merged together and renamed to 'bl-mcu-tool' if it will provide more command line args.
  • The IOT page and MCU page can also be merged together. there are not much difference at all.
  • BLFlashCommand / GUI can be replaced by this new 'bl-mcu-tool' if it have the ability to read flash config file.

Or

  • Use BLFlashCommand and GUI to deprecate DevCube/mcu-tool/iot-tool and open part of the source codes of BLFlashCommand, at least submit a release to pypi.

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
Copy link
Author

sakumisu commented Mar 7, 2023

No simple, sorry.

@sakumisu
Copy link
Author

sakumisu commented Mar 7, 2023

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

@cjacker
Copy link

cjacker commented Mar 7, 2023

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

@sakumisue sakumisue unpinned this issue Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants