summaryrefslogtreecommitdiff
path: root/src/extras/mtd_probe
diff options
context:
space:
mode:
Diffstat (limited to 'src/extras/mtd_probe')
-rw-r--r--src/extras/mtd_probe/mtd_probe.c34
-rw-r--r--src/extras/mtd_probe/mtd_probe.h24
-rw-r--r--src/extras/mtd_probe/probe_smartmedia.c90
3 files changed, 74 insertions, 74 deletions
diff --git a/src/extras/mtd_probe/mtd_probe.c b/src/extras/mtd_probe/mtd_probe.c
index e45867ffa9..1aa08d3851 100644
--- a/src/extras/mtd_probe/mtd_probe.c
+++ b/src/extras/mtd_probe/mtd_probe.c
@@ -28,24 +28,24 @@
int main(int argc, char** argv)
{
- if (argc != 2) {
- printf("usage: mtd_probe /dev/mtd[n]\n");
- return 1;
- }
+ if (argc != 2) {
+ printf("usage: mtd_probe /dev/mtd[n]\n");
+ return 1;
+ }
- int mtd_fd = open(argv[1], O_RDONLY);
- if (mtd_fd == -1) {
- perror("open");
- exit(-1);
- }
+ int mtd_fd = open(argv[1], O_RDONLY);
+ if (mtd_fd == -1) {
+ perror("open");
+ exit(-1);
+ }
- mtd_info_t mtd_info;
- int error = ioctl(mtd_fd, MEMGETINFO, &mtd_info);
- if (error == -1) {
- perror("ioctl");
- exit(-1);
- }
+ mtd_info_t mtd_info;
+ int error = ioctl(mtd_fd, MEMGETINFO, &mtd_info);
+ if (error == -1) {
+ perror("ioctl");
+ exit(-1);
+ }
- probe_smart_media(mtd_fd, &mtd_info);
- return -1;
+ probe_smart_media(mtd_fd, &mtd_info);
+ return -1;
}
diff --git a/src/extras/mtd_probe/mtd_probe.h b/src/extras/mtd_probe/mtd_probe.h
index 20ecd4578e..2a37ede578 100644
--- a/src/extras/mtd_probe/mtd_probe.h
+++ b/src/extras/mtd_probe/mtd_probe.h
@@ -21,29 +21,29 @@
/* Full oob structure as written on the flash */
struct sm_oob {
- uint32_t reserved;
- uint8_t data_status;
- uint8_t block_status;
- uint8_t lba_copy1[2];
- uint8_t ecc2[3];
- uint8_t lba_copy2[2];
- uint8_t ecc1[3];
+ uint32_t reserved;
+ uint8_t data_status;
+ uint8_t block_status;
+ uint8_t lba_copy1[2];
+ uint8_t ecc2[3];
+ uint8_t lba_copy2[2];
+ uint8_t ecc1[3];
} __attribute__((packed));
/* one sector is always 512 bytes, but it can consist of two nand pages */
-#define SM_SECTOR_SIZE 512
+#define SM_SECTOR_SIZE 512
/* oob area is also 16 bytes, but might be from two pages */
-#define SM_OOB_SIZE 16
+#define SM_OOB_SIZE 16
/* This is maximum zone size, and all devices that have more that one zone
have this size */
-#define SM_MAX_ZONE_SIZE 1024
+#define SM_MAX_ZONE_SIZE 1024
/* support for small page nand */
-#define SM_SMALL_PAGE 256
-#define SM_SMALL_OOB_SIZE 8
+#define SM_SMALL_PAGE 256
+#define SM_SMALL_OOB_SIZE 8
void probe_smart_media(int mtd_fd, mtd_info_t *info);
diff --git a/src/extras/mtd_probe/probe_smartmedia.c b/src/extras/mtd_probe/probe_smartmedia.c
index 49704e380a..b3cdefc633 100644
--- a/src/extras/mtd_probe/probe_smartmedia.c
+++ b/src/extras/mtd_probe/probe_smartmedia.c
@@ -30,68 +30,68 @@
#include "mtd_probe.h"
static const uint8_t cis_signature[] = {
- 0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02, 0xDF, 0x01, 0x20
+ 0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02, 0xDF, 0x01, 0x20
};
void probe_smart_media(int mtd_fd, mtd_info_t* info)
{
- char* cis_buffer = malloc(SM_SECTOR_SIZE);
+ char* cis_buffer = malloc(SM_SECTOR_SIZE);
- if (!cis_buffer)
- return;
+ if (!cis_buffer)
+ return;
- if (info->type != MTD_NANDFLASH)
- goto exit;
+ if (info->type != MTD_NANDFLASH)
+ goto exit;
- int sector_size = info->writesize;
- int block_size = info->erasesize;
- int size_in_megs = info->size / (1024 * 1024);
- int spare_count;
+ int sector_size = info->writesize;
+ int block_size = info->erasesize;
+ int size_in_megs = info->size / (1024 * 1024);
+ int spare_count;
- if (sector_size != SM_SECTOR_SIZE && sector_size != SM_SMALL_PAGE)
- goto exit;
+ 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;
- }
+ switch(size_in_megs) {
+ case 1:
+ case 2:
+ spare_count = 6;
+ break;
+ case 4:
+ spare_count = 12;
+ break;
+ default:
+ spare_count = 24;
+ break;
+ }
- int offset;
- int cis_found = 0;
+ int offset;
+ int cis_found = 0;
- for (offset = 0 ; offset < block_size * spare_count ;
- offset += sector_size) {
+ 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;
- }
- }
+ 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 (!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;
+ 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);
+ printf("MTD_FTL=smartmedia\n");
+ free(cis_buffer);
+ exit(0);
exit:
- free(cis_buffer);
- return;
+ free(cis_buffer);
+ return;
}