1 /******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
15 #include "block_lists.h"
17 unsigned char sig_org[] = FLASHFS_PLATFORM_MAGIC;
19 /* this function is part of the crc_lib assembler code */
20 unsigned long check_flash_image(unsigned long, unsigned long, unsigned long);
22 /* this functions needs to be implemented by the board specific flash code
23 * the functions always get 32 bytes and needs to deal with the data */
24 void write_flash(unsigned long, unsigned short *);
60 printf("\nWriting Flash: |");
71 get_block_list_version(unsigned char *data)
79 get_image_size(unsigned long *data, unsigned long length)
83 for (i = 0; i < length / 8; i += 2) {
90 get_image_size_v0(unsigned long *data)
92 unsigned long bl_size = data[0];
93 return get_image_size(data + 1, bl_size - 8);
97 get_image_size_v1(unsigned long *data)
99 unsigned long *bl_addr = data;
100 unsigned long bl_size;
104 bl_size = bl_addr[0];
105 next = (unsigned long *) bl_addr[1];
106 bl_size = bl_size & 0x00FFFFFFFFFFFFFFUL;
107 size += get_image_size(bl_addr + 2, bl_size - 0x10);
114 get_size(unsigned long *data, int version)
117 return get_image_size_v1(data);
118 return get_image_size_v0(data);
122 write_one_block(unsigned long *block, unsigned long length,
123 unsigned long offset)
125 unsigned long block_addr = (unsigned long) block;
127 static unsigned int hash;
131 for (i = 0; i < length; i += 32, offset += 32, block_addr += 32) {
132 write_flash(offset, (unsigned short *) block_addr);
133 if (offset % 10 == 0) {
136 if (offset > hash * progress) {
146 write_one_list(unsigned long *bl, unsigned long length, unsigned long offset)
149 // 0x10: /8 for pointer /2 it has to be done in steps of 2
150 for (i = 0; i < length / 0x10; i++) {
152 write_one_block((unsigned long *) *bl, *(bl + 1), offset);
159 write_block_list(unsigned long *bl, int version)
161 unsigned long offset = 0;
162 unsigned long *bl_addr = bl;
163 unsigned long bl_size;
167 // -8 = removed header length
168 write_one_list(bl + 1, *(bl) - 8, offset);
173 bl_size = bl_addr[0];
174 next = (unsigned long *) bl_addr[1];
175 bl_size = bl_size & 0x00FFFFFFFFFFFFFFUL;
176 // -0x10 = removed header length
177 offset = write_one_list(bl_addr + 2, bl_size - 0x10, offset);
184 check_one_list(unsigned long *bl, unsigned long length, unsigned long crc)
187 // 0x10: /8 for pointer /2 it has to be done in steps of 2
188 for (i = 0; i < length / 0x10; i++) {
189 crc = check_flash_image((unsigned long) *bl, *(bl + 1), crc);
196 image_check_crc(unsigned long *bl, int version)
198 unsigned long *bl_addr = bl;
199 unsigned long bl_size;
201 unsigned long crc = 0;
204 // -8 = removed header length
205 return check_one_list(bl + 1, *(bl) - 8, crc);
209 bl_size = bl_addr[0];
210 next = (unsigned long *) bl_addr[1];
211 bl_size = bl_size & 0x00FFFFFFFFFFFFFFUL;
212 // -0x10 = removed header length
213 crc = check_one_list(bl_addr + 2, bl_size - 0x10, crc);
220 check_platform_one_list(unsigned long *bl, unsigned long bytesec)
222 unsigned long pos = bytesec;
223 unsigned char *sig_tmp, *sig;
224 unsigned long size = 0;
227 while (size < bytesec) {
230 while (size > pos) { // 32 == FLASHFS_PLATFORM_MAGIC length
231 sig_tmp = (unsigned char *) (bl[0] + pos);
232 if (*sig++ != *sig_tmp)
234 if (*sig_tmp == '\0' || (pos == bytesec + 32)) {
240 if (pos == (bytesec + 32))
248 check_platform(unsigned long *bl, unsigned int bytesec, int version)
250 unsigned long *bl_addr = bl;
251 unsigned long bl_size;
257 ptr += 1; // -8 = removed header length
258 return check_platform_one_list(ptr, bytesec);
261 ptr = bl_addr + 2; // -0x10 = removed header length
262 bl_size = bl_addr[0];
263 next = (unsigned long *) bl_addr[1];
264 bl_size = bl_size & 0x00FFFFFFFFFFFFFFUL;
265 if ((bl_size - 0x10) == 0) {
269 if (check_platform_one_list(ptr, bytesec) == 0)