1int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
2{
3 unsigned int block, lastblock;
4 unsigned int page, page_offset;
5
6
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;
11
12 while (block <= lastblock) {
13 if (!nand_is_bad_block(block)) {
14
15 while (page < CONFIG_SYS_NAND_PAGE_COUNT) {
16 nand_read_page(block, page, dst);
17
18
19
20
21
22
23 if (unlikely(page_offset)) {
24 memmove(dst, dst + page_offset,
25 CONFIG_SYS_NAND_PAGE_SIZE);
26 dst = (void *)((int)dst - page_offset);
27 page_offset = 0;
28 }
29 dst += CONFIG_SYS_NAND_PAGE_SIZE;
30 page++;
31 }
32
33 page = 0;
34 } else {
35 lastblock++;
36 }
37
38 block++;
39 }
40
41 return 0;
42}
43
44#ifdef CONFIG_SPL_UBI
45
46
47
48
49
50
51static u8 scratch_buf[CONFIG_SYS_NAND_PAGE_SIZE];
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74int nand_spl_read_block(int block, int offset, int len, void *dst)
75{
76 int page, read;
77
78
79 page = offset / CONFIG_SYS_NAND_PAGE_SIZE;
80
81
82 offset = offset % CONFIG_SYS_NAND_PAGE_SIZE;
83
84 while (len) {
85
86
87
88
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);
93 offset = 0;
94 } else {
95 nand_read_page(block, page, dst);
96 read = CONFIG_SYS_NAND_PAGE_SIZE;
97 }
98 page++;
99 len -= read;
100 dst += read;
101 }
102 return 0;
103}
104#endif
105