summaryrefslogtreecommitdiff
path: root/polux/application
diff options
context:
space:
mode:
authorCyril Jourdan2012-09-12 17:59:37 +0200
committerCyril Jourdan2012-09-20 10:25:53 +0200
commit08b16c5fe86679ca8605f3e96b5a89c09876894a (patch)
tree3b6bd2c25df265e7ad588645bd4a5987c38b4271 /polux/application
parent738f028b6c6fc5b0dc8dcc86ead01871fb0db8d6 (diff)
polux/app/spidlib: make it work with only one flash image (for MSE500)
Diffstat (limited to 'polux/application')
-rw-r--r--polux/application/spidlib/src/system/image_desc.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/polux/application/spidlib/src/system/image_desc.c b/polux/application/spidlib/src/system/image_desc.c
index 742c8e9d58..14609909bc 100644
--- a/polux/application/spidlib/src/system/image_desc.c
+++ b/polux/application/spidlib/src/system/image_desc.c
@@ -31,6 +31,8 @@ spidlib_get_image_desc(spidlib_image_desc_type_t type, spidcom_image_desc_t *ima
char *mtd_name_temp[2] = { SPIDCOM_IMG_DESC_MTD_NAME_0, SPIDCOM_IMG_DESC_MTD_NAME_1 };
int found_index = -1;
+ memset (image_desc_temp, 0, sizeof (image_desc_temp));
+
if((image_desc == NULL) || (mtd_name == NULL))
{
errno = EINVAL;
@@ -42,25 +44,33 @@ spidlib_get_image_desc(spidlib_image_desc_type_t type, spidcom_image_desc_t *ima
return -errno;
}
- /* open the MTD devices for partition #0 and #1 */
- if((fd0 = open(mtd_name_temp[0], O_RDONLY)) < 0)
- return -errno;
- if((fd1 = open(mtd_name_temp[1], O_RDONLY)) < 0)
- {
- close(fd0);
- return -errno;
- }
+ /* open and read the MTD device for partition #0. */
+ if ((fd0 = open (mtd_name_temp[0], O_RDONLY)) < 0)
+ {
+ return -errno;
+ }
+ if (read (fd0, &image_desc_temp[0], sizeof (spidcom_image_desc_t)) < sizeof(spidcom_image_desc_t))
+ {
+ close (fd0);
+ return -errno;
+ }
+ close (fd0);
+
+ if ((fd1 = open (mtd_name_temp[1], O_RDONLY)) >= 0)
+ {
+ if (read (fd1, &image_desc_temp[1], sizeof (spidcom_image_desc_t)) < sizeof(spidcom_image_desc_t))
+ {
+ close (fd1);
+ return -errno;
+ }
+ close (fd1);
+ }
+#ifndef CONFIG_ARCH_MSE500
+ /* Partition #1 may not exist on MSE500 so do not return an error if open fails. */
+ else
+ return -errno;
+#endif
- /* get image descriptor infos from both MTD */
- if((read(fd0, &image_desc_temp[0], sizeof(spidcom_image_desc_t)) < sizeof(spidcom_image_desc_t))
- || (read(fd1, &image_desc_temp[1], sizeof(spidcom_image_desc_t)) < sizeof(spidcom_image_desc_t)))
- {
- close(fd0);
- close(fd1);
- return -errno;
- }
- close(fd0);
- close(fd1);
/* give asked type */
switch(type)