summaryrefslogtreecommitdiff
path: root/src/mtd_probe/probe_smartmedia.c
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2012-11-17 16:22:12 -0500
committerAnthony G. Basile <blueness@gentoo.org>2012-11-17 16:22:12 -0500
commit7730dfb5e1fc7e2f8b1df0eb9ef62c451a5f725f (patch)
tree1f96b7f42e8326d11be9a11f12c98ee4a30cfc70 /src/mtd_probe/probe_smartmedia.c
parentb0dd066bccc9bfabc3df290debc1d55dfb9596e5 (diff)
Restructure src/ as per lu_zero
Diffstat (limited to 'src/mtd_probe/probe_smartmedia.c')
-rw-r--r--src/mtd_probe/probe_smartmedia.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/mtd_probe/probe_smartmedia.c b/src/mtd_probe/probe_smartmedia.c
new file mode 100644
index 0000000000..feadb5076c
--- /dev/null
+++ b/src/mtd_probe/probe_smartmedia.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2010 - Maxim Levitsky
+ *
+ * mtd_probe is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mtd_probe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with mtd_probe; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <mtd/mtd-user.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include "mtd_probe.h"
+
+static const uint8_t cis_signature[] = {
+ 0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02, 0xDF, 0x01, 0x20
+};
+
+
+void probe_smart_media(int mtd_fd, mtd_info_t* info)
+{
+ int sector_size;
+ int block_size;
+ int size_in_megs;
+ int spare_count;
+ char* cis_buffer = malloc(SM_SECTOR_SIZE);
+ int offset;
+ int cis_found = 0;
+
+ if (!cis_buffer)
+ return;
+
+ if (info->type != MTD_NANDFLASH)
+ goto exit;
+
+ sector_size = info->writesize;
+ block_size = info->erasesize;
+ size_in_megs = info->size / (1024 * 1024);
+
+ if (sector_size != SM_SECTOR_SIZE && sector_size != SM_SMALL_PAGE)
+ goto exit;
+
+ switch(size_in_megs) {
+ case 1:
+ case 2:
+ spare_count = 6;
+ break;
+ case 4:
+ spare_count = 12;
+ break;
+ default:
+ spare_count = 24;
+ break;
+ }
+
+ for (offset = 0 ; offset < block_size * spare_count ;
+ offset += sector_size) {
+ lseek(mtd_fd, SEEK_SET, offset);
+ if (read(mtd_fd, cis_buffer, SM_SECTOR_SIZE) == SM_SECTOR_SIZE){
+ cis_found = 1;
+ break;
+ }
+ }
+
+ if (!cis_found)
+ goto exit;
+
+ if (memcmp(cis_buffer, cis_signature, sizeof(cis_signature)) != 0 &&
+ (memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature,
+ sizeof(cis_signature)) != 0))
+ goto exit;
+
+ printf("MTD_FTL=smartmedia\n");
+ free(cis_buffer);
+ exit(0);
+exit:
+ free(cis_buffer);
+ return;
+}