If you want to try out a new feature, integrate a new driver or otherwise make a change in the SDK, this is not a problem in the local repository.
If you create a PR, however, you have the problem that the automated build fails because the changes are not available in the SDK.
With a newer extension to OpenBeken it is now possible to run a script before the build which can (also) make changes to the SDK.
“Also”, because the script opens up a quite powerful possibility to do everything that is possible with scripting...
This enhancement will especially be usefull if you want to create a custom OpenBeken version with "online builds" as described here:
https://www.elektroda.com/rtvforum/topic4056286.html
I would like to give a few examples here of how you can use this possibility:
The general approach is to do changes just before the build run for a platform by calling a script if it's present.
The location checked is "platforms/<module>/pre_build.sh"
As a first example you will find a script which will copy all content of the "override"
directory (under the platforms/<platform>/ directory of your platform to the corresponding location in the SDK:
So say we want to replace this file for platform BK7231N (yes it's surely overkill to use the script for this and not to simply use one "cp" command, but it's just for demonstration
):
You put the new version of the file to the "complete path" under "platforms/BK7231N/override/"
During build you can see the success of the operation:
Since we use a script, you can also use all other commands to change files, like "sed".
So say you need to change two values in BkDriverFlash.c file and want to change .partition_start_addr"
for [BK_PARTITION_OTA] from 0x12A000 to 0x143000 and
for [BK_PARTITION_RF_FIRMWARE] from 0x1D0000 to 0x1F6000
in this section
You can use a "sed" command to do the change.
To make sure, the replacement is only done at the correct line(s) you could/should use ranges before the replacement, like in this command:
Or, taking a look in the source, we see the numbers to change are between line 62 and 70 and the values are unique in this area, so we can also use the range "62,70"
The last example for now should be the patching of a file in sdk with a "diff"-file.
So let's assume you made a local change to your SDK for BK7231N platform
and make a diff from that change ( by calling "git diff" inside "sdk/OpenBK7231N/")
( or make the diff and copy this file to platforms/BK7231N)
and then in pre_build.sh you apply this patch with:
If you create a PR, however, you have the problem that the automated build fails because the changes are not available in the SDK.
With a newer extension to OpenBeken it is now possible to run a script before the build which can (also) make changes to the SDK.
“Also”, because the script opens up a quite powerful possibility to do everything that is possible with scripting...
This enhancement will especially be usefull if you want to create a custom OpenBeken version with "online builds" as described here:
https://www.elektroda.com/rtvforum/topic4056286.html
I would like to give a few examples here of how you can use this possibility:
The general approach is to do changes just before the build run for a platform by calling a script if it's present.
The location checked is "platforms/<module>/pre_build.sh"
As a first example you will find a script which will copy all content of the "override"
directory (under the platforms/<platform>/ directory of your platform to the corresponding location in the SDK:
DIRNAME=$(dirname $0);
echo "PREBUILD script! Executed from $DIRNAME!"
# allow whitspace in file or path, so take only newline as seperator
OFS=$IFS
IFS='
'
for X in $(find ${DIRNAME}/override/ -type f);do
# script is executed from main app directory, so take found file and path as source
S=${X};
# destination is path stripped from path to override
# so inside "override" we have the full path to the file
# starting with "sdk/Open<platform>/..."
D=${X#${DIRNAME}/override/};
# if file is present, we replace it, otherwise file is added ...
[ -e $D ] && echo "PREBUILD: replacing file\n\t$D\n\twith file\n\t$S" || echo "PREBUILD: adding file\n\t$S\n\tas\n\t$D"
cp $S $D;
done
# restore IFS to whatever it was before ...
IFS=$OFS
So say we want to replace this file for platform BK7231N (yes it's surely overkill to use the script for this and not to simply use one "cp" command, but it's just for demonstration

sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/beken378/func/user_driver/BkDriverFlash.c
You put the new version of the file to the "complete path" under "platforms/BK7231N/override/"
platforms/BK7231N/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/beken378/func/user_driver/BkDriverFlash.c
During build you can see the success of the operation:
...
make[2]: Leaving directory '/OpenBK7231T_App/sdk/OpenLN882H/build'
make[1]: Leaving directory '/OpenBK7231T_App/sdk/OpenLN882H/build'
prebuild found for OpenBK7231N
PREBUILD script! Executed from platforms/BK7231N!
PREBUILD: replacing file
sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/beken378/func/user_driver/BkDriverFlash.c
with file
platforms/BK7231N/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/beken378/func/user_driver/BkDriverFlash.c
make APP_NAME=OpenBK7231N TARGET_PLATFORM=bk7231n SDK_PATH=sdk/OpenBK7231N APPS_BUILD_PATH=../bk7231n_os build-BK7231
make[1]: Entering directory '/OpenBK7231T_App'
...
Since we use a script, you can also use all other commands to change files, like "sed".
So say you need to change two values in BkDriverFlash.c file and want to change .partition_start_addr"
for [BK_PARTITION_OTA] from 0x12A000 to 0x143000 and
for [BK_PARTITION_RF_FIRMWARE] from 0x1D0000 to 0x1F6000
in this section

},
[BK_PARTITION_OTA] =
{
.partition_owner = BK_FLASH_EMBEDDED,
.partition_description = "ota",
.partition_start_addr = 0x12A000,
.partition_length = 0xA6000, //664KB
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS,
},
[BK_PARTITION_RF_FIRMWARE] =
{
.partition_owner = BK_FLASH_EMBEDDED,
.partition_description = "RF Firmware",
.partition_start_addr = 0x1D0000,// for rf related info
.partition_length = 0x1000,
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS,
},
[BK_PARTITION_NET_PARAM] =
You can use a "sed" command to do the change.
To make sure, the replacement is only done at the correct line(s) you could/should use ranges before the replacement, like in this command:
# as ranges we use "/\[BK_PARTITION_OTA\]/,+4" and "/\[BK_PARTITION_RF_FIRMWARE\]/,+4"
# the line with ".partition_start_addr" is the 4th line after the matching "header"
sed -i "/\[BK_PARTITION_OTA\]/,+4 s/0x12A000,/0x143000,/; /\[BK_PARTITION_RF_FIRMWARE\]/,+4 s/0x1D0000,/0x1F6000,/" sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/beken378/func/user_driver/BkDriverFlash.c
Or, taking a look in the source, we see the numbers to change are between line 62 and 70 and the values are unique in this area, so we can also use the range "62,70"
sed -i "62,70 {s/0x12A000,/0x143000,/; s/0x1D0000,/0x1F6000,/}" sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/beken378/func/user_driver/BkDriverFlash.c
The last example for now should be the patching of a file in sdk with a "diff"-file.
So let's assume you made a local change to your SDK for BK7231N platform
and make a diff from that change ( by calling "git diff" inside "sdk/OpenBK7231N/")
git diff > ../../platforms/BK7231N/my_change.diff
( or make the diff and copy this file to platforms/BK7231N)
and then in pre_build.sh you apply this patch with:
patch -p 1 -d sdk/OpenBK7231N < platforms/BK7231N/my_change.diff