Exemple #1
0
__s32 ali_otp_ioctl
(

    struct file   *filp,
    unsigned int   cmd,
    unsigned long  arg
)
{
    __s32                       ret;
    unsigned long               paras[MAX_ALI_OTP_PARAS];
   
    ret = 0;

    ret = copy_from_user(&paras, (void __user *)arg, _IOC_SIZE(cmd));

    if (0 != ret)
    {
        return(-EFAULT);
    }

    switch(cmd) 
    {
        case ALI_OTP_READ:
        {
            struct otp_read_paras *par = (struct otp_read_paras *)paras;        
            ALI_OTP_DEBUG("%s, %d.\n", __FUNCTION__, __LINE__);

                ret = ali_otp_read(par->offset, par->buf, par->len);
        }
        break;

        case ALI_OTP_WRITE:
        {
          	struct otp_write_paras *par = (struct otp_write_paras *)paras;
            ALI_OTP_DEBUG("%s, %d.\n", __FUNCTION__, __LINE__);

           	    ret = ali_otp_write(par->buf, par->offset, par->len);
        }
        break;
        default:
        {
            ALI_OTP_DEBUG("%s, %d.\n", __FUNCTION__, __LINE__);
            ret = -EINVAL;
        }
        break;
    }

    return(ret);
}
Exemple #2
0
static RET_CODE decrypt_key(UINT8 *in, UINT8 *out, UINT8 *key, INT32 length)
{
	UINT8 otp_key[16];
	UINT8 decrypted_key[16];
	//UINT8 temp[2][16];
	AES_KEY aes_key;
	UINT32 value;
	UINT32 i;

	//read key from otp
	for(i=0; i<4; i++)
	{
		value = ali_otp_read(0x4d+i*4);
		MEMCPY(otp_key+i*4, &value, 4);
	}

	//decrypt key
	AES_set_decrypt_key(otp_key, 128, &aes_key);
	AES_ecb_encrypt(key, decrypted_key, &aes_key, 0);

	//decrypt input
	AES_set_decrypt_key(decrypted_key, 128, &aes_key);
	while(length>0)
	{
		if(length<16)
		{
			//MEMSET(temp[0], 0, 16);
			//MEMCPY(temp[0], in, length);
			//AES_ecb_encrypt(temp[0], temp[1], &aes_key, 0);
			//MEMCPY(out, temp[1], length);
			MEMCPY(out, in, length);
		}
		else
		{
			AES_ecb_encrypt(in, out, &aes_key, 0);
		}
		in+=16;
		out+=16;
		length -= 16;
	}

	return 0;
}
Exemple #3
0
static int __init ali_otp_init
(
    void
)
{
    int            			result;
    struct device          *clsdev;
    struct ali_otp_dev     *otp;

    ALI_OTP_DEBUG("%s, %d.\n", __FUNCTION__, __LINE__);

    /* Enable CSA module in SEE by PRC. */
    //ali_m36_csa_see_init();

    otp = &g_ali_otp_device;

    mutex_init(&otp->ioctl_mutex);
    
    result = alloc_chrdev_region(&otp->dev_id, 0, 1, "ali_otp");

    if (result < 0) 
    {
        ALI_OTP_DEBUG("%s, %d\n", __FUNCTION__, __LINE__);

        goto fail;
    }

    ALI_OTP_DEBUG("%s, dev_id:%d.\n", __FUNCTION__, otp->dev_id);

    cdev_init(&(otp->cdev), &g_ali_otp_fops);

    otp->cdev.owner = THIS_MODULE;

    result = cdev_add(&otp->cdev, otp->dev_id, 1);

    /* Fail gracefully if need be. */
    if (result)
    {
        ALI_OTP_DEBUG("cdev_add() failed, result:%d\n", result);

        goto fail;
    }

    g_ali_otp_class = class_create(THIS_MODULE, "ali_otp_class");

    if (IS_ERR(g_ali_otp_class))
    {
        result = PTR_ERR(g_ali_otp_class);

        goto fail;
    }

    ALI_OTP_DEBUG("%s, %d.\n", __FUNCTION__, __LINE__);

    clsdev = device_create(g_ali_otp_class, NULL, otp->dev_id, 
                           otp, "ali_otp");

    if (IS_ERR(clsdev))
    {
        ALI_OTP_DEBUG(KERN_ERR "device_create() failed!\n");

        result = PTR_ERR(clsdev);

        goto fail;
    }

    ali_otp_hw_init();

    #ifdef CONFIG_ALI_CHIP_M3912
		ali_otp_read(0x84 * 4, (unsigned char *)(&result), 4);
		ALI_OTP_DEBUG("[ %s, %d ], Chip ID = 0x%08x, [0x84] = 0x%08x\n", 
			__FUNCTION__, __LINE__, *(unsigned int *)0xB8000000, result);		
		if ((0x00200000 != result) && (0x00200038 != result))		
		{			
			ALI_OTP_DEBUG("[ %s %d ], reboot!\n", __FUNCTION__, __LINE__);			
			kernel_restart(NULL);					
		}		
    #endif

	#ifdef CONFIG_ALI_CHIP_M3901C
		ali_otp_read(0x84 * 4, (unsigned char *)(&result), 4);
		ALI_OTP_DEBUG("[ %s, %d ], Chip ID = 0x%08x, [0x84] = 0x%08x\n", 
			__FUNCTION__, __LINE__, *(unsigned int *)0xB8000000, result);		
		
		if ((0x00300000 != result) && (0x00300038 != result))		
		{			
			ALI_OTP_DEBUG("[ %s %d ], reboot!\n", __FUNCTION__, __LINE__);			
			kernel_restart(NULL);				
		}		
    #endif
    
    ALI_OTP_DEBUG("%s, %d.\n", __FUNCTION__, __LINE__);

    return(0);

fail:
    return(-1);
}