summaryrefslogtreecommitdiff
path: root/cleopatre/application/libspid
diff options
context:
space:
mode:
authorCeline Buret2011-08-04 11:12:00 +0200
committerCeline Buret2011-08-05 16:03:00 +0200
commitacceef214051109c1854bd3ed6cfdf4644570856 (patch)
tree7c39fbb2d342d4d245d9eab0114c07748be66eb9 /cleopatre/application/libspid
parentb5a86f9c277c3600e47d0d5b01ab3357f0bde14b (diff)
cleo/{app,devkit/tests}: implement current index of vs_get_version.cnf, closes #976
Changes in libspid: * implement a new function to get the image position of the given MTD path, * update unitary tests: * test the new function, * solve a memory leak in setup() function, * remove dead code, * correctly rename the test suite as "image" instead of "system", * comment tests leading to following error that made the test not runnable: "check_pack.c:269: Error in call to write: Bad file descriptor". Changes in managerd: * call the new libspid function to fill vs_mme_get_version.cnf field returning the index of the current image, * solve 2 compilation warnings in vs_mme_get_version() function.
Diffstat (limited to 'cleopatre/application/libspid')
-rw-r--r--cleopatre/application/libspid/inc/libspid.h2
-rw-r--r--cleopatre/application/libspid/src/image.c67
2 files changed, 69 insertions, 0 deletions
diff --git a/cleopatre/application/libspid/inc/libspid.h b/cleopatre/application/libspid/inc/libspid.h
index 5e505cbe72..05ad748da8 100644
--- a/cleopatre/application/libspid/inc/libspid.h
+++ b/cleopatre/application/libspid/inc/libspid.h
@@ -142,6 +142,8 @@ extern libspid_error_t libspid_mac_bin_to_str(const unsigned char *bin, char *st
extern libspid_error_t libspid_hexstring_to_binary (const char* hex_string, unsigned char *binary, unsigned int binary_length);
extern libspid_error_t libspid_binary_to_hexstring (const unsigned char *binary, unsigned int binary_length, char *hex_string);
extern libspid_error_t libspid_image_get_desc(libspid_image_desc_type_t type, spidcom_image_desc_t *image_desc, char *mtd_name);
+extern libspid_error_t
+libspid_image_get_index (const char *mtd_path, int *index);
extern libspid_error_t libspid_image_select(libspid_image_select_t select);
extern libspid_error_t libspid_network_get_ip (const char *interface, libspid_ip_t *ip);
extern libspid_error_t libspid_network_set_ip (const char *interface, const libspid_ip_t *ip);
diff --git a/cleopatre/application/libspid/src/image.c b/cleopatre/application/libspid/src/image.c
index 2019214b7c..6a3fd9051d 100644
--- a/cleopatre/application/libspid/src/image.c
+++ b/cleopatre/application/libspid/src/image.c
@@ -18,6 +18,7 @@
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#include <libgen.h>
#ifndef __UTESTS__
#include <mtd/mtd-user.h>
#endif /* __UTESTS__ */
@@ -202,6 +203,72 @@ libspid_error_t libspid_image_get_desc(libspid_image_desc_type_t type, spidcom_i
}
/**
+ * Get index of an image from its MTD partition.
+ *
+ * \param mtd_path Full path of MTD partition
+ of the image for which index is wanted
+ * \param index index to return, set to -1 if not found
+ * \return error type (LIBSPID_SUCCESS if success)
+ * \return LIBSPID_ERROR_PARAM: bad input parameters
+ * \return LIBSPID_ERROR_NOT_FOUND: index not found
+ * \return LIBSPID_ERROR_SYSTEM: system error, see errno
+ */
+libspid_error_t
+libspid_image_get_index (const char *mtd_path, int *index)
+{
+ FILE *fp = NULL;
+ char *mtd_partition = NULL;
+ char mtd_path_tmp[32] = {0};
+ char line_buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
+ int dummy;
+
+ /* Check arguments */
+ if ((NULL == mtd_path) || (NULL == index))
+ {
+ return LIBSPID_ERROR_PARAM;
+ }
+
+ /* Copy mtd_path not to modify it */
+ memcpy (mtd_path_tmp, mtd_path, sizeof (mtd_path_tmp));
+
+ /* Initialize index as not found */
+ *index = -1;
+
+ /* From full MTD path, get the MTD partition */
+ mtd_partition = basename (mtd_path_tmp);
+
+ /* From MTD partition, find the MTD name in file "/proc/mtd" */
+ if ((fp = fopen (LIBSPID_SYSTEM_MTD_PATH, "r")) == NULL)
+ {
+ return LIBSPID_ERROR_SYSTEM;
+ }
+ while (fgets (line_buffer, LIBSPID_CONFIG_LINE_MAX_LEN - 1, fp) != NULL)
+ {
+ if (strstr (line_buffer, mtd_partition) != NULL)
+ {
+ /* Extract MTD name from line mtd<num>: <size> <erasesize> "name"
+ * We search following name : "image <index>" */
+ if (4 != sscanf (line_buffer, "mtd%d: %08x %08x \"image %d\"",
+ &dummy, &dummy, &dummy, index))
+ {
+ fclose (fp);
+ return LIBSPID_ERROR_NOT_FOUND;
+ }
+ break;
+ }
+ }
+ fclose (fp);
+
+ /* Check if index has been found */
+ if (-1 == *index)
+ {
+ return LIBSPID_ERROR_NOT_FOUND;
+ }
+
+ return LIBSPID_SUCCESS;
+}
+
+/**
* Select the current image firmware to boot on the next time.
*
* \param select the image to select for nrxt boot