Skip to content

Commit 9b81abd

Browse files
committed
Added support for some new custom IHX record types which will be used to implement further bootloader functionality.
1 parent 771fc76 commit 9b81abd

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/intel_hex.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ uint8_t ihx_check_line(char line[]) {
6565

6666
checksum = ihx_data_byte(line, byte_count);
6767

68-
if (record_type > 1)
68+
if (record_type > 0x01 && (record_type < 0x22 || record_type > 0x25))
6969
return IHX_BAD_RECORD_TYPE;
7070

71-
if (record_type != IHX_RECORD_EOF && (address < USER_CODE_BASE || address > FLASH_SIZE))
71+
if ((record_type == IHX_RECORD_DATA || record_type == IHX_RECORD_READ) && \
72+
(address < USER_CODE_BASE || address > FLASH_SIZE))
7273
return IHX_BAD_ADDRESS;
7374

7475
sum = 0;

src/intel_hex.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@
3434
#define IHX_RECORD_DATA 0x00
3535
#define IHX_RECORD_EOF 0x01
3636

37+
// Custom record types used to implement some extra bootloader functionality.
38+
39+
// Reset record will reset the page erase map which usually ensures each page is only
40+
// erased once, allowing for random writes but preventing overwriting of data already written
41+
// this session.
42+
// :00000022DE
43+
#define IHX_RECORD_RESET 0x22
44+
45+
// Erases all of the user code flash pages
46+
// :00000023DD
47+
#define IHX_RECORD_ERASE_ALL 0x23
48+
49+
// Erases a single page of the user code flash
50+
// :01000024xxyy
51+
// xx - Page number, yy - Checksum
52+
#define IHX_RECORD_ERASE_PAGE 0x24
53+
54+
// Reads back a section of flash in Intel HEX format
55+
// :04xxxx24yyyyzz
56+
// xxxx - Start address, yyyy - Num bytes to read, zz - Checksum
57+
#define IHX_RECORD_READ 0x25
58+
59+
3760
uint8_t hex4(char c);
3861
uint8_t hex8(char s[]);
3962
uint16_t hex16(char s[]);

0 commit comments

Comments
 (0)