logo elektroda
logo elektroda
X
logo elektroda

How to add some initialization configurations when refreshing firmware?

gzq127981 396 5
ADVERTISEMENT
  • #1 21042181
    gzq127981
    Level 2  
    Because I need to produce equipment in bulk, it would be inconvenient for me to refresh the firmware first and then perform additional configurations.

    So I would like to add some custom configurations that can be updated and take effect every time the firmware is refreshed.
    What methods can I use to achieve my goals?

    The platform I am using is BL602.
    I tried adding the following code to "win_main.c", then compiling the firmware and refreshing it to the device. But it didn't take effect.

    Code: JSON
    Log in, to see the code


    So, is it because I misplaced my code that the command did not take effect, or is it some other reason? Besides, can I write a script that executes every firmware refresh to achieve my goal.
  • ADVERTISEMENT
  • #2 21042234
    p.kaczmarek2
    Moderator Smart Home
    Welcome to Elektroda.
    win_main.c, as the name indicates, is run only on Windows.
    This is an entry point for OpenBeken Virtual Device Simulator.
    You should rather consider doing your modification in config code:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/new_cfg.c
    Maybe inside: void CFG_SetDefaultConfig(), but I am not sure about running commands there (not sure if stack size would be sufficient), you need to try, or, alternatively, modify the config structure directly through the pins array


    Futhermore, why not just use OBK templates? Is it too many steps per each device?


    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21042721
    gzq127981
    Level 2  
    Thank you for your reply. I tried to make some configuration changes in the function "void CFG_setDefultConfig()", compile the firmware, and then refresh to the device again, but it still did not take effect. It seems that every refresh I make to the device does not change the previously stored configuration information.
    I am very willing to use OBK templates, but I am letting the OEM factory produce equipment in bulk, and they are only responsible for firmware writing and cannot make configuration changes. This means that after the equipment is assembled, I still need to perform secondary operations on the equipment, which adds a lot of workload to me. So I hope to provide them with firmware that has already been set with some default configurations.
  • ADVERTISEMENT
  • #4 21042829
    p.kaczmarek2
    Moderator Smart Home
    I think that you are doing your tests incorrectly. The CFG_setDefultConfig is run only when OBK config in flash is either not present or invalid (wrong CRC).

    If you are trying to reflash an already flashed device, then you will not get CFG_setDefultConfig call because it will just run a config that's already stored in flash.

    Please triple check if you are indeed flashing a non-yet-OBK device and then let me know if CFG_setDefultConfig runs for you.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 21043450
    gzq127981
    Level 2  

    Thank you!
    I followed your instructions to refresh non-yet-OBK device. CFG_setFaultConfig runs successfully.
    What do I do if I want to clear the flash every time I refresh firmware?
  • #6 21043513
    p.kaczmarek2
    Moderator Smart Home
    That is very simple on BK7231, you just need to erase that particular flash block in the flasher. However, it seems that you are using BL602 platform, which complicates things a bit. I don't know much about BL602 flashing, you would need to check yourself if there is a way to erase given sector in BL602 without removing other data.
    Futhermore, it seems that on BL602, we're using easyflash dependency for config storage:
    https://github.com/openshwprojects/OpenBK7231...ob/main/src/hal/bl602/hal_flashConfig_bl602.c
    So I am currently not sure how it's handled internally and at which offset it resides. We would need to check ef_set_env_blob source code.
    https://github.com/search?q=repo%3Aopenshwprojects%2FOpenBL602%20ef_set_env_blob&type=code
    Helpful post? Buy me a coffee.
ADVERTISEMENT