1 int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
3 unsigned int block, lastblock;
4 unsigned int page, page_offset;
6 /* offs has to be aligned to a page address! */
7 block = offs / CONFIG_SYS_NAND_BLOCK_SIZE;
8 lastblock = (offs + size - 1) / CONFIG_SYS_NAND_BLOCK_SIZE;
9 page = (offs % CONFIG_SYS_NAND_BLOCK_SIZE) / CONFIG_SYS_NAND_PAGE_SIZE;
10 page_offset = offs % CONFIG_SYS_NAND_PAGE_SIZE;
12 while (block <= lastblock) {
13 if (!nand_is_bad_block(block)) {
15 while (page < CONFIG_SYS_NAND_PAGE_COUNT) {
16 nand_read_page(block, page, dst);
18 * When offs is not aligned to page address the
19 * extra offset is copied to dst as well. Copy
20 * the image such that its first byte will be
23 if (unlikely(page_offset)) {
24 memmove(dst, dst + page_offset,
25 CONFIG_SYS_NAND_PAGE_SIZE);
26 dst = (void *)((int)dst - page_offset);
29 dst += CONFIG_SYS_NAND_PAGE_SIZE;
46 * Temporary storage for non NAND page aligned and non NAND page sized
47 * reads. Note: This does not support runtime detected FLASH yet, but
48 * that should be reasonably easy to fix by making the buffer large
51 static u8 scratch_buf[CONFIG_SYS_NAND_PAGE_SIZE];
54 * nand_spl_read_block - Read data from physical eraseblock into a buffer
55 * @block: Number of the physical eraseblock
56 * @offset: Data offset from the start of @peb
57 * @len: Data size to read
58 * @dst: Address of the destination buffer
60 * This could be further optimized if we'd have a subpage read
61 * function in the simple code. On NAND which allows subpage reads
62 * this would spare quite some time to readout e.g. the VID header of
66 * @offset + @len are not allowed to be larger than a physical
67 * erase block. No sanity check done for simplicity reasons.
69 * To support runtime detected flash this needs to be extended by
70 * information about the actual flash geometry, but thats beyond the
71 * scope of this effort and for most applications where fast boot is
72 * required it is not an issue anyway.
74 int nand_spl_read_block(int block, int offset, int len, void *dst)
78 /* Calculate the page number */
79 page = offset / CONFIG_SYS_NAND_PAGE_SIZE;
81 /* Offset to the start of a flash page */
82 offset = offset % CONFIG_SYS_NAND_PAGE_SIZE;
86 * Non page aligned reads go to the scratch buffer.
87 * Page aligned reads go directly to the destination.
89 if (offset || len < CONFIG_SYS_NAND_PAGE_SIZE) {
90 nand_read_page(block, page, scratch_buf);
91 read = min(len, CONFIG_SYS_NAND_PAGE_SIZE - offset);
92 memcpy(dst, scratch_buf + offset, read);
95 nand_read_page(block, page, dst);
96 read = CONFIG_SYS_NAND_PAGE_SIZE;