diff options
author | zhang sanshan <sanshan.zhang@nxp.com> | 2017-05-15 10:45:07 +0800 |
---|---|---|
committer | Chen Guoyin <guoyin.chen@nxp.com> | 2017-07-10 15:08:53 +0800 |
commit | 1c79796a523255af5d012fa3cbc5400131b3b8b9 (patch) | |
tree | 671d094845bc787fca67f158f73084db3ee80f49 /lib/avb/fsl/utils.c | |
parent | 893ec7807779aa34ce49866f03e49c592fff9543 (diff) | |
download | u-boot-imx-1c79796a523255af5d012fa3cbc5400131b3b8b9.zip u-boot-imx-1c79796a523255af5d012fa3cbc5400131b3b8b9.tar.gz u-boot-imx-1c79796a523255af5d012fa3cbc5400131b3b8b9.tar.bz2 |
MA-9409-1 enable avb on android things.
Fix issue for API changed from v2017.
porting below patch from v2016.
commit 44834fd12f60a090e3d10ab6f84a75460894d49d
Change-Id: Ifaf0b86dd29648f9150646f00f54502676df9013
Signed-off-by: zhang sanshan <sanshan.zhang@nxp.com>
Diffstat (limited to 'lib/avb/fsl/utils.c')
-rw-r--r-- | lib/avb/fsl/utils.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/avb/fsl/utils.c b/lib/avb/fsl/utils.c new file mode 100644 index 0000000..ec50c70 --- /dev/null +++ b/lib/avb/fsl/utils.c @@ -0,0 +1,51 @@ + +#include <common.h> +#include <stdlib.h> + +#include "debug.h" +#include "utils.h" + +/* get margin_pos struct from offset [to the partition start/end] and num_bytes to read/write */ +int get_margin_pos(uint64_t part_start, uint64_t part_end, unsigned long blksz, + margin_pos_t *margin, int64_t offset, size_t num_bytes, bool allow_partial) { + long off; + assert(margin != NULL); + if (blksz == 0 || part_start > part_end) + return -1; + + if (offset < 0) { + margin->blk_start = (offset + 1) / blksz + part_end; + margin->start = (off = offset % blksz) == 0 ? 0 : blksz + off; // offset == -1 means the last byte?, or start need -1 + if (offset + num_bytes - 1 >= 0) { + if (!allow_partial) + return -1; + margin->blk_end = part_end; + margin->end = blksz - 1; + } else { + margin->blk_end = (num_bytes + offset) / blksz + part_end; // which blk the last byte is in + margin->end = (off = (num_bytes + offset - 1) % blksz) == 0 ? + 0 : blksz + off; // last byte + } + } else { + margin->blk_start = offset / blksz + part_start; + margin->start = offset % blksz; + margin->blk_end = (offset + num_bytes - 1) / blksz + part_start ; + margin->end = (offset + num_bytes - 1) % blksz; + if (margin->blk_end > part_end) { + if (!allow_partial) + return -1; + margin->blk_end = part_end; + margin->end = blksz - 1; + } + } + VDEBUG("bs=%ld, be=%ld, s=%ld, e=%ld\n", + margin->blk_start, margin->blk_end, margin->start, margin->end); + + if (margin->blk_start > part_end || margin->blk_start < part_start) + return -1; + long multi = margin->blk_end - margin->blk_start - 1 + + (margin->start == 0) + (margin->end == blksz -1); + margin->multi = multi > 0 ? multi : 0; + VDEBUG("bm=%ld\n", margin->multi); + return 0; +} |