Beispiel #1
0
/*******************************************************************************
* Function    :  otp_check_wb_group
* Description :  Check OTP Space Availability
* Parameters  :  [in] index : index of otp group (0, 1, 2)
* Return      :  0, group index is empty
                 1, group index has invalid data
                 2, group index has valid data
                -1, group index error
*******************************************************************************/	
signed char otp_check_wb_group(unsigned char index)
{   
	unsigned short otp_addr = OTP_WB_GROUP_ADDR + index * OTP_WB_GROUP_SIZE;
	unsigned char  flag;

    if (index > 2)
	{
		SENSORDB("OTP input wb group index %d error\n", index);
		return -1;
	}
		
	otp_read(otp_addr, &flag);
	otp_clear();

	// Check all bytes of a group. If all bytes are '0', then the group is empty. 
	// Check from group 1 to group 2, then group 3.
	if (!flag)
	{
		SENSORDB("wb group %d is empty\n", index);
		return 0;
	}
	else if ((!(flag&0x80)) && (flag&0x7f))
	{
		SENSORDB("wb group %d has valid data\n", index);
		return 2;
	}
	else
	{
	//	SENSORDB("wb group %d has invalid data\n", index);
		return 1;
	}
}
Beispiel #2
0
int
main P2C(int, argc, string *, argv)
{
string input_name, full_input_name;
string output_name;
FILE *input_file, *output_file;

   kpse_set_progname (argv[0]);
   switch (argc) {
   case 1: fprintf(stderr, "otp2ocp: No file given\n");
         return EXIT_FAILURE;
   case 2: input_name = argv[1];
         output_name = concat(xbasename(argv[1]), ".ocp");
         break;
   case 3: input_name = argv[1];
         output_name = concat(xbasename(argv[2]), ".ocp");
         break;
   default: fprintf(stderr, "otp2ocp: Too many arguments\n");
         return EXIT_FAILURE;
   }
   full_input_name = kpse_find_file(input_name, kpse_otp_format, true);
   if (!full_input_name) {
     fprintf(stderr, "otp2ocp: %s not found\n", input_name);
     return EXIT_FAILURE;
   }
   input_file = xfopen(full_input_name, FOPEN_R_MODE);
   output_file = xfopen(output_name, FOPEN_WBIN_MODE);
   otp_read(input_file, output_file);

return EXIT_SUCCESS;
}
Beispiel #3
0
/*******************************************************************************
* Function    :  otp_read_wb_group
* Description :  Read group value and store it in OTP Struct 
* Parameters  :  [in] index : index of otp group (0, 1, 2)
* Return      :  group index (0, 1, 2)
                 -1, error
*******************************************************************************/	
signed char otp_read_wb_group(signed char index)
{
	unsigned short otp_addr;
	unsigned char  mid;

	if (index == -1)
	{
		// Check first OTP with valid data
		for (index=0; index<3; index++)
		{
			if (otp_check_wb_group(index) == 2)
			{
			//	SENSORDB("read wb from group %d", index);
				break;
			}
		}

		if (index > 2)
		{
		//	SENSORDB("no group has valid data\n");
			return -1;
		}
	}
	else
	{
		if (otp_check_wb_group(index) != 2)
		{
		//	SENSORDB("read wb from group %d failed\n", index);
			return -1;
		}
	}

	otp_addr = OTP_WB_GROUP_ADDR + index * OTP_WB_GROUP_SIZE;

	otp_read(otp_addr, &mid);
	if ((mid&0x7f) != OTP_MID)
	{
		return -1;
	}

	otp_read(otp_addr+2, &rg_ratio);
	otp_read(otp_addr+3, &bg_ratio);
	otp_clear();

	SENSORDB("read wb finished\n");
	return index;
}
Beispiel #4
0
static int otp_show(void)
{
	for (int i = 0; i < OTP_NUM_BLOCKS; i++) {
		otp_read(i);
	}

	return 0;
}
/*
 * Verify an otp by asking otpd.
 * Returns an OTP_* code, or -1 on system failure.
 * Fills in reply.
 */
static int otp_verify(rlm_otp_t const *opt,
		      otp_request_t const *request, otp_reply_t *reply)
{
	otp_fd_t *fdp;
	int rc;
	int tryagain = 2;

	retry:
	if (!tryagain--) {
		return -1;
	}

	fdp = otp_getfd(opt);
	if (!fdp || fdp->fd == -1) {
		return -1;
	}

	rc = otp_write(fdp, (char const *) request, sizeof(*request));
	if (rc != sizeof(*request)) {
		if (rc == 0) {
			goto retry;	/* otpd disconnect */	/*TODO: pause */
		} else {
			return -1;
		}
	}

	rc = otp_read(fdp, (char *) reply, sizeof(*reply));
	if (rc != sizeof(*reply)) {
		if (rc == 0) {
			goto retry;	/* otpd disconnect */	/*TODO: pause */
		} else {
			return -1;
		}
	}

	/* validate the reply */
	if (reply->version != 1) {
		AUTH("rlm_otp: otpd reply for [%s] invalid "
		       "(version %d != 1)", request->username, reply->version);

		otp_putfd(fdp, 1);
		return -1;
	}

	if (reply->passcode[OTP_MAX_PASSCODE_LEN] != '\0') {
		AUTH("rlm_otp: otpd reply for [%s] invalid "
		       "(passcode)", request->username);

		otp_putfd(fdp, 1);
		return -1;
	}

	otp_putfd(fdp, 0);
	return reply->rc;
}
Beispiel #6
0
void bfin_get_ether_addr(char *addr)
{
	/* the MAC is stored in OTP memory page 0xDF */
	u32 ret;
	u64 otp_mac;
	u32 (*otp_read)(u32 page, u32 flags, u64 *page_content) = (void *)0xEF00001A;

	ret = otp_read(0xDF, 0x00, &otp_mac);
	if (!(ret & 0x1)) {
		char *otp_mac_p = (char *)&otp_mac;
		for (ret = 0; ret < 6; ++ret)
			addr[ret] = otp_mac_p[5 - ret];
	}
}
Beispiel #7
0
u32 CHIPID_IsFused_KEY3_IdsATLAS(void)
{
	u32 ErrorCnt;
	u32 fused_data = 0;
	u8 Data[32] = {0,};
	u32 ulSize = 32;
	u32 i;

	if (otp_read((BANK_OFFSET * 3), Data, ulSize, &ErrorCnt)) {
		for (i = 0; i < 16; i = i + 2) {
			if (Data[i] != 0)
				fused_data += Data[i] * CHIPID_Power(2, i / 2);
		}
	}

	if (fused_data == 0)
		return 0;

	return fused_data;
}
Beispiel #8
0
/**
 *	bfin_otp_read - Read OTP pages
 *
 *	All reads must be in half page chunks (half page == 64 bits).
 */
static ssize_t bfin_otp_read(struct file *file, char __user *buff, size_t count, loff_t *pos)
{
	ssize_t bytes_done;
	u32 page, flags, ret;
	u64 content;

	stampit();

	if (count % sizeof(u64))
		return -EMSGSIZE;

	if (mutex_lock_interruptible(&bfin_otp_lock))
		return -ERESTARTSYS;

	bytes_done = 0;
	page = *pos / (sizeof(u64) * 2);
	while (bytes_done < count) {
		flags = (*pos % (sizeof(u64) * 2) ? OTP_UPPER_HALF : OTP_LOWER_HALF);
		stamp("processing page %i (%s)", page, (flags == OTP_UPPER_HALF ? "upper" : "lower"));
		ret = otp_read(page, flags, &content);
		if (ret & OTP_MASTER_ERROR) {
			bytes_done = -EIO;
			break;
		}
		if (copy_to_user(buff + bytes_done, &content, sizeof(content))) {
			bytes_done = -EFAULT;
			break;
		}
		if (flags == OTP_UPPER_HALF)
			++page;
		bytes_done += sizeof(content);
		*pos += sizeof(content);
	}

	mutex_unlock(&bfin_otp_lock);

	return bytes_done;
}
Beispiel #9
0
int otp_main(int argc, char *argv[])
{
	int getblocknum(int argnum) {
		if (argnum >= argc) {
			errx(1, "must specify a block number");
			return -1;

		} else {
			int bnum = -1;
			sscanf(argv[argnum], "%d", &bnum);

			if (bnum < 0 || bnum >= OTP_NUM_BLOCKS) {
				errx(1, "invalid block number");
				return -1;

			} else {
				return bnum;
			}
		}
	}

	if (argc < 2) {
		usage(NULL);

	} else {
		const char *cmd = argv[1];

		if (!strcmp(cmd, "show")) {
			return otp_show();

		} else if (!strcmp(cmd, "read") && argc == 3) {
			int bnum = getblocknum(2);

			if (bnum >= 0) {
				return otp_read(bnum);
			}

		} else if (!strcmp(cmd, "write") && argc == 5) {
			int bnum = getblocknum(2);
			uint32_t expectedcrc = strtol(argv[4], NULL, 16);

			if (bnum >= 0) {
				return otp_write(bnum, argv[3], expectedcrc);
			}

		} else if (!strcmp(cmd, "lock") && argc == 4) {
			int bnum = getblocknum(2);
			int bnum2 = getblocknum(3);

			if (bnum >= 0 && bnum == bnum2) {
				otp_lock(bnum);
				printf("LOCKED\n");
				return 0;

			} else {
				printf("FAILED\n");
				return 1;
			}

		} else {
			usage("Invalid arguments");
		}
	}

	return 0;
}