mirror of https://github.com/Nonannet/copapy.git
command ids updated to include header size
This commit is contained in:
parent
8f9cd96973
commit
33b833c41a
|
|
@ -4,19 +4,20 @@ import struct
|
||||||
|
|
||||||
ByteOrder = Literal['little', 'big']
|
ByteOrder = Literal['little', 'big']
|
||||||
|
|
||||||
Command = Enum('Command', [('ALLOCATE_DATA', 1), ('COPY_DATA', 2),
|
# header lengths in bytes, command id
|
||||||
('ALLOCATE_CODE', 3), ('COPY_CODE', 4),
|
Command = Enum('Command', [('ALLOCATE_DATA', 0x04_0001), ('COPY_DATA', 0x08_0002),
|
||||||
('PATCH_FUNC', 0x1000),
|
('ALLOCATE_CODE', 0x04_0003), ('COPY_CODE', 0x08_0004),
|
||||||
('PATCH_FUNC_ARM32_THM', 0x1005),
|
('PATCH_FUNC', 0x10_1000),
|
||||||
('PATCH_OBJECT', 0x2000),
|
('PATCH_FUNC_ARM32_THM', 0x10_1005),
|
||||||
('PATCH_OBJECT_HI21', 0x2001),
|
('PATCH_OBJECT', 0x10_2000),
|
||||||
('PATCH_OBJECT_ABS', 0x2002),
|
('PATCH_OBJECT_HI21', 0x10_2001),
|
||||||
('PATCH_OBJECT_REL', 0x2003),
|
('PATCH_OBJECT_ABS', 0x10_2002),
|
||||||
('PATCH_OBJECT_ARM32_ABS', 0x2004),
|
('PATCH_OBJECT_REL', 0x10_2003),
|
||||||
('PATCH_OBJECT_ARM32_ABS_THM', 0x2006),
|
('PATCH_OBJECT_ARM32_ABS', 0x10_2004),
|
||||||
('ENTRY_POINT', 7),
|
('PATCH_OBJECT_ARM32_ABS_THM', 0x10_2006),
|
||||||
('RUN_PROG', 64), ('READ_DATA', 65),
|
('ENTRY_POINT', 0x04_0007),
|
||||||
('END_COM', 256), ('FREE_MEMORY', 257), ('DUMP_CODE', 258)])
|
('RUN_PROG', 0x00_0040), ('READ_DATA', 0x08_0041),
|
||||||
|
('END_COM', 0x00_0100), ('FREE_MEMORY', 0x00_0101), ('DUMP_CODE', 0x00_0102)])
|
||||||
COMMAND_SIZE = 4
|
COMMAND_SIZE = 4
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,28 +22,40 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Command opcodes used by the parser */
|
/* Command opcodes used by the parser */
|
||||||
#define ALLOCATE_DATA 1
|
#define ALLOCATE_DATA 0x040001
|
||||||
#define COPY_DATA 2
|
#define COPY_DATA 0x080002
|
||||||
#define ALLOCATE_CODE 3
|
#define ALLOCATE_CODE 0x040003
|
||||||
#define COPY_CODE 4
|
#define COPY_CODE 0x080004
|
||||||
#define PATCH_FUNC 0x1000
|
#define PATCH_FUNC 0x101000
|
||||||
#define PATCH_FUNC_ARM32_THM 0x1005
|
#define PATCH_FUNC_ARM32_THM 0x101005
|
||||||
#define PATCH_OBJECT 0x2000
|
#define PATCH_OBJECT 0x102000
|
||||||
#define PATCH_OBJECT_HI21 0x2001
|
#define PATCH_OBJECT_HI21 0x102001
|
||||||
#define PATCH_OBJECT_ABS 0x2002
|
#define PATCH_OBJECT_ABS 0x102002
|
||||||
#define PATCH_OBJECT_REL 0x2003
|
#define PATCH_OBJECT_REL 0x102003
|
||||||
#define PATCH_OBJECT_ARM32_ABS 0x2004
|
#define PATCH_OBJECT_ARM32_ABS 0x102004
|
||||||
#define PATCH_OBJECT_ARM32_ABS_THM 0x2006
|
#define PATCH_OBJECT_ARM32_ABS_THM 0x102006
|
||||||
#define ENTRY_POINT 7
|
#define ENTRY_POINT 0x040007
|
||||||
#define RUN_PROG 64
|
#define RUN_PROG 0x000040
|
||||||
#define READ_DATA 65
|
#define READ_DATA 0x080041
|
||||||
#define END_COM 256
|
#define END_COM 0x000100
|
||||||
#define FREE_MEMORY 257
|
#define FREE_MEMORY 0x000101
|
||||||
#define DUMP_CODE 258
|
#define DUMP_CODE 0x000102
|
||||||
|
|
||||||
/* Entry point type */
|
/* Entry point type */
|
||||||
typedef int (*entry_point_t)(void);
|
typedef int (*entry_point_t)(void);
|
||||||
|
|
||||||
|
/* rx_state */
|
||||||
|
#define RX_STATE_IDLE 0
|
||||||
|
#define RX_STATE_HEADER 1
|
||||||
|
#define RX_STATE_DATA 2
|
||||||
|
|
||||||
|
/* state_flag */
|
||||||
|
#define STATE_FLAG_NONE 0
|
||||||
|
#define STATE_FLAG_END_COM 1
|
||||||
|
#define STATE_FLAG_DUMP_CODE 2
|
||||||
|
#define STATE_FLAG_UNKNOWN_COMMAND -1
|
||||||
|
#define STATE_FLAG_MEM_DIST -4 //code and data memory to far apart
|
||||||
|
|
||||||
/* Struct for run-time memory state */
|
/* Struct for run-time memory state */
|
||||||
typedef struct runmem_s {
|
typedef struct runmem_s {
|
||||||
uint8_t *data_memory; // Pointer to data memory
|
uint8_t *data_memory; // Pointer to data memory
|
||||||
|
|
@ -52,13 +64,18 @@ typedef struct runmem_s {
|
||||||
uint32_t executable_memory_len; // Length of executable memory
|
uint32_t executable_memory_len; // Length of executable memory
|
||||||
int data_offs; // Offset of data memory relative to executable memory
|
int data_offs; // Offset of data memory relative to executable memory
|
||||||
entry_point_t entr_point; // Entry point function pointer
|
entry_point_t entr_point; // Entry point function pointer
|
||||||
|
int32_t rx_state; // State for receiving commands (idle, header, data)
|
||||||
|
int32_t state_flag; // Flag for result/error state
|
||||||
|
uint8_t *data_src;
|
||||||
|
uint8_t *data_dest;
|
||||||
|
uint32_t data_size;
|
||||||
} runmem_t;
|
} runmem_t;
|
||||||
|
|
||||||
/* Command parser: takes a pointer to the command stream and returns
|
/* Command parser: takes a pointer to the command stream and returns
|
||||||
an error flag (0 on success according to current code) */
|
an error flag (0 on success according to current code) */
|
||||||
int parse_commands(runmem_t *context, uint8_t *bytes);
|
int parse_commands(runmem_t *context, uint8_t *bytes, uint32_t lengths);
|
||||||
|
|
||||||
/* Free program and data memory */
|
/* Free program and data memory */
|
||||||
void free_memory(runmem_t *context);
|
void free_memory(runmem_t *context);
|
||||||
|
|
||||||
#endif /* RUNMEM_H */
|
#endif /* RUNMEM_H */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue