Skip to content

Commit 5d3393e

Browse files
cmd: bootrkp: use align address to load image
Without this change, the mmc bounce buffer would use malloc and memcpy actions to load the image on unaligned address. Let's simplify that with a final memcpy action, which indenpends on malloc pool size. Signed-off-by: Joseph Chen <[email protected]> Change-Id: I50158d93cda45d517c8ac1de0c95357973a1d40a
1 parent 8cdfda8 commit 5d3393e

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

cmd/bootrkp.c

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -168,51 +168,36 @@ static void boot_lmb_init(bootm_headers_t *images)
168168
static int read_rockchip_image(struct blk_desc *dev_desc,
169169
disk_partition_t *part, void *dst)
170170
{
171-
struct rockchip_image *img;
171+
struct rockchip_image *img = dst;
172172
int header_len = 8;
173173
int cnt, ret;
174174
#ifdef CONFIG_ROCKCHIP_CRC
175175
u32 crc32;
176176
#endif
177-
178-
img = memalign(ARCH_DMA_MINALIGN, RK_BLK_SIZE);
179-
if (!img)
180-
return -ENOMEM;
181-
182-
/* read first block with header imformation */
183177
ret = blk_dread(dev_desc, part->start, 1, img);
184-
if (ret != 1) {
185-
ret = -EIO;
186-
goto err;
187-
}
178+
if (ret != 1)
179+
return -EIO;
188180

189181
if (img->tag != TAG_KERNEL) {
190182
printf("Invalid %s image tag(0x%x)\n", part->name, img->tag);
191-
ret = -EINVAL;
192-
goto err;
183+
return -EINVAL;
193184
}
194185

195-
/*
196-
* read the rest blks
197-
* total size = image size + 8 bytes header + 4 bytes crc32
198-
*/
186+
/* total size = image size + 8 bytes header + 4 bytes crc32 */
199187
cnt = DIV_ROUND_UP(img->size + 8 + 4, RK_BLK_SIZE);
200188
if (!sysmem_alloc_base_by_name((const char *)part->name,
201189
(phys_addr_t)dst,
202-
cnt * dev_desc->blksz)) {
203-
ret = -ENXIO;
204-
goto err;
205-
}
190+
cnt * dev_desc->blksz))
191+
return -ENXIO;
206192

207-
memcpy(dst, img->image, RK_BLK_SIZE - header_len);
208-
ret = blk_dread(dev_desc, part->start + 1, cnt - 1,
209-
dst + RK_BLK_SIZE - header_len);
210-
if (ret != (cnt - 1)) {
211-
printf("Failed to read %s part, ret=%d\n", part->name, ret);
212-
ret = -EIO;
193+
ret = blk_dread(dev_desc, part->start, cnt, dst);
194+
if (ret != cnt) {
195+
printf("Failed to read %s part, blkcnt=%d\n", part->name, ret);
196+
return -EIO;
213197
} else {
214198
ret = img->size;
215199
}
200+
memcpy(dst, dst + header_len, img->size);
216201

217202
#ifdef CONFIG_ROCKCHIP_CRC
218203
printf("%s image rk crc32 verify... ", part->name);
@@ -224,9 +209,6 @@ static int read_rockchip_image(struct blk_desc *dev_desc,
224209
printf("okay.\n");
225210
}
226211
#endif
227-
228-
err:
229-
free(img);
230212
return ret;
231213
}
232214

0 commit comments

Comments
 (0)