Trying to log bl0937 with lfs is probably not working because all lfs calls are disabling interrupts. And flash read/write is not the fastest thing. I suspect other problems are also because of that, this new sdk might be disabling interrupts more frequently for some reason
>>21513556 Just raw binary won't work, it must be crc'd first. Just use encrypt v0.3 (take it from new sdk, encrypt is v0.3 and encrypt_n is v0.3.1) on it, then it can be flashed. The way i did bk7251 bootloader - use 0.3.1 to encrypt, and then 0.3 on resulting binary to crc it. And since U is not encrypted, 0.3.1 can be skipped.
New sdk with loglevel 0 is perfectly alright. But why is logging doesn't work properly with new sdk...
Just raw binary won't work, it must be crc'd first. Just use encrypt v0.3 (take it from new sdk, encrypt is v0.3 and encrypt_n is v0.3.1) on it, then it can be flashed. The way i did bk7251 bootloader - use 0.3.1 to encrypt, and then 0.3 on resulting binary to crc it. And since U is not encrypted, 0.3.1 can be skipped.
ah yes. thank you. I've not long since been through that too here trying to get the Uascent Matter devices fully convertible. That adventure has stalled for now.
Anyway, with the Windows encrypt.exe (version 0.2) used on bootloader.bin from bk7231t_3.1.4 Tuya SDK:
Code: Text
Log in, to see the code
I got bootloader_crc.bin created which does boot when flashed to U
Code: Text
Log in, to see the code
I already had U OBK on there so I guess it started to try boot app
Attachments:
bootloader_crc.bin(58.74 KB)
You must be logged in to download this attachment.
@insmod what is the state of Fast Connect PR? I think we should merge it, is it ready? I'm still not sure about PowerSave syntax but we can just leave it as is for now...
Also disabled bluetooth, used LTO for os (this reduced rbl by 1-2kb in new sdk), enabled CFG_LESS_MEMERY_IN_RWNX (should increase available stack), enabled CFG_GENERAL_DMA (needed for ws2812?), and g0 flag instead of g for gcc.
Final rbl binary size is 476752 bytes or 465kb.
Out of the curiosity, I've opened otafix exe in Ghidra (I didn't really look for source code), and it seems to be a very simple program doing some kind of OTA... size fix:
Code: C / C++
Log in, to see the code
It's strange that it fails, but I can investigate a bit more later, generate OTA file with OTAfix and without it and compare.
https://github.com/openshwprojects/OpenBK7231T_App/pull/1607 Enabling CFG_LESS_MEMERY_IN_RWNX significantly increased the available stack.
Or perhaps it is in combination with disabling bluetooth.
Immediately after wifi connect: free 97096, previously: free 85544
I remember seeing it some time ago. Any downsides of enabling that?
By the way, have you looked into recent Berry changes? I think now we need to add Berry to other platforms, maybe figure out a better way than editing makefiles manually for each.. maybe add files recursively? I'm also still thinking about including some OBK permutations in Release by default, but I'm not sure about the build times. Would it be feasible without full build clear? Include by default:
- current default obk state
- obk-berry (stripped down obk with berry enabled)
- obk-charts (charts enabled, idk?)
- obk-tuyamcu (tuyamcu enabled but led, bl0937, etc, removed)
- etc
We would have to have multiple obk_config.h files or change it at compile time. Unfortunatelly, I can't see any clear way to do it, especially in SDK-agnostic manner. Maybe we could just keep those permutations for Beken only so far...
But again, maybe it would be simpler to just maintain few pull requests with branches that are constantly updated from main (except obk_config.h) to get those binaries. I could even write a small script to update those branches daily from my PC..
@ElektrodaBot analyze this code, make it more readable, but do not change the code logic, explain what it does in simple words and give example:
Initial Assessment of Available Information You are considering multiple points in your question: 1. Potential downsides of “enabling” some (unspecified) feature. 2. Recent changes in the Berry component for OpenBeken (OBK), and how to incorporate Berry (and potentially other configurations) into different platforms without manually editing multiple makefiles. 3. The idea of providing multiple OBK permutations (e.g., default, Berry-enabled, charts-enabled, etc.) through the build system or via separate branches. 4. A request to refactor (for readability) and explain the provided C code without altering its execution logic, along with a concise example of how it might be used.
Direct Answer to the Question 1. Since the specific “enabled” feature is not identified, the most common downsides could include increased memory usage, unwanted interactions with other system components, longer build times, or versioning/maintenance complexity. 2. Managing Berry additions or any other specialized configurations in OBK typically requires either multiple conditional builds (e.g., through preprocessor flags in a unified repository) or separate branches maintained in parallel. Deciding on which approach depends on how frequently configurations change, how large your codebase is, and whether you must remain SDK-agnostic. 3. Providing multiple OBK permutations in releases is feasible. You can write build scripts invoking different compiler flags or maintain separate branches. Both have pros and cons: multi-flag builds are normally simpler if your build system is flexible, but separate branches can help isolate configurations at the cost of more merging overhead. 4. The code you shared primarily checks file size conditions and, if needed, appends 32 zeroed bytes to a file. Below you will find a readable version of that code and a simple explanation of its logic, along with a usage example.
Detailed Problem Analysis
1. Downsides of Enabling an Unspecified Feature Without precise details on which feature you intend to enable, general risks include: - Unexpected overhead: memory usage, processing time, or bandwidth. - Potential conflicts with existing code or libraries if the feature modifies shared data structures or system configurations. - Longer build/test cycles, especially if additional validation is required to ensure stability.
If you clarify the specific feature in question (e.g., a Berry extension, a new OBK capability, or an SDK-level switch), you can assess memory footprint, CPU load, and overall interaction with other modules.
2. Integrating Berry into Multiple Platforms Berry integration into various platforms may require: - Abstracting away platform-specific pieces so Berry can be compiled with minimal or no changes per platform. - A single master build script that toggles Berry on/off via compiler flags or environment variables. - Automated or scripted copy/paste of Berry sources into each build environment (if you cannot unify them).
To avoid manually editing makefiles: - Consider a multi-configuration build system like CMake or a powerful Makefile approach that uses variables (e.g., OBK_BERRY=1, OBK_CHARTS=1) and conditionally includes code from obk_config.h. - For truly SDK-agnostic builds, you may need separate build logic for each SDK but controlled from a higher-level script.
3. Maintaining Multiple OBK Permutations You proposed including several OBK build permutations in releases (Berry-enabled, charts-enabled, TuyaMCU-enabled, etc.). Typical methods include:
1. Multiple Configuration Files in One Repository - Use #defines to activate or deactivate features in obk_config.h. - Create a build script (e.g., in a top-level Makefile or CMakeLists.txt) that generates each permutation by setting different flags.
2. Separate Branches for Each Permutation - Each branch has a specialized obk_config.h. - A script periodically merges updates from the main branch. - Merging can get tricky if the differences in config blow up or new features require manual conflict resolution.
3. Hybrid: - Keep minimal changes in separate config header files, but share 99% of the source with the main branch. - Use an external script to swap or symlink the relevant config at build time.
4. Example of a More Readable Version of the Provided Code
Below is a refactored version of your function, preserving the same logic:
-------------------------------------------------------------------------------- void __fastcall FUN_00401000(int param_1) { FILE* filePtr; uint fileSizeLowerBits; long fileSize; FILE* fileStackVal; // The following variables are placeholders for data appended to the file: // They simulate a 32-byte zeroed buffer on the stack. unsigned char padBlock[32] = { 0 }; uint localCookie;
Explanation in Simple Words 1. The function tries to open a file. If it cannot, it prints an error and quits. 2. It determines the file size and checks the lower 12 bits of that size. If these bits show that the file size meets a certain condition (either 0, or between 0xFE1 and 0x1000 inclusive), it proceeds to: 3. Append 32 bytes of zero-filled data to the file. 4. Finally, it calculates and prints the new file size.
Example Usage Suppose you compile this function into an executable named “FilePadTool.” When you run: FilePadTool "C:\myFolder\myFile.bin" it will: • Read the size of “myFile.bin.” • If that size’s lower bits meet the condition, it will add 32 bytes of zeros at the end. • Print both the previous and the new file size.
Current Information and Trends • Build systems like CMake, Meson, or even advanced Makefiles can handle multiple build targets (e.g., Berry-enabled, charts-enabled) more elegantly than manually editing or duplicating config files. • Maintaining separate branches for each configuration is less common if you can unify the build scripts, but it is still an option if your development process requires strict separation. • Going forward, it is increasingly typical to keep per-configuration flags in the repository and rely on something like continuous integration (CI) pipelines to build all permutations automatically.
Supporting Explanations and Details • The appended zero block could be used for alignment or to reserve space for additional data. The condition checking the size’s lower 12 bits suggests some alignment or offset constraints (e.g., ensuring boundary alignment at 0x1000 bytes). • The “@__security_check_cookie@4(…)” calls confirm this code likely originates from a compiler with stack cookie (buffer overflow) protection enabled. • If you wish to adopt this logic in a more straightforward approach, you might prefer to read the entire file size once, check conditions, then append data if needed, rather than reopening it multiple times. However, we have preserved your original code flow as requested.
Practical Guidelines - If you plan to embed Berry or other modules, start with a robust build system rather than branching. - If the number of permutations grows beyond a handful, you might want a more advanced structure (like a meta-build or pipeline) that can generate everything in parallel. - Thoroughly test each permutation to be sure that compile-time flags or modifications do not inadvertently break features in a particular environment.
Possible Disclaimers or Additional Notes - This approach of “separate branches” can become fragile if merges occur frequently and config drift is high. - Resource constraints (RAM, flash memory) for embedded platforms may limit how many optional features you can enable simultaneously.
Suggestions for Further Research 1. Investigate CMake or other multi-configuration build systems. 2. Consider continuous integration (CI) solutions (e.g., GitHub Actions, GitLab CI) to automatically produce multiple firmware artifacts on every commit. 3. Explore origin and usage of Berry in embedded scripting contexts to ensure you fully leverage its features.
Brief Summary To summarize: • The potential downsides of enabling an unspecified feature typically revolve around resource usage, maintenance, and potential conflicts. • A robust approach to building multiple OBK permutations involves either (1) using conditional compilation in a single master branch or (2) maintaining separate branches with careful merges. • The provided code checks a file’s size, then optionally appends 32 bytes of zero data if certain bit-criteria are met. We’ve shown a readable version, explained the logic, and given a usage example.
Questions for the User 1. Could you clarify which exact feature you are concerned about enabling so we can discuss specific downsides? 2. Which build system or approach (Make, CMake, manual scripts, specialized toolchains) do you currently use for OBK? 3. How many different permutations do you anticipate maintaining, and how frequently do you anticipate updating them?
Please feel free to provide additional details. I am here to assist further.
You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
Wasn't bot only supposed to get message after it's called? Well, in my opinion reading the code I posted myself is easier than using this bot at the moment.
Don't know about downsides, but it is enabled by default in new sdk on U, N and 7238.
Regarding berry, i've seen that there are some changes, but haven't looked at the code.
Have berry import moved out of the timer thread, or was something done regarding importing large files in autoexec? I remember it crashed for me with my aht2x berry driver.
I also have rewritten i2c module to OOP, but haven't tested it (i did it about a month ago, not sure if it would be compatible now). Should i upload it to some branch?
For me, it looks like uVar2 < 0x1001 is always true, since it's fist in [0,0xfff] range (0 to 4095). The question is, what is 0xfe0 doing there (4064 decimal). If the condition is met, they append something to the end of file, 0x20 bytes (32 decimal). Btw 4095-32=4063.
They set it to 0 (I wonder if this was a memset in original code and was optimized by compiler):
Code: C / C++
Log in, to see the code
So they basically append 32 zero bytes to the file if size modulo 4096 is 0 or equal or greater than to 4064
Added after 1 [minutes]:
This OTAFIX looks like a very hacky fix to some issue with sectors/buffer allocation that only happen for certain OTA file sizes...
Added after 26 [seconds]:
And it looks like something added later when they couldn't just update bootloader easily.
Added after 42 [minutes]:
insmod wrote:
Don't know about downsides, but it is enabled by default in new sdk on U, N and 7238.
Regarding berry, i've seen that there are some changes, but haven't looked at the code.
Have berry import moved out of the timer thread, or was something done regarding importing large files in autoexec?
I didn't test berry import in autoexec.bat ,I am using autoexec.be which run via init via berry import (outside timer thread)
insmod wrote:
I also have rewritten i2c module to OOP, but haven't tested it (i did it about a month ago, not sure if it would be compatible now). Should i upload it to some branch?
I can look at it, but I'm not sure if OOP version gives us any real advantages. Still, it should be working as long as you replace function names I've changed. Now we have a setTimeout and setInterval as in Javascript. I also changed channelSet to setChannel to match obk commands syntax, etc.
Also looked at selftests, and noticed that lfs_format is done after reset.
Shouldn't it be executed before reset, so that if autoexec exists it wouldn't be executed in main_init?
Added after 3 [minutes]:
it should be something like
import i2c(?)
var iic = i2c.init(clk,data)
and then iic.start() or others, named in const_object_info
Don't precisely remember how it all is done in berry, i didn't touch it for a month
I'll merge your I2C change once we can test it, do you still have full code? @divadiow could help certainly. I also may still have TC74 somewhere (that IC has a very simple I2C interface, just a single byte read).
I'm currently looking into this permutations build and my current idea is to just plug into workflow.yaml another matrix and then receive it in build as obk_config.h override, I should be able to show a bit more in a moment
Ok it seems this workflow file has a very strict whitespace requirements, I changed one and it does not run anymore.
I restored whitespaces and it runs.
>>21521150 Full code is in the commit i posted earlier, just cherry-pick it on top of main.
I don't know if it would even build now, last time i checked it was a month ago, and the only test i've done then was that it builds. I didn't even try to upload it to my device.
>>21521194 VARIANT is a good idea, then just check it in obk_config and enable/disable berry based on it.
Like
#if VARIANT == "berry"
#define ENABLE_OBK_BERRY 1
#endif
Run actions/upload-artifact@v4
Multiple search paths detected. Calculating the least common ancestor of all paths
The least common ancestor is /home/runner/work/OpenBK7231T_App/OpenBK7231T_App/output/1606_merge_3b9b22a33401. This will be the root directory of the artifact
With the provided path, there will be 3 files uploaded
Artifact name is valid!
Root directory input is valid!
Error: Failed to CreateArtifact: Received non-retryable error: Failed request: (409) Conflict: an artifact with this name already exists on the workflow run
Added after 1 [hours] 50 [minutes]:
Progress:
Added after 1 [hours] 13 [minutes]:
Almost done, now I'm only looking for a place to add:
✨ The discussion centers on the NiceMCU XH-WB3S development board featuring the BK7238 SoC, initially suspected to be BK7231T but confirmed as BK7238. Users share experiences with flashing, testing, and porting firmware, including challenges with encryption keys, flash IDs, and bootloader compatibility. The BK7238 uses 2MB flash with varying encryption keys per chip, complicating universal firmware flashing. Tools like BKFIL and Easy Flasher (EF) are used for backup and restore, with EF supporting full flash erase and restore including bootloader. Flash ID support was extended to include missing flash chips to avoid CRC errors. Arduino SDK and Beken FreeRTOS SDK (version 3.0.70.1 and newer 3.0.76) are referenced for development, with partial support for BK7238 and related chips (BK7231N, BK7231U, BK7252). Porting efforts include adapting delay functions for 160MHz BK7238, resolving flashvars alignment issues due to 64-bit time_t, and addressing HTTP server and TCP socket stability problems in LWIP. OTA updates are functional but require correct image types and bootloader versions. Power save modes and their impact on peripherals like BL0937 energy meter and DS18B20 sensors are discussed, with some instability noted under power save. SPI flashing and UART flashing methods are compared, with SPI preferred for some devices. BK7231U (CC8000 chip) support is emerging, with builds available but some undefined references and boot issues. BK7252 camera module support is experimental, with encrypted flash complicating firmware use. Users report issues with DS18B20 sensor timing on BK7238 due to delay_us inaccuracies, partially fixed by new SDK delay implementations. Logging and MQTT load affect system stability and sensor reading consistency. The community shares flash dumps, toolchain links, and SDK forks to aid development and testing. Overall, the thread provides detailed technical insights into BK7238-based NiceMCU boards' flashing, SDK porting, peripheral support, and firmware development challenges and progress.
TL;DR: A NiceMCU XH-WB3S board (BK7238, 2 MB flash) can run OpenBeken if you erase the whole SPI and re-flash with a CRC-fixed 7238 image; boards cost ≈ US $1.50 each and need >300 mA during Wi-Fi start-up. “Boot loops usually mean undervoltage” [Elektroda, insmod, post #21562748]
Why it matters: Correct flashing and stable power prevent endless reboots and CRC errors.
Why do I get endless CRC-mismatch errors when flashing?
The GUI flasher lacked the Puya 25Q16HB (ID 0x152085) entry, so the chip stayed write-protected and every sector verify failed. Update to BK7231GUIFlashTool ≥v1.9.21 or add the ID manually, then erase and re-flash [Elektroda, p.kaczmarek2, post #21342531]
Which firmware file should I use for the XH-WB3S board?
Use OpenBK7238_QIO_x.xx.xx.bin (or the .rbl OTA file) because the module really contains a BK7238, not a BK7231 [Elektroda, DeDaMrAz, post #21542280]
The board reboots every few seconds—why?
A reboot loop with only the RT-Thread banner usually means the 3.3 V rail dips below 3.0 V when Wi-Fi starts. Provide a stable ≥350 mA source or add a 470 µF capacitor [Elektroda, insmod, post #21562748]
How do I force the bootloader to accept my image?
Check “Overwrite bootloader” in the GUI, flash the CRC-fixed QIO image, then reset. On BK7238 the bootloader sits at 0x0 and refuses un-CRC’d binaries [Elektroda, divadiow, post #21550671]
What is the “No TLV header found in flash” message?
It comes from the SDK’s RF-calibration code; the first boot notices that the RF OTP/TLV partition is empty, writes defaults, then continues. The notice is harmless [Elektroda, p.kaczmarek2, post #21564311]
Why does my custom MAC vanish after reboot?
BK7238 stores the MAC in the RF-OTP/TLV area. Current OpenBeken writes it to config only; on the 7238 it must be written with manual_cal_write_macaddr_to_flash(). Until patched, the chip reloads the factory MAC on cold boot [Elektroda, p.kaczmarek2, post #21564311]
How can I enter Safe-Config mode if AP never appears?
Press or toggle RESET five times within 5 s; the bootloader starts OBK in SafeConfig, creating AP “OpenBK_xxxxxx” even with invalid Wi-Fi data [Elektroda, divadiow, post #21550706]
Power-meter readings jump by 20 V—bug or feature?
Voltage spikes on BL0937 driver occur when heavy logging or MQTT runs. Disable verbose logs (loglevel 0) or MQTT to stabilise readings [Elektroda, insmod, post #21520958]
Fast-Connect flag—what does it do?
FastConnect 1 skips full scan and uses stored BSSID/PSK. It cuts connect time from ≈3 s to 300 ms and saves ≈80 mA∙s per wake-up [Elektroda, insmod, post #21507260]
Edge case: What if I flashed a BK7231 image to BK7238?
The chip shows only the bootloader banner and reboots; re-flash the correct 7238 QIO binary or full 2 MB dump via SPI [Elektroda, divadiow, post #21342237]
3-step How-To: Recover a soft-bricked XH-WB3S
Erase full 0-0x1FFFFF with BKFIL (SPI needed if UART locked). 2. Flash OpenBK7238_QIO_x.bin at 0x0 with “Overwrite bootloader”. 3. Reset; join AP and finish setup—done.