Skip to content

Commit 10bc52f

Browse files
authored
Merge pull request #354 from kyliuxing/rel_1.3.0
update rda5981x
2 parents 06b1412 + cff2753 commit 10bc52f

File tree

22 files changed

+299
-62
lines changed

22 files changed

+299
-62
lines changed

board/uno-91h/board.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,56 @@ const hal_logic_partition_t hal_partitions[] =
1818
{
1919
.partition_owner = HAL_FLASH_EMBEDDED,
2020
.partition_description = "Application",
21-
.partition_start_addr = 0x18001000,
22-
.partition_length = 0xBF000, // 764K bytes
21+
.partition_start_addr = 0x18004000,
22+
.partition_length = 0x1f4000,//0xBF000, // 764K bytes
2323
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
2424
},
25-
#if 0
25+
#if 1
2626
[HAL_PARTITION_OTA_TEMP] =
2727
{
2828
.partition_owner = HAL_FLASH_EMBEDDED,
2929
.partition_description = "OTA Storage",
30-
.partition_start_addr = 0x18100000,
31-
.partition_length = 0x100000, //1M bytes
30+
.partition_start_addr = 0x181f8000, //0x18100000,
31+
.partition_length = 0xAF000,//700k //0x1f4000, // 2000k //0x100000, //1M bytes
3232
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
3333
},
3434
#endif
3535
[HAL_PARTITION_PARAMETER_1] =
3636
{
3737
.partition_owner = HAL_FLASH_EMBEDDED,
3838
.partition_description = "PARAMETER1",
39-
.partition_start_addr = 0x180C0000,
39+
.partition_start_addr = 0x183ec000,//0x180C0000,
4040
.partition_length = 0x1000, //4k bytes
4141
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
4242
},
4343
[HAL_PARTITION_PARAMETER_2] =
4444
{
4545
.partition_owner = HAL_FLASH_EMBEDDED,
4646
.partition_description = "PARAMETER2",
47-
.partition_start_addr = 0x180C1000,
47+
.partition_start_addr = 0x183ed000,//0x180C1000,
4848
.partition_length = 0x2000, //8k bytes
4949
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
5050
},
5151
[HAL_PARTITION_PARAMETER_3] =
5252
{
5353
.partition_owner = HAL_FLASH_EMBEDDED,
5454
.partition_description = "PARAMETER3",
55-
.partition_start_addr = 0x180C3000,
55+
.partition_start_addr = 0x183ef000,//0x180C3000,
5656
.partition_length = 0x1000, //4k bytes
5757
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
5858
},
5959
[HAL_PARTITION_PARAMETER_4] =
6060
{
6161
.partition_owner = HAL_FLASH_EMBEDDED,
6262
.partition_description = "PARAMETER4",
63-
.partition_start_addr = 0x180C4000,
63+
.partition_start_addr = 0x183F0000, //0x180C4000,
6464
.partition_length = 0x1000, //4k bytes
6565
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
6666
},
6767
};
6868

69+
extern uart_dev_t uart_0;
6970
void board_init(void)
7071
{
72+
hal_uart_init(&uart_0);
7173
}

board/uno-91h/uno-91h.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ GLOBAL_INCLUDES += .
1313
GLOBAL_DEFINES += STDIO_UART=0
1414
GLOBAL_DEFINES += RHINO_CONFIG_TICK_TASK=0 RHINO_CONFIG_WORKQUEUE=0
1515

16-
#CURRENT_TIME = $(shell /bin/date +%Y%m%d.%H%M)
17-
CURRENT_TIME = $(/bin/date +%Y%m%d.%H%M)
18-
CONFIG_SYSINFO_KERNEL_VERSION = AOS-R-1.3.0
16+
CURRENT_TIME := $(shell $(DATE) +%Y%m%d.%H%M)
17+
#CURRENT_TIME = $(/bin/date +%Y%m%d.%H%M)
18+
#CURRENT_TIME = 20180425.2039
19+
#CONFIG_SYSINFO_KERNEL_VERSION = AOS-R-1.0.1
1920

2021
CONFIG_SYSINFO_OS_VERSION := $(call get-os-version)
2122

platform/mcu/rda5981x/aos/aos.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ extern int aos_framework_init(void);
1717

1818
extern void hw_start_hal(void);
1919

20+
void hal_init()
21+
{
22+
board_init();
23+
}
24+
2025
static void sys_init(void)
2126
{
2227
LOG("sys_init.");
@@ -25,7 +30,7 @@ static void sys_init(void)
2530
#ifdef BOOTLOADER
2631
main();
2732
#else
28-
//hal_init();
33+
hal_init();
2934
hw_start_hal();
3035
vfs_init();
3136
vfs_device_init();

platform/mcu/rda5981x/driver/PeripheralNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define MBED_PERIPHERALNAMES_H
1818

1919
#include "cmsis.h"
20-
#include "pinnames.h"
20+
#include "PinNames.h"
2121

2222
#ifdef __cplusplus
2323
extern "C" {

platform/mcu/rda5981x/driver/objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "cmsis.h"
2020
#include "PortNames.h"
2121
#include "PeripheralNames.h"
22-
#include "pinnames.h"
22+
#include "PinNames.h"
2323
#include "gpio_object.h"
2424

2525
#ifdef __cplusplus

platform/mcu/rda5981x/driver/rda_flash.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@ void rda5981_spi_erase_partition(void *src, r_u32 counts)
7575
if (a64kend > a64k) {
7676
if (atmp == a64k) {
7777
for (; atmp < a64kend; atmp += (0x01UL << 16)) {
78+
core_util_critical_section_enter();
7879
rda5981_spi_flash_erase_64KB_block(atmp);
80+
core_util_critical_section_exit();
7981
}
8082
if (atmp == a4kend)
8183
break;
8284
}
8385
}
86+
core_util_critical_section_enter();
8487
rda5981_spi_flash_erase_4KB_sector(atmp);
88+
core_util_critical_section_exit();
8589
}
8690
}
8791
}
@@ -102,9 +106,9 @@ int rda5981_erase_flash(r_u32 addr, r_u32 len)
102106
len = ((len+SECTOR_SIZE) & (~(SECTOR_SIZE-1)));
103107
}
104108

105-
core_util_critical_section_enter();
109+
//core_util_critical_section_enter();
106110
rda5981_spi_erase_partition((void*)addr, len);
107-
core_util_critical_section_exit();
111+
//core_util_critical_section_exit();
108112
return 0;
109113
}
110114

platform/mcu/rda5981x/driver/rda_flash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
#define SECTOR_SIZE 4096
16-
#define FLASH_SIZE 0x100000
16+
#define FLASH_SIZE 0x400000
1717

1818
#define RDA5991H_PARTITION_TABLE_END_ADDR 0x18001000 //partition table end addr
1919

platform/mcu/rda5981x/hal/hw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ void hal_timer_stop(timer_dev_t *tmr)
7070
}
7171
#endif
7272
extern hal_wifi_module_t aos_wifi_rda59xx;
73-
//extern struct hal_ota_module_s stm32l475_ota_module;
73+
extern struct hal_ota_module_s rda59xx_ota_module;
7474
void hw_start_hal(void)
7575
{
7676
printf("start-----------hal\n");
7777
hal_wifi_register_module(&aos_wifi_rda59xx);
7878
aos_wifi_rda59xx.init(&aos_wifi_rda59xx);
79-
//hal_ota_register_module(&stm32l475_ota_module);
79+
hal_ota_register_module(&rda59xx_ota_module);
8080
}
8181

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <stdlib.h>
4+
#include <unistd.h>
5+
6+
#include <errno.h>
7+
#include <hal/ota.h>
8+
#include <aos/log.h>
9+
#include <hal/soc/soc.h>
10+
11+
#include "rda_def.h"
12+
#include "rda_flash.h"
13+
14+
r_u32 g_crc_result = ~0UL;
15+
r_u32 g_ota_off_set = 0;
16+
17+
#define CRC32_TABLE_ADDR 0xbb5c
18+
#define CRC32_ADDR 0x8dff
19+
#define CRC32_TABLE_ADDR_4 0xbbd8
20+
#define CRC32_ADDR_4 0x8e33
21+
#define IMAGE_MAGIC 0xAEAE
22+
23+
static r_u32 bootrom_crc32(r_u8 *p, r_u32 len)
24+
{
25+
r_u32 func = CRC32_ADDR;
26+
if (rda_ccfg_hwver() >= 4) {
27+
func = CRC32_ADDR_4;
28+
}
29+
return ((r_u32(*)(r_u8 *, r_u32))func)(p, len);
30+
}
31+
32+
static r_u32 crc32(const r_u8 *p, r_u32 len, r_u32 crc)
33+
{
34+
const r_u32 *crc32_tab = (const r_u32 *)CRC32_TABLE_ADDR;
35+
36+
if (rda_ccfg_hwver() >= 4) {
37+
crc32_tab = (const r_u32 *)CRC32_TABLE_ADDR_4;
38+
}
39+
/* Calculate CRC */
40+
while (len--)
41+
{
42+
crc = crc32_tab[((crc & 0xFF) ^ *p++)] ^ (crc >> 8);
43+
}
44+
45+
return crc;
46+
}
47+
48+
static r_s32 rda59xx_ota_init(hal_ota_module_t *m, void *something)
49+
{
50+
printf("========= OTA init ========= \r\n");
51+
g_ota_off_set = *(r_u32*)something;
52+
hal_partition_t pno = HAL_PARTITION_OTA_TEMP;
53+
hal_logic_partition_t *partition_info;
54+
partition_info = hal_flash_get_info(pno);
55+
//g_ota_partition_len = partition_info->partition_length;
56+
if (g_ota_off_set == 0) {
57+
hal_flash_erase(pno, 0, partition_info->partition_length);
58+
} else {
59+
printf("OTA init invalid, offset = %d \r\n", g_ota_off_set);
60+
}
61+
62+
return 0;
63+
}
64+
65+
static r_s32 rda59xx_ota_write(hal_ota_module_t *m, volatile r_u32* off_set, r_u8* in_buf ,r_u32 in_buf_len)
66+
{
67+
r_s32 ret;
68+
69+
hal_partition_t pno = HAL_PARTITION_OTA_TEMP;
70+
printf("========= OTA write start: len: %d ==========\r\n", in_buf_len);
71+
g_crc_result = crc32(in_buf, in_buf_len, g_crc_result);
72+
ret = hal_flash_write(pno, &g_ota_off_set, in_buf, in_buf_len);
73+
g_ota_off_set += in_buf_len;
74+
return ret;
75+
}
76+
77+
static r_s32 rda59xx_ota_read(hal_ota_module_t *m, volatile r_u32* off_set, r_u8* out_buf, r_u32 out_buf_len)
78+
{
79+
hal_partition_t pno = HAL_PARTITION_OTA_TEMP;
80+
hal_flash_read(pno, off_set, out_buf, out_buf_len);
81+
82+
return 0;
83+
}
84+
85+
static r_s32 rda59xx_ota_set_boot(hal_ota_module_t *m, void *something)
86+
{
87+
printf("========= OTA boot set ========= \r\n");
88+
hal_logic_partition_t *partition_info;
89+
hal_partition_t pno = HAL_PARTITION_OTA_TEMP;
90+
ota_finish_param_t *param = (ota_finish_param_t *)something;
91+
if (param==NULL) {
92+
return -1;
93+
}
94+
if (param->result_type == OTA_FINISH) {
95+
partition_info = hal_flash_get_info(pno);
96+
core_util_critical_section_enter();
97+
spi_flash_flush_cache();
98+
r_u32 crc32_check = bootrom_crc32((r_u8 *)partition_info->partition_start_addr, g_ota_off_set);
99+
core_util_critical_section_exit();
100+
printf("rda5981_write_partition_end:0x%08x:0x%08x\r\n", g_crc_result, crc32_check);
101+
if (crc32_check == g_crc_result) {
102+
hal_reboot();
103+
} else {
104+
printf("ERROR!!! check crc32 error\r\n");
105+
}
106+
} else if (param->result_type==OTA_BREAKPOINT) {
107+
printf("OTA package is incomplete!\r\n");
108+
}
109+
return 0;
110+
}
111+
112+
struct hal_ota_module_s rda59xx_ota_module = {
113+
.init = rda59xx_ota_init,
114+
.ota_write = rda59xx_ota_write,
115+
.ota_read = rda59xx_ota_read,
116+
.ota_set_boot = rda59xx_ota_set_boot,
117+
};

platform/mcu/rda5981x/hal/rda_ccfg_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ int rda_ccfg_boot(void)
284284
if(!abort_flag) {
285285
rda_ccfg_pdi2c();
286286
}
287-
//rda_ccfg_ck();
287+
rda_ccfg_ck();
288288
#endif /* RDA5991H_HW_VER */
289289
/* Set flash clock */
290290
rda_ccfg_spifck();

0 commit comments

Comments
 (0)