Skip to content

Commit f3cb4c1

Browse files
authored
Merge pull request #57 from Pavlos1/master
BL808 Support
1 parent 5580eec commit f3cb4c1

File tree

12 files changed

+848
-101
lines changed

12 files changed

+848
-101
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ add_library(libblisp_obj OBJECT
1414
lib/blisp_easy.c
1515
lib/blisp_util.c
1616
lib/chip/blisp_chip_bl60x.c
17-
lib/chip/blisp_chip_bl70x.c)
17+
lib/chip/blisp_chip_bl70x.c
18+
lib/chip/blisp_chip_bl808.c)
1819

1920
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/include/)
2021
if (NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")

include/blisp.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct blisp_segment_header {
1616
struct blisp_device {
1717
struct blisp_chip* chip;
1818
void* serial_port;
19+
uint32_t serial_timeout; // in ms
1920
bool is_usb;
2021
uint32_t current_baud_rate;
2122
uint8_t rx_buffer[5000]; // TODO:
@@ -32,33 +33,41 @@ struct blisp_boot_info {
3233
// image_run, image_check etc.
3334

3435
blisp_return_t blisp_device_init(struct blisp_device* device, struct blisp_chip* chip);
35-
blisp_return_t blisp_device_open(struct blisp_device* device, const char* port_name);
36+
blisp_return_t blisp_device_open(struct blisp_device* device, const char* port_name,
37+
uint32_t baudrate);
3638
blisp_return_t blisp_device_handshake(struct blisp_device* device, bool in_ef_loader);
3739
blisp_return_t blisp_device_get_boot_info(struct blisp_device* device,
38-
struct blisp_boot_info* boot_info);
40+
struct blisp_boot_info* boot_info);
3941
blisp_return_t blisp_device_load_boot_header(struct blisp_device* device,
40-
uint8_t* boot_header);
42+
uint8_t* boot_header);
43+
4144
blisp_return_t blisp_device_load_segment_header(
4245
struct blisp_device* device,
4346
struct blisp_segment_header* segment_header);
4447
blisp_return_t blisp_device_load_segment_data(struct blisp_device* device,
45-
uint8_t* segment_data,
46-
uint32_t segment_data_length);
48+
uint8_t* segment_data,
49+
uint32_t segment_data_length);
4750
blisp_return_t blisp_device_write_memory(struct blisp_device* device,
48-
uint32_t address,
49-
uint32_t value,
50-
bool wait_for_res);
51+
uint32_t address,
52+
uint32_t value,
53+
bool wait_for_res);
5154
blisp_return_t blisp_device_check_image(struct blisp_device* device);
5255
blisp_return_t blisp_device_run_image(struct blisp_device* device);
5356
blisp_return_t blisp_device_flash_erase(struct blisp_device* device,
54-
uint32_t start_address,
55-
uint32_t end_address);
57+
uint32_t start_address,
58+
uint32_t end_address);
59+
blisp_return_t blisp_device_chip_erase(struct blisp_device* device);
5660
blisp_return_t blisp_device_flash_write(struct blisp_device* device,
57-
uint32_t start_address,
58-
uint8_t* payload,
59-
uint32_t payload_size);
61+
uint32_t start_address,
62+
uint8_t* payload,
63+
uint32_t payload_size);
64+
6065
blisp_return_t blisp_device_program_check(struct blisp_device* device);
6166
blisp_return_t blisp_device_reset(struct blisp_device* device);
6267
void blisp_device_close(struct blisp_device* device);
6368

64-
#endif
69+
blisp_return_t bl808_load_clock_para(struct blisp_device* device,
70+
bool irq_en, uint32_t baudrate);
71+
blisp_return_t bl808_load_flash_para(struct blisp_device* device);
72+
73+
#endif

include/blisp_chip.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ extern struct blisp_chip blisp_chip_bl70x;
2828
extern struct blisp_chip blisp_chip_bl808;
2929
extern struct blisp_chip blisp_chip_bl61x;
3030

31-
#endif
31+
extern struct bl808_bootheader_t bl808_header;
32+
void fill_crcs(struct bl808_bootheader_t *bh);
33+
34+
#endif

include/blisp_struct.h

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,212 @@ struct blflash_segment_header {
173173
static_assert(sizeof(struct blflash_segment_header) == 16,
174174
"Segment header have wrong size");
175175

176+
struct bl808_spi_flash_cfg_t {
177+
uint8_t ioMode; /*!< Serail flash interface mode,bit0-3:IF mode,bit4:unwrap */
178+
uint8_t cReadSupport; /*!< Support continuous read mode,bit0:continuous read mode support,bit1:read mode cfg */
179+
uint8_t clkDelay; /*!< SPI clock delay,bit0-3:delay,bit4-6:pad delay */
180+
uint8_t clkInvert; /*!< SPI clock phase invert,bit0:clck invert,bit1:rx invert,bit2-4:pad delay,bit5-7:pad delay */
181+
uint8_t resetEnCmd; /*!< Flash enable reset command */
182+
uint8_t resetCmd; /*!< Flash reset command */
183+
uint8_t resetCreadCmd; /*!< Flash reset continuous read command */
184+
uint8_t resetCreadCmdSize; /*!< Flash reset continuous read command size */
185+
uint8_t jedecIdCmd; /*!< JEDEC ID command */
186+
uint8_t jedecIdCmdDmyClk; /*!< JEDEC ID command dummy clock */
187+
uint8_t enter32BitsAddrCmd; /*!< Enter 32-bits addr command */
188+
uint8_t exit32BitsAddrCmd; /*!< Exit 32-bits addr command */
189+
uint8_t sectorSize; /*!< *1024bytes */
190+
uint8_t mid; /*!< Manufacturer ID */
191+
uint16_t pageSize; /*!< Page size */
192+
uint8_t chipEraseCmd; /*!< Chip erase cmd */
193+
uint8_t sectorEraseCmd; /*!< Sector erase command */
194+
uint8_t blk32EraseCmd; /*!< Block 32K erase command,some Micron not support */
195+
uint8_t blk64EraseCmd; /*!< Block 64K erase command */
196+
uint8_t writeEnableCmd; /*!< Need before every erase or program */
197+
uint8_t pageProgramCmd; /*!< Page program cmd */
198+
uint8_t qpageProgramCmd; /*!< QIO page program cmd */
199+
uint8_t qppAddrMode; /*!< QIO page program address mode */
200+
uint8_t fastReadCmd; /*!< Fast read command */
201+
uint8_t frDmyClk; /*!< Fast read command dummy clock */
202+
uint8_t qpiFastReadCmd; /*!< QPI fast read command */
203+
uint8_t qpiFrDmyClk; /*!< QPI fast read command dummy clock */
204+
uint8_t fastReadDoCmd; /*!< Fast read dual output command */
205+
uint8_t frDoDmyClk; /*!< Fast read dual output command dummy clock */
206+
uint8_t fastReadDioCmd; /*!< Fast read dual io comamnd */
207+
uint8_t frDioDmyClk; /*!< Fast read dual io command dummy clock */
208+
uint8_t fastReadQoCmd; /*!< Fast read quad output comamnd */
209+
uint8_t frQoDmyClk; /*!< Fast read quad output comamnd dummy clock */
210+
uint8_t fastReadQioCmd; /*!< Fast read quad io comamnd */
211+
uint8_t frQioDmyClk; /*!< Fast read quad io comamnd dummy clock */
212+
uint8_t qpiFastReadQioCmd; /*!< QPI fast read quad io comamnd */
213+
uint8_t qpiFrQioDmyClk; /*!< QPI fast read QIO dummy clock */
214+
uint8_t qpiPageProgramCmd; /*!< QPI program command */
215+
uint8_t writeVregEnableCmd; /*!< Enable write reg */
216+
uint8_t wrEnableIndex; /*!< Write enable register index */
217+
uint8_t qeIndex; /*!< Quad mode enable register index */
218+
uint8_t busyIndex; /*!< Busy status register index */
219+
uint8_t wrEnableBit; /*!< Write enable bit pos */
220+
uint8_t qeBit; /*!< Quad enable bit pos */
221+
uint8_t busyBit; /*!< Busy status bit pos */
222+
uint8_t wrEnableWriteRegLen; /*!< Register length of write enable */
223+
uint8_t wrEnableReadRegLen; /*!< Register length of write enable status */
224+
uint8_t qeWriteRegLen; /*!< Register length of contain quad enable */
225+
uint8_t qeReadRegLen; /*!< Register length of contain quad enable status */
226+
uint8_t releasePowerDown; /*!< Release power down command */
227+
uint8_t busyReadRegLen; /*!< Register length of contain busy status */
228+
uint8_t readRegCmd[4]; /*!< Read register command buffer */
229+
uint8_t writeRegCmd[4]; /*!< Write register command buffer */
230+
uint8_t enterQpi; /*!< Enter qpi command */
231+
uint8_t exitQpi; /*!< Exit qpi command */
232+
uint8_t cReadMode; /*!< Config data for continuous read mode */
233+
uint8_t cRExit; /*!< Config data for exit continuous read mode */
234+
uint8_t burstWrapCmd; /*!< Enable burst wrap command */
235+
uint8_t burstWrapCmdDmyClk; /*!< Enable burst wrap command dummy clock */
236+
uint8_t burstWrapDataMode; /*!< Data and address mode for this command */
237+
uint8_t burstWrapData; /*!< Data to enable burst wrap */
238+
uint8_t deBurstWrapCmd; /*!< Disable burst wrap command */
239+
uint8_t deBurstWrapCmdDmyClk; /*!< Disable burst wrap command dummy clock */
240+
uint8_t deBurstWrapDataMode; /*!< Data and address mode for this command */
241+
uint8_t deBurstWrapData; /*!< Data to disable burst wrap */
242+
uint16_t timeEsector; /*!< 4K erase time */
243+
uint16_t timeE32k; /*!< 32K erase time */
244+
uint16_t timeE64k; /*!< 64K erase time */
245+
uint16_t timePagePgm; /*!< Page program time */
246+
uint16_t timeCe; /*!< Chip erase time in ms */
247+
uint8_t pdDelay; /*!< Release power down command delay time for wake up */
248+
uint8_t qeData; /*!< QE set data */
249+
};
250+
251+
struct bl808_boot_flash_cfg_t {
252+
uint32_t magiccode;
253+
struct bl808_spi_flash_cfg_t cfg;
254+
uint32_t crc32;
255+
};
256+
257+
struct bl808_sys_clk_cfg_t {
258+
uint8_t xtal_type;
259+
uint8_t mcu_clk;
260+
uint8_t mcu_clk_div;
261+
uint8_t mcu_bclk_div;
262+
263+
uint8_t mcu_pbclk_div;
264+
uint8_t lp_div;
265+
uint8_t dsp_clk;
266+
uint8_t dsp_clk_div;
267+
268+
uint8_t dsp_bclk_div;
269+
uint8_t dsp_pbclk;
270+
uint8_t dsp_pbclk_div;
271+
uint8_t emi_clk;
272+
273+
uint8_t emi_clk_div;
274+
uint8_t flash_clk_type;
275+
uint8_t flash_clk_div;
276+
uint8_t wifipll_pu;
277+
278+
uint8_t aupll_pu;
279+
uint8_t cpupll_pu;
280+
uint8_t mipipll_pu;
281+
uint8_t uhspll_pu;
282+
};
283+
284+
struct bl808_boot_clk_cfg_t {
285+
uint32_t magiccode;
286+
struct bl808_sys_clk_cfg_t cfg;
287+
uint32_t crc32;
288+
};
289+
290+
struct bl808_boot_basic_cfg_t {
291+
uint32_t sign_type : 2; /* [1: 0] for sign */
292+
uint32_t encrypt_type : 2; /* [3: 2] for encrypt */
293+
uint32_t key_sel : 2; /* [5: 4] key slot */
294+
uint32_t xts_mode : 1; /* [6] for xts mode */
295+
uint32_t aes_region_lock : 1; /* [7] rsvd */
296+
uint32_t no_segment : 1; /* [8] no segment info */
297+
uint32_t rsvd_0 : 1; /* [9] boot2 enable(rsvd_0) */
298+
uint32_t rsvd_1 : 1; /* [10] boot2 rollback(rsvd_1) */
299+
uint32_t cpu_master_id : 4; /* [14: 11] master id */
300+
uint32_t notload_in_bootrom : 1; /* [15] notload in bootrom */
301+
uint32_t crc_ignore : 1; /* [16] ignore crc */
302+
uint32_t hash_ignore : 1; /* [17] hash ignore */
303+
uint32_t power_on_mm : 1; /* [18] power on mm */
304+
uint32_t em_sel : 3; /* [21: 19] em_sel */
305+
uint32_t cmds_en : 1; /* [22] command spliter enable */
306+
uint32_t cmds_wrap_mode : 2; /* [24: 23] cmds wrap mode */
307+
uint32_t cmds_wrap_len : 4; /* [28: 25] cmds wrap len */
308+
uint32_t icache_invalid : 1; /* [29] icache invalid */
309+
uint32_t dcache_invalid : 1; /* [30] dcache invalid */
310+
uint32_t rsvd_3 : 1; /* [31] rsvd_3 */
311+
312+
uint32_t group_image_offset; /* flash controller offset */
313+
uint32_t aes_region_len; /* aes region length */
314+
315+
uint32_t img_len_cnt; /* image length or segment count */
316+
uint32_t hash[32 / 4]; /* hash of the image */
317+
};
318+
319+
struct bl808_boot_cpu_cfg_t {
320+
uint8_t config_enable; /* coinfig this cpu */
321+
uint8_t halt_cpu; /* halt this cpu */
322+
uint8_t cache_enable : 1; /* cache setting */
323+
uint8_t cache_wa : 1; /* cache setting */
324+
uint8_t cache_wb : 1; /* cache setting */
325+
uint8_t cache_wt : 1; /* cache setting */
326+
uint8_t cache_way_dis : 4; /* cache setting */
327+
uint8_t rsvd;
328+
329+
uint32_t cache_range_h; /* cache range high */
330+
uint32_t cache_range_l; /* cache range low */
331+
332+
uint32_t image_address_offset; /* image_address_offset */
333+
uint32_t rsvd0; /* rsvd0 */
334+
uint32_t msp_val; /* msp value */
335+
};
336+
337+
struct bl808_aesiv_cfg_t {
338+
uint8_t aesiv[16];
339+
uint32_t crc32;
340+
};
341+
342+
struct bl808_pkey_cfg_t {
343+
uint8_t eckeyx[32]; /* ec key in boot header */
344+
uint8_t eckeyy[32]; /* ec key in boot header */
345+
uint32_t crc32;
346+
};
347+
348+
struct bl808_sign_cfg_t {
349+
uint32_t sig_len;
350+
uint8_t signature[32];
351+
uint32_t crc32;
352+
};
353+
354+
struct bl808_bootheader_t {
355+
uint32_t magiccode; /* 4 */
356+
uint32_t rivison; /* 4 */
357+
358+
struct bl808_boot_flash_cfg_t flash_cfg; /* 4 + 84 + 4 */
359+
struct bl808_boot_clk_cfg_t clk_cfg; /* 4 + 20 + 4 */
360+
361+
struct bl808_boot_basic_cfg_t basic_cfg; /* 4 + 4 + 4 + 4 + 4*8 */
362+
363+
struct bl808_boot_cpu_cfg_t cpu_cfg[3]; /*24*3 */
364+
365+
uint32_t boot2_pt_table_0_rsvd; /* address of partition table 0 */ /* 4 */
366+
uint32_t boot2_pt_table_1_rsvd; /* address of partition table 1 */ /* 4 */
367+
368+
uint32_t flash_cfg_table_addr; /* address of flashcfg table list */ /* 4 */
369+
uint32_t flash_cfg_table_len; /* flashcfg table list len */ /* 4 */
370+
371+
uint32_t rsvd0[8]; /* rsvd */
372+
uint32_t rsvd1[8]; /* rsvd */
373+
374+
uint32_t rsvd3[5]; /* 20 */
375+
376+
uint32_t crc32; /* 4 */
377+
};
378+
379+
static_assert(sizeof(struct bl808_bootheader_t) == 352,
380+
"BL808 bootheader size mismatch");
381+
176382
#pragma pack(pop)
177383

178384
#endif

include/blisp_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
void blisp_dlog(const char* format, ...);
1313

14+
void blisp_dlog_no_nl(const char* format, ...);
15+
1416
void sleep_ms(int milliseconds);
1517

1618
uint32_t crc32_calculate(const void *data, size_t data_len);

0 commit comments

Comments
 (0)