From b29c28b12c5cac624e786bbc4a9bb88675cb58df Mon Sep 17 00:00:00 2001 From: divadiow Date: Sat, 16 Nov 2024 15:49:13 +0000 Subject: [PATCH 1/5] try partition partition details change for 4mb module --- platforms/BK7231N/pre_build.sh | 52 +-- .../bk378/func/user_driver/BkDriverFlash.c | 381 ++++++++++++++++++ 2 files changed, 392 insertions(+), 41 deletions(-) create mode 100644 platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c diff --git a/platforms/BK7231N/pre_build.sh b/platforms/BK7231N/pre_build.sh index b4e5d0dbb..149099250 100644 --- a/platforms/BK7231N/pre_build.sh +++ b/platforms/BK7231N/pre_build.sh @@ -1,41 +1,11 @@ -# This script will be called just before starting build process for BK7231N -# It allows you to make changes to the SDK, for example.. -# For example, you can use changed files in the SDK for the automated build during the checks for a PR without changing the SDK itself: -# So if your PR requires a changed define in SDK, you can do this here - -# -# -# As an example you will find a script below which will copy all content of the "override" -# directory 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 platforms/BK7231N/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/OpenBK7231N/..." -# D=${X#platforms/BK7231N/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 - -# you can also use all other commands to change files, like -# sed -i "s/#define FOO bar/#define FOO baz/" sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/beken378/file_to_change.c -# or, let's assume you made a local change to your SDK -# and make a diff from that change (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 - +DIRNAME=$(dirname $0); +echo "PREBUILD script! Executed from $DIRNAME!" +OFS=$IFS +IFS=' +' +for X in $(find platforms/BK7231N/override/ -type f);do +S=${X}; +D=${X#platforms/BK7231N/override/}; +[ -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; +IFS=$OFS \ No newline at end of file diff --git a/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c b/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c new file mode 100644 index 000000000..e3c6a43bc --- /dev/null +++ b/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c @@ -0,0 +1,381 @@ +/** + ****************************************************************************** + * @file BkDriverFlash.h + * @brief This file provides all the headers of Flash operation functions. + ****************************************************************************** + * + * The MIT License + * Copyright (c) 2017 BEKEN Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR + * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ****************************************************************************** + */ +#include "include.h" +#include "rtos_pub.h" +#include "BkDriverFlash.h" +#include "flash_pub.h" +#include "drv_model_pub.h" +#include "rtos_error.h" +#include "uart_pub.h" +#include "mem_pub.h" + +static beken_mutex_t hal_flash_mutex; + +/* Logic partition on flash devices */ +const bk_logic_partition_t bk7231_partitions[BK_PARTITION_MAX] = +{ + [BK_PARTITION_BOOTLOADER] = + { + .partition_owner = BK_FLASH_EMBEDDED, + .partition_description = "Bootloader", + .partition_start_addr = 0x00000000, + .partition_length = 0x11000,//68KB + .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, + }, + [BK_PARTITION_APPLICATION] = + { + .partition_owner = BK_FLASH_EMBEDDED, + .partition_description = "Application", + .partition_start_addr = 0x11000, + .partition_length = 0x121000,//1156KB + .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, + }, + [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 = 0x1E3000,// for rf related info + .partition_length = 0x1000, + .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, + }, + [BK_PARTITION_NET_PARAM] = + { + .partition_owner = BK_FLASH_EMBEDDED, + .partition_description = "NET info", + .partition_start_addr = 0x1D1000,// for net related info + .partition_length = 0x1000, + .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, + } +}; + +static void BkFlashPartitionAssert( bk_partition_t inPartition ) +{ + ASSERT(BK_PARTITION_BOOTLOADER < BK_PARTITION_MAX); +} + +static uint32_t BkFlashPartitionIsValid( bk_partition_t inPartition ) +{ + if((inPartition >= BK_PARTITION_BOOTLOADER)&&(inPartition < BK_PARTITION_MAX)) + { + return 1; + } + else + { + return 0; + } +} + +bk_logic_partition_t *bk_flash_get_info( bk_partition_t inPartition ) +{ + bk_logic_partition_t *pt = NULL; + + BkFlashPartitionAssert(inPartition); + + if(BkFlashPartitionIsValid(inPartition)) + { + pt = (bk_logic_partition_t *)&bk7231_partitions[inPartition]; + } + else + pt = NULL; + return pt; +} + +OSStatus BkFlashInit(void) +{ + return 0; +} + +OSStatus BkFlashUninit(void) +{ + return 0; +} + +OSStatus bk_flash_erase(bk_partition_t inPartition, uint32_t off_set, uint32_t size) +{ + uint32_t i; + uint32_t param; + UINT32 status; + DD_HANDLE flash_hdl; + uint32_t start_sector, end_sector; + bk_logic_partition_t *partition_info; + GLOBAL_INT_DECLARATION(); + + partition_info = bk_flash_get_info(inPartition); + start_sector = off_set >> 12; + end_sector = (off_set + size - 1) >> 12; + + flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0); + ASSERT(DD_HANDLE_UNVALID != flash_hdl); + for(i = start_sector; i <= end_sector; i ++) + { + param = partition_info->partition_start_addr + (i << 12); + GLOBAL_INT_DISABLE(); + ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, (void *)¶m); + GLOBAL_INT_RESTORE(); + } + + return kNoErr; +} + +OSStatus bk_flash_write( bk_partition_t inPartition, volatile uint32_t off_set, uint8_t *inBuffer , uint32_t inBufferLength) +{ + UINT32 status; + DD_HANDLE flash_hdl; + uint32_t start_addr; + bk_logic_partition_t *partition_info; + GLOBAL_INT_DECLARATION(); + + if (NULL == inBuffer) + { + os_printf("%s inBuffer=NULL\r\n", __FUNCTION__); + return kParamErr; + } + + partition_info = bk_flash_get_info(inPartition); + if (NULL == partition_info) + { + os_printf("%s partiion not found\r\n", __FUNCTION__); + return kNotFoundErr; + } + + start_addr = partition_info->partition_start_addr + off_set; + + flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0); + if (DD_HANDLE_UNVALID == flash_hdl) + { + os_printf("%s open failed\r\n", __FUNCTION__); + return kOpenErr; + } + + GLOBAL_INT_DISABLE(); + ddev_write(flash_hdl, (char*)inBuffer, inBufferLength, start_addr); + GLOBAL_INT_RESTORE(); + + return kNoErr; +} + +OSStatus bk_flash_read( bk_partition_t inPartition, volatile uint32_t off_set, uint8_t *outBuffer, uint32_t inBufferLength) +{ + UINT32 status; + uint32_t start_addr; + DD_HANDLE flash_hdl; + bk_logic_partition_t *partition_info; + GLOBAL_INT_DECLARATION(); + + if (NULL == outBuffer) + { + os_printf("%s outBuffer=NULL\r\n", __FUNCTION__); + return kParamErr; + } + + partition_info = bk_flash_get_info(inPartition); + if (NULL == partition_info) + { + os_printf("%s partiion not found\r\n", __FUNCTION__); + return kNotFoundErr; + } + + start_addr = partition_info->partition_start_addr + off_set; + + flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0); + if (DD_HANDLE_UNVALID == flash_hdl) + { + os_printf("%s open failed\r\n", __FUNCTION__); + return kOpenErr; + } + + GLOBAL_INT_DISABLE(); + ddev_read(flash_hdl, (char*)outBuffer, inBufferLength, start_addr); + GLOBAL_INT_RESTORE(); + + return kNoErr; +} + +OSStatus bk_flash_enable_security(PROTECT_TYPE type ) +{ + DD_HANDLE flash_hdl; + UINT32 status; + uint32_t param = type; + + flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0); + if (DD_HANDLE_UNVALID == flash_hdl) + { + os_printf("%s open failed\r\n", __FUNCTION__); + return kOpenErr; + } + ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, (void *)¶m); + + return kNoErr; +} + + +OSStatus test_flash_write(volatile uint32_t start_addr, uint32_t len) +{ + UINT32 status; + DD_HANDLE flash_hdl; + uint32_t i; + u8 buf[256]; + uint32_t addr = start_addr; + uint32_t length = len; + uint32_t tmp = addr + length; + + for(i=0;i<256;i++) + buf[i]=i; + + flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0); + ASSERT(DD_HANDLE_UNVALID != flash_hdl); + for(;addr Date: Sat, 16 Nov 2024 15:53:07 +0000 Subject: [PATCH 2/5] actually save changes to bkdriverflash.c --- .../bk7231n_os/bk378/func/user_driver/BkDriverFlash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c b/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c index e3c6a43bc..a3100df64 100644 --- a/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c +++ b/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c @@ -52,15 +52,15 @@ const bk_logic_partition_t bk7231_partitions[BK_PARTITION_MAX] = .partition_owner = BK_FLASH_EMBEDDED, .partition_description = "Application", .partition_start_addr = 0x11000, - .partition_length = 0x121000,//1156KB + .partition_length = 0x190000,//1600KB .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, }, [BK_PARTITION_OTA] = { .partition_owner = BK_FLASH_EMBEDDED, .partition_description = "ota", - .partition_start_addr = 0x12A000, - .partition_length = 0xA6000, //664KB + .partition_start_addr = 0x286000, + .partition_length = 0x1A9000, //1692KB .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, }, [BK_PARTITION_RF_FIRMWARE] = @@ -75,7 +75,7 @@ const bk_logic_partition_t bk7231_partitions[BK_PARTITION_MAX] = { .partition_owner = BK_FLASH_EMBEDDED, .partition_description = "NET info", - .partition_start_addr = 0x1D1000,// for net related info + .partition_start_addr = 0x3E0000,// for net related info .partition_length = 0x1000, .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, } From ba681e7a04106e87bdcc8108f431007fc8414bde Mon Sep 17 00:00:00 2001 From: divadiow Date: Sat, 16 Nov 2024 15:58:46 +0000 Subject: [PATCH 3/5] restore 'done' --- platforms/BK7231N/pre_build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/platforms/BK7231N/pre_build.sh b/platforms/BK7231N/pre_build.sh index 149099250..25ba1b101 100644 --- a/platforms/BK7231N/pre_build.sh +++ b/platforms/BK7231N/pre_build.sh @@ -8,4 +8,5 @@ S=${X}; D=${X#platforms/BK7231N/override/}; [ -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 IFS=$OFS \ No newline at end of file From e37a0211ba56acec788828336adcc020596fe33b Mon Sep 17 00:00:00 2001 From: divadiow Date: Sat, 16 Nov 2024 17:00:07 +0000 Subject: [PATCH 4/5] try same RF and Net Info addresses original mac in factory fw is found in 0x3E0000 B4 ED D5 03 C2 66 --- .../bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c b/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c index a3100df64..65ed56e75 100644 --- a/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c +++ b/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c @@ -67,7 +67,7 @@ const bk_logic_partition_t bk7231_partitions[BK_PARTITION_MAX] = { .partition_owner = BK_FLASH_EMBEDDED, .partition_description = "RF Firmware", - .partition_start_addr = 0x1E3000,// for rf related info + .partition_start_addr = 0x3E0000,// for rf related info .partition_length = 0x1000, .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, }, From 6e7ed3e1150854ef2e7b5359f99cac7fa398bfe2 Mon Sep 17 00:00:00 2001 From: divadiow Date: Sun, 17 Nov 2024 14:08:30 +0000 Subject: [PATCH 5/5] NET info 0x3E1000 --- .../bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c b/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c index 65ed56e75..4a7f24901 100644 --- a/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c +++ b/platforms/bk7231n/override/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os/bk378/func/user_driver/BkDriverFlash.c @@ -75,7 +75,7 @@ const bk_logic_partition_t bk7231_partitions[BK_PARTITION_MAX] = { .partition_owner = BK_FLASH_EMBEDDED, .partition_description = "NET info", - .partition_start_addr = 0x3E0000,// for net related info + .partition_start_addr = 0x3E1000,// for net related info .partition_length = 0x1000, .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS, }