Commit f6f7395eb36a5d4ac7e3b088f65cda42629d1d79
Committed by
Wolfgang Denk
1 parent
d2397817f1
Exists in
master
and in
54 other branches
post: new nor flash test
This adds a simple flash test to automatically verify erasing, writing, and reading of sectors. The code is based on existing Blackfin tests but generalized for everyone to use. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Showing 4 changed files with 123 additions and 2 deletions Side-by-side Diff
include/post.h
post/drivers/Makefile
post/drivers/flash.c
1 | +/* | |
2 | + * Parallel NOR Flash tests | |
3 | + * | |
4 | + * Copyright (c) 2005-2011 Analog Devices Inc. | |
5 | + * | |
6 | + * Licensed under the GPL-2 or later. | |
7 | + */ | |
8 | + | |
9 | +#include <common.h> | |
10 | +#include <malloc.h> | |
11 | +#include <post.h> | |
12 | +#include <flash.h> | |
13 | + | |
14 | +#if CONFIG_POST & CONFIG_SYS_POST_FLASH | |
15 | + | |
16 | +/* | |
17 | + * This code will walk over the declared sectors erasing them, | |
18 | + * then programming them, then verifying the written contents. | |
19 | + * Possible future work: | |
20 | + * - verify sectors before/after are not erased/written | |
21 | + * - verify partial writes (e.g. programming only middle of sector) | |
22 | + * - verify the contents of the erased sector | |
23 | + * - better seed pattern than 0x00..0xff | |
24 | + */ | |
25 | + | |
26 | +#ifndef CONFIG_SYS_POST_FLASH_NUM | |
27 | +# define CONFIG_SYS_POST_FLASH_NUM 0 | |
28 | +#endif | |
29 | +#if CONFIG_SYS_POST_FLASH_START >= CONFIG_SYS_POST_FLASH_END | |
30 | +# error "invalid flash block start/end" | |
31 | +#endif | |
32 | + | |
33 | +extern flash_info_t flash_info[]; | |
34 | + | |
35 | +static void *seed_src_data(void *ptr, ulong *old_len, ulong new_len) | |
36 | +{ | |
37 | + unsigned char *p; | |
38 | + ulong i; | |
39 | + | |
40 | + p = ptr = realloc(ptr, new_len); | |
41 | + if (!ptr) | |
42 | + return ptr; | |
43 | + | |
44 | + for (i = *old_len; i < new_len; ++i) | |
45 | + p[i] = i; | |
46 | + | |
47 | + *old_len = new_len; | |
48 | + | |
49 | + return ptr; | |
50 | +} | |
51 | + | |
52 | +int flash_post_test(int flags) | |
53 | +{ | |
54 | + ulong len; | |
55 | + void *src; | |
56 | + int ret, n, n_start, n_end; | |
57 | + flash_info_t *info; | |
58 | + | |
59 | + /* the output from the common flash layers needs help */ | |
60 | + puts("\n"); | |
61 | + | |
62 | + len = 0; | |
63 | + src = NULL; | |
64 | + info = &flash_info[CONFIG_SYS_POST_FLASH_NUM]; | |
65 | + n_start = CONFIG_SYS_POST_FLASH_START; | |
66 | + n_end = CONFIG_SYS_POST_FLASH_END; | |
67 | + | |
68 | + for (n = n_start; n < n_end; ++n) { | |
69 | + ulong s_start, s_len, s_off; | |
70 | + | |
71 | + s_start = info->start[n]; | |
72 | + s_len = flash_sector_size(info, n); | |
73 | + s_off = s_start - info->start[0]; | |
74 | + | |
75 | + src = seed_src_data(src, &len, s_len); | |
76 | + if (!src) { | |
77 | + printf("malloc(%#lx) failed\n", s_len); | |
78 | + return 1; | |
79 | + } | |
80 | + | |
81 | + printf("\tsector %i: %#lx +%#lx", n, s_start, s_len); | |
82 | + | |
83 | + ret = flash_erase(info, n, n + 1); | |
84 | + if (ret) { | |
85 | + flash_perror(ret); | |
86 | + break; | |
87 | + } | |
88 | + | |
89 | + ret = write_buff(info, src, s_start, s_len); | |
90 | + if (ret) { | |
91 | + flash_perror(ret); | |
92 | + break; | |
93 | + } | |
94 | + | |
95 | + ret = memcmp(src, (void *)s_start, s_len); | |
96 | + if (ret) { | |
97 | + printf(" verify failed with %i\n", ret); | |
98 | + break; | |
99 | + } | |
100 | + } | |
101 | + | |
102 | + free(src); | |
103 | + | |
104 | + return ret; | |
105 | +} | |
106 | + | |
107 | +#endif |
post/tests.c
... | ... | @@ -46,6 +46,7 @@ |
46 | 46 | extern int dsp_post_test (int flags); |
47 | 47 | extern int codec_post_test (int flags); |
48 | 48 | extern int ecc_post_test (int flags); |
49 | +extern int flash_post_test(int flags); | |
49 | 50 | |
50 | 51 | extern int dspic_init_post_test (int flags); |
51 | 52 | extern int dspic_post_test (int flags); |
... | ... | @@ -301,7 +302,19 @@ |
301 | 302 | NULL, |
302 | 303 | NULL, |
303 | 304 | CONFIG_SYS_POST_COPROC |
304 | - } | |
305 | + }, | |
306 | +#endif | |
307 | +#if CONFIG_POST & CONFIG_SYS_POST_FLASH | |
308 | + { | |
309 | + "Parallel NOR flash test", | |
310 | + "flash", | |
311 | + "This test verifies parallel flash operations.", | |
312 | + POST_RAM | POST_SLOWTEST | POST_MANUAL, | |
313 | + &flash_post_test, | |
314 | + NULL, | |
315 | + NULL, | |
316 | + CONFIG_SYS_POST_FLASH | |
317 | + }, | |
305 | 318 | #endif |
306 | 319 | }; |
307 | 320 |