Exemplo n.º 1
0
static void setup_serial(void)
{
#if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE)
	const u32 cpuid_offset = 0x7;
	const u32 cpuid_length = 0x10;

	struct udevice *dev;
	int ret, i;
	u8 cpuid[cpuid_length];
	u8 low[cpuid_length/2], high[cpuid_length/2];
	char cpuid_str[cpuid_length * 2 + 1];
	u64 serialno;
	char serialno_str[17];

	/* retrieve the device */
	ret = uclass_get_device_by_driver(UCLASS_MISC,
					  DM_GET_DRIVER(rockchip_efuse), &dev);
	if (ret) {
		debug("%s: could not find efuse device\n", __func__);
		return;
	}

	/* read the cpu_id range from the efuses */
	ret = misc_read(dev, cpuid_offset, &cpuid, sizeof(cpuid));
	if (ret) {
		debug("%s: reading cpuid from the efuses failed\n",
		      __func__);
		return;
	}

	memset(cpuid_str, 0, sizeof(cpuid_str));
	for (i = 0; i < 16; i++)
		sprintf(&cpuid_str[i * 2], "%02x", cpuid[i]);

	debug("cpuid: %s\n", cpuid_str);

	/*
	 * Mix the cpuid bytes using the same rules as in
	 *   ${linux}/drivers/soc/rockchip/rockchip-cpuinfo.c
	 */
	for (i = 0; i < 8; i++) {
		low[i] = cpuid[1 + (i << 1)];
		high[i] = cpuid[i << 1];
	}

	serialno = crc32_no_comp(0, low, 8);
	serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
	snprintf(serialno_str, sizeof(serialno_str), "%016llx", serialno);

	env_set("cpuid#", cpuid_str);
	env_set("serial#", serialno_str);
#endif
}
Exemplo n.º 2
0
static int
read_block_by_offset(int fd, int blksize, uint64_t offset, char *buffer)
{

    if (lseek(fd, offset, SEEK_SET) == -1) {
        /* Seek error. */
        error_text("Error: Could not seek to %llu: %s!\n",
                   (unsigned long long) offset);
        return -1;
    }

    misc_read(fd, buffer, blksize);

    return 0;
}
void main(void) {
        int ldv_s_misc_fops_file_operations = 0;
 my_init();
        while(__VERIFIER_nondet_int()) {

                switch(__VERIFIER_nondet_int()) {

                        case 0: {
                                if(ldv_s_misc_fops_file_operations==0) {
                                misc_open();
                                ldv_s_misc_fops_file_operations++;
                                }
                        }
   break;

                        case 1: {
                                if(ldv_s_misc_fops_file_operations==1) {
                                misc_read();
                                ldv_s_misc_fops_file_operations++;
                                }
                        }
                        break;

                        case 2: {
                                if(ldv_s_misc_fops_file_operations==2) {
                                misc_llseek();
                                ldv_s_misc_fops_file_operations++;
                                }
                        }
                        break;

                        case 3: {
                                if(ldv_s_misc_fops_file_operations==3) {
                                misc_release();
                                ldv_s_misc_fops_file_operations=0;
                                }
                        }
                        break;

                        default: break;
                }
        }
        check_final_state();
 return;
}
void display_sysid(void)
{
	struct udevice *dev;
	u32 sysid[2];
	struct tm t;
	char asc[32];
	time_t stamp;
	int ret;

	/* the first misc device will be used */
	ret = uclass_first_device_err(UCLASS_MISC, &dev);
	if (ret)
		return;
	ret = misc_read(dev, 0, &sysid, sizeof(sysid));
	if (ret)
		return;

	stamp = sysid[1];
	localtime_r(&stamp, &t);
	asctime_r(&t, asc);
	printf("SYSID: %08x, %s", sysid[0], asc);
}
int fuse_sense(u32 bank, u32 word, u32 *val)
{
	struct udevice *dev;
	int ret;

	switch (bank) {
	case STM32MP_OTP_BANK:
		ret = uclass_get_device_by_driver(UCLASS_MISC,
						  DM_GET_DRIVER(stm32mp_bsec),
						  &dev);
		if (ret)
			return ret;
		ret = misc_read(dev, word * 4 + STM32_BSEC_OTP_OFFSET, val, 4);
		break;

	default:
		printf("stm32mp %s: wrong value for bank %i\n", __func__, bank);
		ret = -EINVAL;
		break;
	}

	return ret;
}
int main(void) 
{ int ldv_s_misc_fops_file_operations ;
  int tmp ;
  int tmp___0 ;

  {
  {
#line 72
  ldv_s_misc_fops_file_operations = 0;
#line 73
  my_init();
  }
  {
#line 74
  while (1) {
    while_0_continue: /* CIL Label */ ;
    {
#line 74
    tmp___0 = __VERIFIER_nondet_int();
    }
#line 74
    if (tmp___0) {

    } else {
      goto while_0_break;
    }
    {
#line 76
    tmp = __VERIFIER_nondet_int();
    }
#line 78
    if (tmp == 0) {
      goto switch_1_0;
    } else {
#line 86
      if (tmp == 1) {
        goto switch_1_1;
      } else {
#line 94
        if (tmp == 2) {
          goto switch_1_2;
        } else {
#line 102
          if (tmp == 3) {
            goto switch_1_3;
          } else {
            {
            goto switch_1_default;
#line 76
            if (0) {
              switch_1_0: /* CIL Label */ 
#line 79
              if (ldv_s_misc_fops_file_operations == 0) {
                {
#line 80
                misc_open();
#line 81
                ldv_s_misc_fops_file_operations = ldv_s_misc_fops_file_operations + 1;
                }
              } else {

              }
              goto switch_1_break;
              switch_1_1: /* CIL Label */ 
#line 87
              if (ldv_s_misc_fops_file_operations == 1) {
                {
#line 88
                misc_read();
#line 89
                ldv_s_misc_fops_file_operations = ldv_s_misc_fops_file_operations + 1;
                }
              } else {

              }
              goto switch_1_break;
              switch_1_2: /* CIL Label */ 
#line 95
              if (ldv_s_misc_fops_file_operations == 2) {
                {
#line 96
                misc_llseek();
#line 97
                ldv_s_misc_fops_file_operations = ldv_s_misc_fops_file_operations + 1;
                }
              } else {

              }
              goto switch_1_break;
              switch_1_3: /* CIL Label */ 
#line 103
              if (ldv_s_misc_fops_file_operations == 3) {
                {
#line 104
                misc_release();
#line 105
                ldv_s_misc_fops_file_operations = 0;
                }
              } else {

              }
              goto switch_1_break;
              switch_1_default: /* CIL Label */ ;
              goto switch_1_break;
            } else {
              switch_1_break: /* CIL Label */ ;
            }
            }
          }
        }
      }
    }
  }
  while_0_break: /* CIL Label */ ;
  }
  {
#line 113
  check_final_state();
  }
#line 114
  return 0;
}
}
Exemplo n.º 7
0
static int dm_test_misc(struct unit_test_state *uts)
{
	struct udevice *dev;
	u8 buf[16];
	int id;
	ulong last_ioctl;
	bool enabled;

	ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "misc-test", &dev));

	/* Read / write tests */
	ut_asserteq(4, misc_write(dev, 0, "TEST", 4));
	ut_asserteq(5, misc_write(dev, 4, "WRITE", 5));
	ut_asserteq(9, misc_read(dev, 0, buf, 9));

	ut_assertok(memcmp(buf, "TESTWRITE", 9));

	/* Call tests */

	id = 0;
	ut_assertok(misc_call(dev, 0, &id, 4, buf, 16));
	ut_assertok(memcmp(buf, "Zero", 4));

	id = 2;
	ut_assertok(misc_call(dev, 0, &id, 4, buf, 16));
	ut_assertok(memcmp(buf, "Two", 3));

	ut_assertok(misc_call(dev, 1, &id, 4, buf, 16));
	ut_assertok(memcmp(buf, "Forty-two", 9));

	id = 1;
	ut_assertok(misc_call(dev, 1, &id, 4, buf, 16));
	ut_assertok(memcmp(buf, "Forty-one", 9));

	/* IOCTL tests */

	ut_assertok(misc_ioctl(dev, 6, NULL));
	/* Read back last issued ioctl */
	ut_assertok(misc_call(dev, 2, NULL, 0, &last_ioctl,
			      sizeof(last_ioctl)));
	ut_asserteq(6, last_ioctl)

	ut_assertok(misc_ioctl(dev, 23, NULL));
	/* Read back last issued ioctl */
	ut_assertok(misc_call(dev, 2, NULL, 0, &last_ioctl,
			      sizeof(last_ioctl)));
	ut_asserteq(23, last_ioctl)

	/* Enable / disable tests */

	/* Read back enable/disable status */
	ut_assertok(misc_call(dev, 3, NULL, 0, &enabled,
			      sizeof(enabled)));
	ut_asserteq(true, enabled);

	ut_assertok(misc_set_enabled(dev, false));
	/* Read back enable/disable status */
	ut_assertok(misc_call(dev, 3, NULL, 0, &enabled,
			      sizeof(enabled)));
	ut_asserteq(false, enabled);

	ut_assertok(misc_set_enabled(dev, true));
	/* Read back enable/disable status */
	ut_assertok(misc_call(dev, 3, NULL, 0, &enabled,
			      sizeof(enabled)));
	ut_asserteq(true, enabled);

	return 0;
}