Commit 24307d6337e69c277e8f70ae9af97ef331dc39c5
Committed by
Tom Rini
1 parent
ff95e579cf
Exists in
v2017.01-smarct4x
and in
25 other branches
Suspected Spam: Do not open attachements![PATCH 4/6] tools/env: flash_write_buf:…
… enforce offset to be start of environment This allows to take advantage of the environment being block aligned. This is not a new constraint. Writes always start at the begin of the environment, since the header with CRC/length as there. Every environment modification requires updating the header Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
Showing 1 changed file with 8 additions and 7 deletions Side-by-side Diff
tools/env/fw_env.c
... | ... | @@ -765,12 +765,12 @@ |
765 | 765 | } |
766 | 766 | |
767 | 767 | /* |
768 | - * Write count bytes at offset, but stay within ENVSECTORS (dev) sectors of | |
768 | + * Write count bytes from begin of environment, but stay within | |
769 | + * ENVSECTORS(dev) sectors of | |
769 | 770 | * DEVOFFSET (dev). Similar to the read case above, on NOR and dataflash we |
770 | 771 | * erase and write the whole data at once. |
771 | 772 | */ |
772 | -static int flash_write_buf (int dev, int fd, void *buf, size_t count, | |
773 | - off_t offset) | |
773 | +static int flash_write_buf(int dev, int fd, void *buf, size_t count) | |
774 | 774 | { |
775 | 775 | void *data; |
776 | 776 | struct erase_info_user erase; |
777 | 777 | |
778 | 778 | |
779 | 779 | |
... | ... | @@ -796,20 +796,21 @@ |
796 | 796 | if (DEVTYPE(dev) == MTD_ABSENT) { |
797 | 797 | blocklen = count; |
798 | 798 | erase_len = blocklen; |
799 | - blockstart = offset; | |
799 | + blockstart = DEVOFFSET(dev); | |
800 | 800 | block_seek = 0; |
801 | 801 | write_total = blocklen; |
802 | 802 | } else { |
803 | 803 | blocklen = DEVESIZE(dev); |
804 | 804 | |
805 | - erase_offset = (offset / blocklen) * blocklen; | |
805 | + erase_offset = DEVOFFSET(dev); | |
806 | 806 | |
807 | 807 | /* Maximum area we may use */ |
808 | 808 | erase_len = environment_end(dev) - erase_offset; |
809 | 809 | |
810 | 810 | blockstart = erase_offset; |
811 | + | |
811 | 812 | /* Offset inside a block */ |
812 | - block_seek = offset - erase_offset; | |
813 | + block_seek = DEVOFFSET(dev) - erase_offset; | |
813 | 814 | |
814 | 815 | /* |
815 | 816 | * Data size we actually write: from the start of the block |
... | ... | @@ -1007,7 +1008,7 @@ |
1007 | 1008 | #endif |
1008 | 1009 | |
1009 | 1010 | rc = flash_write_buf(dev_target, fd_target, environment.image, |
1010 | - CUR_ENVSIZE, DEVOFFSET(dev_target)); | |
1011 | + CUR_ENVSIZE); | |
1011 | 1012 | if (rc < 0) |
1012 | 1013 | return rc; |
1013 | 1014 |