Skip to content

Commit

Permalink
Add documentation about the checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
chenguokai committed Apr 13, 2020
1 parent 6515e57 commit 1047fdd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ want to disassemble the code at 0x20000000, use:\
(gdb) disassemble 0x20000001
```

Checksum of binary file
-----------------------

When flashing a file, the checksum of which is calculated, both in md5 and the sum algorithm used by ST's official tool. The detail of sum algorithm can be found in [https://www.st.com/resource/en/user_manual/cd00262073-stm32-stlink-utility-software-description-stmicroelectronics.pdf](https://www.st.com/resource/en/user_manual/cd00262073-stm32-stlink-utility-software-description-stmicroelectronics.pdf).

References
==========

Expand Down
22 changes: 11 additions & 11 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ static int check_file(stlink_t* sl, mapped_file_t* mf, stm32_addr_t addr) {
return 0;
}

static void md5_calculate(mapped_file_t *mf, const char *path) {
static void md5_calculate(mapped_file_t *mf) {
/* calculate md5 checksum of given binary file */
Md5Context md5Context;
MD5_HASH md5Hash;
Expand All @@ -1380,7 +1380,7 @@ static void md5_calculate(mapped_file_t *mf, const char *path) {
printf(", ");
}

static void stlink_checksum(mapped_file_t *mp, const char* path) {
static void stlink_checksum(mapped_file_t *mp) {
/* checksum that backward compatible with official ST tools */
uint32_t sum = 0;
uint8_t *mp_byte = (uint8_t *)mp->base;
Expand Down Expand Up @@ -1470,9 +1470,9 @@ int stlink_fwrite_sram(stlink_t * sl, const char* path, stm32_addr_t addr) {
fprintf(stderr, "map_file() == -1\n");
return -1;
}
printf("file %s ");
md5_calculate(&mf, path);
stlink_checksum(&mf, path);
printf("file %s ", path);
md5_calculate(&mf);
stlink_checksum(&mf);

/* check addr range is inside the sram */
if (addr < sl->sram_base) {
Expand Down Expand Up @@ -2698,9 +2698,9 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
return -1;
}

printf("file %s ");
md5_calculate(&mf, path);
stlink_checksum(&mf, path);
printf("file %s ", path);
md5_calculate(&mf);
stlink_checksum(&mf);

if (sl->opt) {
idx = (unsigned int) mf.len;
Expand Down Expand Up @@ -3266,9 +3266,9 @@ int stlink_fwrite_option_bytes(stlink_t *sl, const char* path, stm32_addr_t addr
return -1;
}

printf("file %s ");
md5_calculate(&mf, path);
stlink_checksum(&mf, path);
printf("file %s ", path);
md5_calculate(&mf);
stlink_checksum(&mf);

err = stlink_write_option_bytes(sl, addr, mf.base, (uint32_t) mf.len);
stlink_fwrite_finalize(sl, addr);
Expand Down

0 comments on commit 1047fdd

Please sign in to comment.