Exemplo n.º 1
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		cpu_full_name_set
 * @BRIEF		set CPU full name (name + rev + type)
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_INTERNAL
 * @param[in]		none
 * @DESCRIPTION		set CPU full name (name + rev + type)
 *//*------------------------------------------------------------------------ */
static int cpu_full_name_set(void)
{
	char name[CPU_NAME_MAX_LENGTH];
	char rev[CPU_REVISION_MAX_NAME_LENGTH];
	char type[CPU_DEVICE_TYPE_MAX_NAME_LENGTH];

	strncpy(cpu_full_name, "", sizeof(cpu_full_name));

	cpu_gets(name);
	if (name == NULL) {
		fprintf(stderr, "%s(): name == NULL!\n", __func__);
		return OMAPCONF_ERR_INTERNAL;
	}
	cpu_revision_gets(rev);
	if (rev == NULL) {
		fprintf(stderr, "%s(): rev == NULL!\n", __func__);
		return OMAPCONF_ERR_INTERNAL;
	}
	cpu_device_type_gets(type);
	if (type == NULL) {
		fprintf(stderr, "%s(): type == NULL!\n", __func__);
		return OMAPCONF_ERR_INTERNAL;
	}

	if (cpu_is_forced() == 1)
		strcat(cpu_full_name, "FORCED ");
	strcat(cpu_full_name, name);
	strcat(cpu_full_name, " ES");
	strcat(cpu_full_name, rev);
	strcat(cpu_full_name, " (");
	strcat(cpu_full_name, type);
	strcat(cpu_full_name, ")");

	dprintf("%s(): cpu_full_name=%s\n", __func__, cpu_full_name);
	return 0;
}
Exemplo n.º 2
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		main
 * @BRIEF		main entry point
 * @RETURNS		0 on success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_REG_ACCESS
 * @param[in, out]	argc: shell input argument number
 * @param[in, out]	argv: shell input argument(s)
 * @DESCRIPTION		main entry point
 *//*------------------------------------------------------------------------ */
int main(int argc, char *argv[])
{
	int ret;
	struct sigaction act;
	unsigned int start, end, time, delay;
	double sampling_rate;
	char *prefix;
	char *cfgfile;
	int c;

	cpu_found = 0;
	ret = 0;

	/* Register signal handler in order to catch incorrect memory access. */
	act.sa_sigaction = &main_sigbus_handler;
	act.sa_flags = SA_SIGINFO;
	sigaction(SIGBUS, &act, NULL);

	/* Some of the omapconf functions do not support DEVICE OFF Mode,
	 * so by default acquire a wakelock if OS is Android.
	 */
	if (os_is_android())
		wakelock_acquire();

	/* To be case-insensitive, lowercase all arguments */
	main_arguments_lowercase(argc, argv);

	/* Scan user arguments for options */
	argc--;
	argv++;
	ret = main_options_scan(&argc, &argv);
	if (ret < 0)
		goto main_exit;

	if (!cpu_is_forced()) {
		/* Detect CPU if not user-enforced */
		ret = cpu_detect();
		switch (ret) {
		case 0:
			cpu_found = 1;
			break;

		case OMAPCONF_ERR_REG_ACCESS:
			omapconf_revision_show(stdout);
			printf("'/dev/mem' could not be opened.\n");
			printf(
				"Privileged access required to run omapconf.\n\n");
			ret = OMAPCONF_ERR_REG_ACCESS;
			goto main_exit;

		case OMAPCONF_ERR_CPU:
			printf(
				"Warning: chip not recognized, running in safe mode (only platform-generic functions allowed).\n\n");
			break;

		case OMAPCONF_ERR_UNEXPECTED:
		default:
			omapconf_revision_show(stdout);
			printf("Unexpected error, sorry ... (%d)\n\n", ret);
			ret = OMAPCONF_ERR_UNEXPECTED;
			goto main_exit;
		}

	}

	if (argc == 0) {
		help(HELP_USAGE);
		ret = OMAPCONF_ERR_ARG;
		goto main_exit;
	}

	/* Platform-generic functions, no need to detect cpu */
	if (strcmp(argv[0], "--help") == 0) {
		omapconf_revision_show(stdout);
		help(HELP_ALL);
		ret = 0;
		goto main_exit;
	} else if (strcmp(argv[0], "--version") == 0) {
		omapconf_revision_show(stdout);
		ret = 0;
		goto main_exit;
	} else if (strcmp(argv[0], "--cpuinfo") == 0) {
		omapconf_revision_show(stdout);
		chips_info_show(stdout, 1);
		ret = 0;
		goto main_exit;
	} else if (strcmp(argv[0], "--buildinfo") == 0) {
		omapconf_revision_show(stdout);
		release_info_show(stdout);
		ret = 0;
		goto main_exit;
	} else if (strcmp(argv[0], "read") == 0) {
		if ((argc >= 2) &&
			(strcmp(argv[1], "audioic") == 0)) {
			goto main_platform_specific;
		} else if ((argc >= 2) &&
			(strcmp(argv[1], "i2c") == 0)) {
			if (argc < 5) {
				ret = err_arg_missing_msg_show(HELP_I2C_RW);
				goto main_exit;
			} else if (argc == 5) {
				ret = main_i2c_read(argc, argv);
				goto main_exit;
			} else {
				ret = err_arg_too_many_msg_show(HELP_I2C_RW);
				goto main_exit;
			}
		}

		if (argc == 2) {
			ret = main_readreg(uppercase(argv[1]), "hex");
			goto main_exit;
		} else if (argc == 3) {
			ret = main_readreg(uppercase(argv[1]),
				lowercase(argv[2]));
			goto main_exit;
		} else {
			ret = err_arg_too_many_msg_show(HELP_RW);
			goto main_exit;
		}
	} else if (strcmp(argv[0], "write") == 0) {
		if ((argc >= 2) &&
			(strcmp(argv[1], "audioic") == 0)) {
			goto main_platform_specific;
		} else if ((argc >= 2) &&
			(strcmp(argv[1], "i2c") == 0)) {
			if (argc < 6) {
				ret = err_arg_missing_msg_show(HELP_I2C_RW);
				goto main_exit;
			} else if (argc == 6) {
				ret = main_i2c_write(argc, argv);
				goto main_exit;
			} else {
				ret = err_arg_too_many_msg_show(HELP_I2C_RW);
				goto main_exit;
			}
		}

		if (argc < 3) {
			ret = err_arg_missing_msg_show(HELP_RW);
			goto main_exit;
		} else if (argc == 3) {
			ret = main_writereg(uppercase(argv[1]),
				uppercase(argv[2]));
			goto main_exit;
		} else {
			ret = err_arg_too_many_msg_show(HELP_RW);
			goto main_exit;
		}
	} else if (strcmp(argv[0], "clear") == 0) {
		if ((argc >= 2) && (strcmp(argv[1], "bit") == 0)) {
			ret = main_clearbit(argc, argv);
			goto main_exit;
		}
	} else if (strcmp(argv[0], "set") == 0) {
		if ((argc >= 2) && (strcmp(argv[1], "bit") == 0)) {
			ret = main_setbit(argc, argv);
			goto main_exit;
		}
	} else if (strcmp(argv[0], "i2c") == 0) {
		if ((argc != 5) && (argc != 6)) {
			help(HELP_I2C_RW);
			ret = OMAPCONF_ERR_ARG;
			goto main_exit;
		}
		if (strcmp(argv[1], "read") == 0) {
			ret = main_i2c_read(argc, argv);
			goto main_exit;
		} else if (strcmp(argv[1], "write") == 0) {
			ret = main_i2c_write(argc, argv);
			goto main_exit;
		} else {
			ret = err_arg_msg_show(HELP_I2C_RW);
			goto main_exit;
		}
	} else if ((strcmp(argv[0], "dump") == 0)
		&& (argc == 3)
		&& (sscanf(argv[1], "0x%08x", &start) == 1)
		&& (sscanf(argv[2], "0x%08x", &end) == 1)) {
		ret = mem_address_range_dump(start, end);
		goto main_exit;
	} else if ((argc >= 3) &&
		(strcmp(argv[0], "trace") == 0) &&
		(strcmp(argv[1], "perf") == 0) &&
		(strcmp(argv[2], "setup") == 0)) {
		if (argc == 3)
			ret = trace_perf_setup(
				(char *) trace_perf_default_cfgfile);
		else
			ret = trace_perf_setup(argv[3]);
		goto main_exit;
	} else if ((argc >= 2) &&
		(strcmp(argv[0], "trace") == 0) &&
		(strcmp(argv[1], "perf") == 0)) {
		time = TRACE_PERF_DEFAULT_CAPTURE_TIME;
		delay = TRACE_PERF_DEFAULT_DELAY_TIME;
		sampling_rate = TRACE_PERF_DEFAULT_SAMPLING_RATE;
		prefix = NULL;
		cfgfile = (char *) trace_perf_default_cfgfile;

		omapconf_revision_show(stdout);
		chips_info_show(stdout, 0);
		release_info_show(stdout);

		if (argc == 2) {
			time = TRACE_PERF_DEFAULT_CAPTURE_TIME;
			delay = TRACE_PERF_DEFAULT_DELAY_TIME;
			sampling_rate = TRACE_PERF_DEFAULT_SAMPLING_RATE;
			prefix = NULL;
			cfgfile = (char *) trace_perf_default_cfgfile;
		} else if (argc == 3) {
			ret = sscanf(argv[2], "%u", &time);
			if (ret != 1) {
				help(HELP_TRACE);
				ret = OMAPCONF_ERR_ARG;
				goto main_exit;
			}
		} else {
			while ((c = getopt(argc, argv, "d:t:s:p:c:")) != -1) {
				switch (c) {
				case 'd': /* delay time */
					ret = sscanf(optarg, "%u", &delay);
					if (ret != 1) {
						ret = err_arg_msg_show(
							HELP_TRACE);
						goto main_exit;
					}
					break;
				case 't': /* capture time */
					ret = sscanf(optarg, "%u", &time);
					if (ret != 1) {
						ret = err_arg_msg_show(
							HELP_TRACE);
						goto main_exit;
					}
					break;
				case 's': /* sampling rate */
					ret = sscanf(optarg, "%lf",
						&sampling_rate);
					if (ret != 1) {
						ret = err_arg_msg_show(
							HELP_TRACE);
						goto main_exit;
					}
					break;
				case 'p': /* file prefix */
					prefix = optarg;
					break;
				case 'c': /* configuration file */
					cfgfile = optarg;
					break;
				default:
					ret = err_arg_msg_show(HELP_TRACE);
					goto main_exit;
				}
			}
		}
		if (cpu_is_omap44xx())
			main44xx_init();
		else if (cpu_is_omap54xx())
			dpll54xx_init();
		ret = trace_perf_capture(cfgfile, prefix,
				sampling_rate, time, delay);
		goto main_exit;
	}


	/* Platform-specific functions */
main_platform_specific:
	if (cpu_found) {
		omapconf_revision_show(stdout);
		chips_info_show(stdout, 0);
		release_info_show(stdout);
		if (cpu_is_omap44xx()) {
			ret = main44xx(argc, argv);
			goto main_exit;
		} else if (cpu_is_omap54xx()) {
			ret = main54xx(argc, argv);
			goto main_exit;
		} else if (cpu_is_dra7xx()) {
			ret = main_dra7xx(argc, argv);
			goto main_exit;
		} else {
			printf("Unsupported chip, sorry ...\n\n");
			ret = OMAPCONF_ERR_CPU;
			goto main_exit;
		}
	} else {
		printf("Function disabled in safe mode, sorry ...\n\n");
		ret = OMAPCONF_ERR_NOT_AVAILABLE;
		goto main_exit;
	}

main_exit:
	if (os_is_android())
		wakelock_release();

	/* Unmap last mapped memory page */
	mem_unmap();

	/* Deinitializations */
	if (cpu_get() != OMAP_MAX) {
		opp_deinit();
		voltdm_deinit();
		temp_sensor_deinit();
		module_deinit();
		powerdm_deinit();
		clockdm_deinit();
	}

	return ret;
}