Пример #1
0
int LedSpiDevice::writeBytes(const unsigned size, const uint8_t * data)
{
	if (mFid < 0)
	{
		return -1;
	}

	spi.tx_buf = __u64(data);
	spi.len    = __u32(size);

	int retVal = ioctl(mFid, SPI_IOC_MESSAGE(1), &spi);

	if (retVal == 0 && mLatchTime_ns > 0)
	{
		// The 'latch' time for latching the shifted-value into the leds
		timespec latchTime;
		latchTime.tv_sec  = 0;
		latchTime.tv_nsec = mLatchTime_ns;

		// Sleep to latch the leds (only if write succesfull)
		nanosleep(&latchTime, NULL);
	}

	return retVal;
}
Пример #2
0
int ProviderSpi::writeBytes(const unsigned size, const uint8_t * data)
{
	if (_fid < 0)
	{
		return -1;
	}

	_spi.tx_buf = __u64(data);
	_spi.len    = __u32(size);

	if (_spiDataInvert)
	{
		uint8_t * newdata = (uint8_t *)malloc(size);
		for (unsigned i = 0; i<size; i++) {
			newdata[i] = data[i] ^ 0xff;
		}
		_spi.tx_buf = __u64(newdata);
	}

	int retVal = ioctl(_fid, SPI_IOC_MESSAGE(1), &_spi);
	ErrorIf((retVal < 0), _log, "SPI failed to write. errno: %d, %s", errno,  strerror(errno) );

	return retVal;
}
Пример #3
0
//int DMAgent::writeRebootFlash(unsigned int iMagicNum)
int DMAgent::writeRebootFlash(char *rebootCmd) {
	int fd;
	int iWriteSize = 512;
	int iRealWriteSize = 0;
	int result;
	//    int miscPartition = 0; //we can get this num from SS6, not used
	int bootEndBlock = 2048;
	char *tempBuf = NULL;
	//    miscPartition = get_partition_numb("misc");
	struct mtd_info_user info;
	struct erase_info_user erase_info;
	XLOGD("[REBOOT_FLAG]:enter write flash  the cmd is [%s]\r\n", rebootCmd);
	char devName[32];
	memset(devName, '\0', sizeof(devName));
	//sprintf(devName,"/dev/mtd/mtd%d",miscPartition);
	sprintf(devName, MISC_PATH);
	fd = open(devName, O_RDWR);
	if (fd < 0) {
		XLOGD("[REBOOT_FLAG]:mtd open error\r\n");
		return 0;
	}

	XLOGD("[REBOOT_FLAG]:before memget ioctl fd = %d\r\n", fd);

	result = ioctl(fd, MEMGETINFO, &info);
	if (result < 0) {
		XLOGE("[REBOOT_FLAG]:mtd get info error\r\n");
		close(fd);
		return 0;
	}
	iWriteSize = info.writesize;

	XLOGD("[REBOOT_FLAG]:after memget ioctl fd = %d\r\n", fd);

	XLOGI("[REBOOT_FLAG]:start to earse\r\n");
	erase_info.start = __u64(START_BLOCK);
	erase_info.length = __u64(BLOCK_SIZE);
	XLOGD("[REBOOT_FLAG]:before erase ioctl u64 convert fd = %d\r\n", fd);
	result = ioctl(fd, MEMERASE, &erase_info);
	if (result < 0) {
		XLOGE(
				"[REBOOT_FLAG]:mtd erase error result = %d errorno = [%d] err =[%s] \r\n",
				result, errno, strerror(errno));
		close(fd);
		free(tempBuf);
		return 0;
	}

	XLOGI("[REBOOT_FLAG]:end to earse\r\n");

	tempBuf = (char *) malloc(iWriteSize);

	if (tempBuf == NULL) {
		XLOGE("[REBOOT_FLAG]:malloc error\r\n");
		close(fd);
		free(tempBuf);
		return 0;
	}
	memset(tempBuf, 0, iWriteSize);
	iRealWriteSize = strlen(rebootCmd);
	memcpy(tempBuf, rebootCmd, iRealWriteSize);

	XLOGD("[REBOOT_FLAG]:start to write tempBuff = %s\r\n", tempBuf);

#ifndef MTK_EMMC_SUPPORT
	result = lseek(fd, bootEndBlock, SEEK_SET);
	if (result != (bootEndBlock)) {
		XLOGE("[REBOOT_FLAG]:mtd first lseek error\r\n");
		close(fd);
		free(tempBuf);
		return 0;
	}
#endif

	result = write(fd, tempBuf, iWriteSize);
	sync();
	if (result != iWriteSize) {
		XLOGE("[REBOOT_FLAG]:mtd write error,iWriteSize:%d\r\n", iWriteSize);
		close(fd);
		free(tempBuf);
		return 0;
	}

#ifndef MTK_EMMC_SUPPORT
	result = lseek(fd, bootEndBlock, SEEK_SET);
	if (result != (bootEndBlock)) {
		XLOGE("[REBOOT_FLAG]:mtd second lseek error\r\n");
		free(tempBuf);
		return 0;
	}
#endif

	XLOGD("[REBOOT_FLAG]:end to write iRealWriteSize = %d \r\n", iRealWriteSize);

	free(tempBuf);
	close(fd);
	return 1;
}
Пример #4
0
//int DMAgent::getUpgradeStatus()
int DMAgent::getUpgradeStatus() {
	int fd;
	int readSize = 32;
	//int miscNumber = UPGRADE_PARTITION;
	//    int miscNumber = 0;
	//    miscNumber = get_partition_numb("misc");
	int iWriteSize = 512;
	int result;
	int statusEndBlock = 2048;
	char *readBuf = NULL;

	int iRealWriteSize = 0;
	//    int miscPartition = get_partition_numb("misc"); //we can get this num from SS6

	// for test  
	char *tempBuf = NULL;

	struct mtd_info_user info;
	struct erase_info_user erase_info;
	XLOGD("[getUpgradeStatus]:enter write flash\r\n");
	char devName[32];
	memset(devName, '\0', sizeof(devName));
	//sprintf(devName,"/dev/mtd/mtd%d",miscPartition);
	sprintf(devName, MISC_PATH);
	fd = open(devName, O_RDWR);
	if (fd < 0) {
		XLOGE("[getUpgradeStatus]:mtd open error\r\n");
		return 0;
	}

	XLOGD("[getUpgradeStatus]:before memget ioctl fd = %d\r\n", fd);

	result = ioctl(fd, MEMGETINFO, &info);
	if (result < 0) {
		XLOGE("[getUpgradeStatus]:mtd get info error\r\n");
		return 0;
	}
	iWriteSize = info.writesize;

	XLOGD("[getUpgradeStatus]:after memget ioctl fd = %d\r\n", fd);

	XLOGI("[getUpgradeStatus]:start to earse\r\n");
	erase_info.start = __u64(START_BLOCK);
	erase_info.length = __u64(BLOCK_SIZE);
	XLOGD("[getUpgradeStatus]:before erase ioctl u64 convert fd = %d\r\n", fd);
	result = ioctl(fd, MEMERASE, &erase_info);
	if (result < 0) {
		XLOGE(
				"[getUpgradeStatus]:mtd erase error result = %d errorno = [%d] err =[%s] \r\n",
				result, errno, strerror(errno));
		close(fd);
		free(tempBuf);
		return 0;
	}

	XLOGI("[getUpgradeStatus]:end to earse\r\n");

	tempBuf = (char *) malloc(iWriteSize);

	if (tempBuf == NULL) {
		XLOGE("[getUpgradeStatus]:malloc error\r\n");
		close(fd);
		free(tempBuf);
		return 0;
	}
	memset(tempBuf, 0, iWriteSize);
	iRealWriteSize = sizeof("-12");
	memcpy(tempBuf, "-12", iRealWriteSize);

	XLOGI("[getUpgradeStatus]:start to write\r\n");

#ifndef MTK_EMMC_SUPPORT
	result = lseek(fd, statusEndBlock, SEEK_SET);
	if (result != (statusEndBlock)) {
		XLOGE("[getUpgradeStatus]:mtd first lseek error\r\n");
		close(fd);
		free(tempBuf);
		return 0;
	}
#endif

	result = write(fd, tempBuf, iWriteSize);
	sync();
	if (result != iWriteSize) {
		XLOGE("[getUpgradeStatus]:mtd write error,iWriteSize:%d\r\n",
				iWriteSize);
		close(fd);
		free(tempBuf);
		return 0;
	}
	memset(tempBuf, 0, iWriteSize);

#ifndef MTK_EMMC_SUPPORT
	result = lseek(fd, statusEndBlock, SEEK_SET);
	if (result != (statusEndBlock)) {
		XLOGE("[getUpgradeStatus]:mtd second lseek error\r\n");
		free(tempBuf);
		return 0;
	}
#endif

	XLOGI("[getUpgradeStatus]:end to write\r\n");
	//for test end 


	readBuf = readMiscPartition(readSize);
	if (readBuf == NULL) {
		XLOGE("[getUpgradeStatus] read Misc paartition error");
		result = 1;
	} else {
		//tranfer char * to int
		XLOGD("[getUpgradeStatus] : the readbuf is [%s]", readBuf);
		result = atoi(readBuf);
	}

	return result;

}
Пример #5
0
int GoogleOtaAgent::writeRebootFlash(char *rebootCmd)
{
    int fd;
    int iWriteSize = 512 ;
    int iRealWriteSize = 0;
    int result;

#ifdef MTK_EMMC_SUPPORT
    int bootEndBlock = 0;
    XLOGI("[REBOOT_FLAG]:MTK_EMMC_SUPPORT defined\r\n");
#else
    int bootEndBlock = 4096;///2048;
    XLOGI("[REBOOT_FLAG]:MTK_NAND_SUPPORT defined\r\n");
#endif
    char *tempBuf=NULL;

    struct mtd_info_user info;
    struct erase_info_user erase_info;
    char devName[32];
    memset(devName, '\0', sizeof(devName));

    sprintf(devName,"/dev/misc");
    fd=open(devName,O_RDWR);
    if(fd<0)
    {
        XLOGE("[REBOOT_FLAG]:mtd open error\r\n");
        return 0;
    }
#ifdef MTK_EMMC_SUPPORT
#else

    result=ioctl(fd,MEMGETINFO,&info);
    if(result<0)
    {
        XLOGE("[REBOOT_FLAG]:mtd get info error\r\n");
        return 0;
    }
    iWriteSize=info.writesize;
    bootEndBlock = iWriteSize;
    XLOGI("[REBOOT_FLAG]:bootEndBlock = %d\r\n",bootEndBlock);

    erase_info.start=__u64(START_BLOCK);
    erase_info.length = info.erasesize;
    XLOGI("[REBOOT_FLAG]:info.erasesize = %d\r\n",info.erasesize);
    result=ioctl(fd, MEMERASE, &erase_info);
    if(result<0)
    {
        XLOGE("[REBOOT_FLAG]:mtd erase error result = %d errorno = [%d] err =[%s] \r\n", result, errno, strerror(errno));
        close(fd);
        free(tempBuf);
        return 0;
    }

    XLOGI("[REBOOT_FLAG]:end to earse\r\n");

#endif

    tempBuf=(char *)malloc(iWriteSize);

    if(tempBuf==NULL)
    {
        XLOGE("[REBOOT_FLAG]:malloc error\r\n");
        close(fd);
        free(tempBuf);
        return 0;
    }
    memset(tempBuf,0,iWriteSize);

    iRealWriteSize=strlen(rebootCmd);
    memcpy(tempBuf,rebootCmd, iRealWriteSize);

    XLOGI("[REBOOT_FLAG]:start to write\r\n");

    result=lseek(fd,bootEndBlock,SEEK_SET);
    if(result!=(bootEndBlock))
    {
        XLOGE("[REBOOT_FLAG]:mtd first lseek error\r\n");
        close(fd);
        free(tempBuf);
        return 0;
    }

    result=write(fd,tempBuf,iWriteSize);
    if(result!=iWriteSize)
    {
        XLOGE("[REBOOT_FLAG]:mtd write error,iWriteSize:%d\r\n",iWriteSize);
        close(fd);
        free(tempBuf);
        return 0;
    }

    result=lseek(fd,bootEndBlock,SEEK_SET);
    if(result!=(bootEndBlock))
    {
        XLOGE("[REBOOT_FLAG]:mtd second lseek error\r\n");
        free(tempBuf);
        return 0;
    }

    XLOGI("[REBOOT_FLAG]:end to write\r\n");
    //read from misc partition to make sure it is correct
    char *readBuf = (char *)malloc(iRealWriteSize+1);
    memset(readBuf, 0, iRealWriteSize+1);
    result=read(fd,readBuf,iRealWriteSize);
    if(result!=iRealWriteSize)
    {
        XLOGE("[REBOOT_FLAG]:mtd read error\r\n");
        free(readBuf);
        close(fd);
        free(tempBuf);
        return 0;
    }

    XLOGI("[REBOOT_FLAG]:end to read  readbuf = %s\r\n",readBuf);
    XLOGI("[REBOOT_FLAG]:end to read  tempBuf = %s\r\n",tempBuf);
    if(strcmp(readBuf, tempBuf) != 0)
    {
        XLOGE("[REBOOT_FLAG]:mtd readed value error\r\n");
        close(fd);
        free(tempBuf);
        return 0;
    }
    free(tempBuf);
    free(readBuf);
    close(fd);
    return 1;
}