~ubuntu-branches/ubuntu/maverick/udev/maverick

« back to all changes in this revision

Viewing changes to extras/mtd_probe/probe_smartmedia.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-08-21 10:07:44 UTC
  • Revision ID: james.westby@ubuntu.com-20100821100744-otqi1fk1v4y584ux
Tags: 161+git20100820-1
* New upstream release 161, plus fixes from git head: (LP: #620977)
  - udevadm trigger now defaults to change instead of add.
  - modem modeswitch removed, use usb_modeswitch instead (see LP #521578)
  - NAME= now ignored
  - udevd creates device nodes itself on startup based on modules.udevname
  - default device permission is 0600
  - lots of bug fixes 
  - updated keymaps (LP: #271706, #554066, #569815, #592371)
  - update udev(7) to point out naming of rules files (LP: #616108)
  - cdrom_id: fix media state detection of DVD-RW/DVD+RWs (LP: #581925)
  - cdrom_id: fix media state detection on older hardware (LP: #502143)
* debian/libudev0.symbols: Add new symbols from upstream version.
* debian/udev.initramfs-hook: Drop 64-device-mapper.rules, it was removed
  upstream.
* debian/control: Drop obsolete (pre-lucid) Breaks and Conflicts.
* debian/rules: Replace obsolete dh_clean -k with dh_prep.
* debian/control: Slightly more generously version libselinux1-dev build
  dependency (thanks lintian).
* debian/control: Replace obsolete ${Source-Version} with ${binary:Version}.
* debian/control: Update Standards-Version to 3.9.1.
* debian/control: Add Homepage field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 - Maxim Levitsky
 
3
 *
 
4
 * mtd_probe is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * mtd_probe is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with mtd_probe; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 
17
 * Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <stdio.h>
 
21
#include <stdlib.h>
 
22
#include <mtd/mtd-user.h>
 
23
#include <string.h>
 
24
#include <sys/types.h>
 
25
#include <sys/stat.h>
 
26
#include <fcntl.h>
 
27
#include <unistd.h>
 
28
#include <stdint.h>
 
29
#include <stdlib.h>
 
30
#include "mtd_probe.h"
 
31
 
 
32
static const uint8_t cis_signature[] = {
 
33
        0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02, 0xDF, 0x01, 0x20
 
34
};
 
35
 
 
36
 
 
37
void probe_smart_media(int mtd_fd, mtd_info_t* info)
 
38
{
 
39
        char* cis_buffer = malloc(SM_SECTOR_SIZE);
 
40
 
 
41
        if (!cis_buffer)
 
42
                return;
 
43
 
 
44
        if (info->type != MTD_NANDFLASH)
 
45
                goto exit;
 
46
 
 
47
        int sector_size = info->writesize;
 
48
        int block_size = info->erasesize;
 
49
        int size_in_megs = info->size / (1024 * 1024);
 
50
        int spare_count;
 
51
 
 
52
 
 
53
        if (sector_size != SM_SECTOR_SIZE && sector_size != SM_SMALL_PAGE)
 
54
                goto exit;
 
55
 
 
56
        switch(size_in_megs) {
 
57
        case 1:
 
58
        case 2:
 
59
                spare_count = 6;
 
60
                break;
 
61
        case 4:
 
62
                spare_count = 12;
 
63
                break;
 
64
        default:
 
65
                spare_count = 24;
 
66
                break;
 
67
        }
 
68
 
 
69
 
 
70
        int offset;
 
71
        int cis_found = 0;
 
72
 
 
73
        for (offset = 0 ; offset < block_size * spare_count ;
 
74
                                                offset += sector_size) {
 
75
 
 
76
                lseek(mtd_fd, SEEK_SET, offset);
 
77
                if (read(mtd_fd, cis_buffer, SM_SECTOR_SIZE) == SM_SECTOR_SIZE){
 
78
                        cis_found = 1;
 
79
                        break;
 
80
                }
 
81
        }
 
82
 
 
83
        if (!cis_found)
 
84
                goto exit;
 
85
 
 
86
        if (memcmp(cis_buffer, cis_signature, sizeof(cis_signature)) != 0 &&
 
87
                (memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature,
 
88
                        sizeof(cis_signature)) != 0))
 
89
                goto exit;
 
90
 
 
91
        printf("MTD_FTL=smartmedia\n");
 
92
        free(cis_buffer);
 
93
        exit(0);
 
94
exit:
 
95
        free(cis_buffer);
 
96
        return;
 
97
}