Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion boards/arm/rtl8762gn_evb/rtl8762gn_evb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
};

&flash {
reg = <0x4000000 DT_SIZE_K(1024)>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
Expand Down Expand Up @@ -58,7 +59,11 @@
};
app_partition: partition@2d000 {
label = "app-image";
reg = <0x2D000 DT_SIZE_K(828)>;
reg = <0x2D000 DT_SIZE_K(412)>;
};
ota_tmp_partition: partition@94000 {
label = "ota-tmp-image";
reg = <0x94000 DT_SIZE_K(416)>;
};
storage_partition: partition@fc000 {
label = "storage";
Expand All @@ -79,4 +84,8 @@
parity = "none";
stop-bits = "1";
data-bits = <8>;
};

&corewdt {
status = "okay";
};
1 change: 0 additions & 1 deletion dts/arm/realtek/rtl87x2g.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
compatible = "soc-nv-flash";
write-block-size = <1>;
erase-block-size = <4096>;
reg = <0x4000000 DT_SIZE_K(1024)>;
};
};

Expand Down
10 changes: 10 additions & 0 deletions samples/bluetooth/rtk_ota_sample_dual_bank/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(rtk_ota_sample_dual_bank)

target_sources(app PRIVATE
src/main.c
src/cts.c
)
17 changes: 17 additions & 0 deletions samples/bluetooth/rtk_ota_sample_dual_bank/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### 工程编译

该工程默认编译 `bank0 Image`。如果需要编译 `bank1 Image`,请将 `rtl8762gn_evb.overlay` 中的 `zephyr,code-partition` 修改为 `&app_partition_1`。

### 脚本运行

为了使得 Zephyr Image 能够兼容 Realtek 的 OTA 系统,在编译完后,请运行 `tools/run.bat`。该脚本会将生成的 `zephyr.bin` 加上 Realtek 的 MP header,并将sha256校验值、payload length 等写入 image header 中。

最终将生成两版 image,分别是 `zephyrImage_MP.bin` 和 `zephyrImage.bin`(不带 MP header)。

### 如何在蓝牙工程中打开RTK OTA?

要开启OTA功能,需要在开启蓝牙的app中打开CONFIG_REALTEK_OTA。

另外如果需要对Zephyr Image进行OTA升级,请拷贝本工程路径下的tools目录到您的应用程序路径下,并使用tools/run.bat脚本对原始Zephyr Image进行处理。

OTA相关的source/header file放置在 `zephyr\soc\arm\realtek_bee\rtl87x2g\ota_src\` 目录下。
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/ {
chosen {
zephyr,code-partition = &app_partition_0;
};
};


&flash {
reg = <0x4000000 DT_SIZE_K(1024)>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
reserved: partition@0 {
label = "reserved-image";
reg = <0x0 DT_SIZE_K(4)>;
};
config_file: partition@1000 {
label = "config-file-image";
reg = <0x1000 DT_SIZE_K(4)>;
};
boot_patch_0: partition@2000 {
label = "boot-patch-0-image";
reg = <0x2000 DT_SIZE_K(32)>;
};
boot_patch_1: partition@a000 {
label = "boot-patch-1-image";
reg = <0xA000 DT_SIZE_K(32)>;
};
/* Bank 0 */
ota_header_0: partition@12000 {
label = "ota-header-0-image";
reg = <0x12000 DT_SIZE_K(4)>;
};
system_patch_0: partition@13000 {
label = "system-patch-0-image";
reg = <0x13000 DT_SIZE_K(32)>;
};
stack_patch_0: partition@1b000 {
label = "stack-patch-0-image";
reg = <0x1B000 DT_SIZE_K(72)>;
};
app_partition_0: partition@2d000 {
label = "app-image-0";
reg = <0x2D000 DT_SIZE_K(360)>;
};
/* Bank 1 */
ota_header_1: partition@87000 {
label = "ota-header-1-image";
reg = <0x87000 DT_SIZE_K(4)>;
};
system_patch_1: partition@88000 {
label = "system-patch-1-image";
reg = <0x88000 DT_SIZE_K(32)>;
};
stack_patch_1: partition@90000 {
label = "stack-patch-1-image";
reg = <0x90000 DT_SIZE_K(72)>;
};
app_partition_1: partition@a2000 {
label = "app-image-1";
reg = <0xA2000 DT_SIZE_K(360)>;
};
storage_partition: partition@fc000 {
label = "storage";
reg = <0xFC000 DT_SIZE_K(16)>;
};
};
};
29 changes: 29 additions & 0 deletions samples/bluetooth/rtk_ota_sample_dual_bank/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Increased stack due to settings API usage
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_BT=y
CONFIG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_SIGNING=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DIS=y
CONFIG_BT_ATT_PREPARE_COUNT=5
CONFIG_BT_BAS=y
CONFIG_BT_HRS=y
CONFIG_BT_IAS=y
# CONFIG_BT_PRIVACY=y
CONFIG_BT_DEVICE_NAME="Zephyr Peripheral Sample Long Name"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=65

CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

CONFIG_REALTEK_OTA=y
CONFIG_LOG_BUFFER_SIZE=3072
109 changes: 109 additions & 0 deletions samples/bluetooth/rtk_ota_sample_dual_bank/src/cts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/** @file
* @brief CTS Service sample
*/

/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/kernel.h>

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/gatt.h>

static uint8_t ct[10];
static uint8_t ct_update;

static void ct_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{
/* TODO: Handle value */
}

static ssize_t read_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
{
const char *value = attr->user_data;

return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
sizeof(ct));
}

static ssize_t write_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags)
{
uint8_t *value = attr->user_data;

if (offset + len > sizeof(ct)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
}

memcpy(value + offset, buf, len);
ct_update = 1U;

return len;
}

/* Current Time Service Declaration */
BT_GATT_SERVICE_DEFINE(cts_cvs,
BT_GATT_PRIMARY_SERVICE(BT_UUID_CTS),
BT_GATT_CHARACTERISTIC(BT_UUID_CTS_CURRENT_TIME, BT_GATT_CHRC_READ |
BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_ct, write_ct, ct),
BT_GATT_CCC(ct_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
);

static void generate_current_time(uint8_t *buf)
{
uint16_t year;

/* 'Exact Time 256' contains 'Day Date Time' which contains
* 'Date Time' - characteristic contains fields for:
* year, month, day, hours, minutes and seconds.
*/

year = sys_cpu_to_le16(2015);
memcpy(buf, &year, 2); /* year */
buf[2] = 5U; /* months starting from 1 */
buf[3] = 30U; /* day */
buf[4] = 12U; /* hours */
buf[5] = 45U; /* minutes */
buf[6] = 30U; /* seconds */

/* 'Day of Week' part of 'Day Date Time' */
buf[7] = 1U; /* day of week starting from 1 */

/* 'Fractions 256 part of 'Exact Time 256' */
buf[8] = 0U;

/* Adjust reason */
buf[9] = 0U; /* No update, change, etc */
}

void cts_init(void)
{
/* Simulate current time for Current Time Service */
generate_current_time(ct);
}

void cts_notify(void)
{ /* Current Time Service updates only when time is changed */
if (!ct_update) {
return;
}

ct_update = 0U;
bt_gatt_notify(NULL, &cts_cvs.attrs[1], &ct, sizeof(ct));
}
20 changes: 20 additions & 0 deletions samples/bluetooth/rtk_ota_sample_dual_bank/src/cts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** @file
* @brief CTS Service sample
*/

/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifdef __cplusplus
extern "C" {
#endif

void cts_init(void);
void cts_notify(void);

#ifdef __cplusplus
}
#endif
Loading
Loading