2 * Parallel NOR Flash tests
4 * Copyright (c) 2005-2011 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
14 #if CONFIG_POST & CONFIG_SYS_POST_FLASH
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
26 #ifndef CONFIG_SYS_POST_FLASH_NUM
27 # define CONFIG_SYS_POST_FLASH_NUM 0
29 #if CONFIG_SYS_POST_FLASH_START >= CONFIG_SYS_POST_FLASH_END
30 # error "invalid flash block start/end"
33 extern flash_info_t flash_info[];
35 static void *seed_src_data(void *ptr, ulong *old_len, ulong new_len)
40 p = ptr = realloc(ptr, new_len);
44 for (i = *old_len; i < new_len; ++i)
52 int flash_post_test(int flags)
56 int ret, n, n_start, n_end;
59 /* the output from the common flash layers needs help */
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;
68 for (n = n_start; n < n_end; ++n) {
69 ulong s_start, s_len, s_off;
71 s_start = info->start[n];
72 s_len = flash_sector_size(info, n);
73 s_off = s_start - info->start[0];
75 src = seed_src_data(src, &len, s_len);
77 printf("malloc(%#lx) failed\n", s_len);
81 printf("\tsector %i: %#lx +%#lx", n, s_start, s_len);
83 ret = flash_erase(info, n, n + 1);
89 ret = write_buff(info, src, s_start, s_len);
95 ret = memcmp(src, (void *)s_start, s_len);
97 printf(" verify failed with %i\n", ret);