Esempio n. 1
0
File: main.c Progetto: eerimoq/simba
static int test_read_cid(struct harness_t *harness_p)
{
    struct sd_cid_t cid;
    static const char *mdt_month[16] = {
        "0",
        "Jan", "Feb", "Mar", "Apr",
        "May", "June", "July", "Aug",
        "Sep", "Oct", "Nov", "Dec",
        "13", "14", "15"
    };

    /* Read CID and print it to stdout. */
    BTASSERT(sd_read_cid(&sd, &cid) == sizeof(cid));

    std_printf(FSTR("cid {\r\n"
                    "    manufacturer id = 0x%02x\r\n"
                    "    application id = '%c%c'\r\n"
                    "    product name = '%c%c%c%c%c'\r\n"
                    "    product revision = %02x\r\n"
                    "    product serial number = %lu\r\n"
                    "    manufacturing date = %s %u\r\n"
                    "    crc checksum = 0x%02x\r\n"
                    "}\r\n"),
               (unsigned int)cid.mid,
               cid.oid[0], cid.oid[1],
               cid.pnm[0], cid.pnm[1], cid.pnm[2], cid.pnm[3], cid.pnm[4],
               cid.prv,
               cid.psn,
               mdt_month[ntohs(cid.mdt) & 0xf],
               2000 + ((ntohs(cid.mdt) >> 4) & 0xff),
               cid.crc);

    return (0);
}
Esempio n. 2
0
static int sd_welcome_card(struct sd_host *host)
{
	int retval;

	/* soft reset the card */
	retval = sd_reset_sequence(host);
	if (retval < 0 || sd_card_is_bad(host))
		goto out;

	/* read Operating Conditions Register */
	retval = sd_read_ocr(host);
	if (retval < 0)
		goto err_bad_card;

	/* refuse to drive cards reporting voltage ranges out of scope */
	if (!(host->ocr & host->ocr_avail)) {
		sd_printk(KERN_WARNING, "reported OCR (%08x)"
			  " indicates that it is not safe to use this"
			  " card with a GameCube\n", host->ocr);
		retval = -ENODEV;
		goto err_bad_card;
	}

	/* read and decode the Card Specific Data */
	retval = sd_read_csd(host);
	if (retval < 0)
		goto err_bad_card;
	mmc_decode_csd(&host->card);

	/* calculate some card access related timeouts */
	sd_calc_timeouts(host);

	/* read and decode the Card Identification Data */
	retval = sd_read_cid(host);
	if (retval < 0)
		goto err_bad_card;
	mmc_decode_cid(&host->card);

	sd_printk(KERN_INFO, "slot%d: descr \"%s\", size %luk, block %ub,"
		  " serial %08x\n",
		  to_channel(exi_get_exi_channel(host->exi_device)),
		  host->card.cid.prod_name,
		  (unsigned long)((host->card.csd.capacity *
			  (1 << host->card.csd.read_blkbits)) / 1024),
		  1 << host->card.csd.read_blkbits,
		  host->card.cid.serial);

	retval = 0;
	goto out;

err_bad_card:
	sd_card_set_bad(host);
out:
	return retval;
}
Esempio n. 3
0
/**
 * def read_cid(self)
 */
static mp_obj_t class_sd_read_cid(mp_obj_t self_in)
{
    struct class_sd_t *self_p;
    struct sd_cid_t cid;
    mp_obj_t tuple[7];

    self_p = MP_OBJ_TO_PTR(self_in);

    if (sd_read_cid(&self_p->drv, &cid) != sizeof(cid)) {
        nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
                                           "sd_read_cid() failed"));
    }

    tuple[0] = MP_OBJ_NEW_SMALL_INT(cid.mid);
    tuple[1] = mp_obj_new_bytes((const byte *)cid.oid, sizeof(cid.oid));
    tuple[2] = mp_obj_new_bytes((const byte *)cid.pnm, sizeof(cid.pnm));
    tuple[3] = MP_OBJ_NEW_SMALL_INT(cid.prv);
    tuple[4] = mp_obj_new_int(cid.psn);
    tuple[5] = mp_obj_new_int(cid.mdt);
    tuple[6] = MP_OBJ_NEW_SMALL_INT(cid.crc);

    return (mp_obj_new_attrtuple(&cid_fields[0], 7, tuple));
}
/*
 * Checks if media changed.
 */
static int sd_media_changed(struct gendisk *disk)
{
	struct sd_host *host = disk->private_data;
	unsigned int last_serial;
	int retval;

	/* report a media change for zombies */
	if (!host)
		return 1;

	/* report a media change if someone forced it */
	if (test_bit(__SD_MEDIA_CHANGED, &host->flags))
		return 1;

	/* check if the serial number of the card changed */
	last_serial = host->card.cid.serial;
	retval = sd_read_cid(host);
	if (!retval && last_serial == host->card.cid.serial && last_serial)
		clear_bit(__SD_MEDIA_CHANGED, &host->flags);
	else
		set_bit(__SD_MEDIA_CHANGED, &host->flags);

	return (host->flags & SD_MEDIA_CHANGED) ? 1 : 0;
}