2012-06-21 22:50:05 +08:00
|
|
|
#include "TegraDetector.h"
|
|
|
|
#include <zlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define KERNEL_CONFIG "/proc/config.gz"
|
|
|
|
#define KERNEL_CONFIG_MAX_LINE_WIDTH 512
|
|
|
|
#define KERNEL_CONFIG_TEGRA_MAGIC "CONFIG_ARCH_TEGRA=y"
|
|
|
|
#define KERNEL_CONFIG_TEGRA2_MAGIC "CONFIG_ARCH_TEGRA_2x_SOC=y"
|
|
|
|
#define KERNEL_CONFIG_TEGRA3_MAGIC "CONFIG_ARCH_TEGRA_3x_SOC=y"
|
2013-03-18 16:12:17 +08:00
|
|
|
#define KERNEL_CONFIG_TEGRA4_MAGIC "CONFIG_ARCH_TEGRA_11x_SOC=y"
|
2012-06-21 22:50:05 +08:00
|
|
|
#define MAX_DATA_LEN 4096
|
|
|
|
|
|
|
|
int DetectTegra()
|
|
|
|
{
|
|
|
|
int result = TEGRA_NOT_TEGRA;
|
|
|
|
gzFile kernelConfig = gzopen(KERNEL_CONFIG, "r");
|
|
|
|
if (kernelConfig != 0)
|
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
char tmpbuf[KERNEL_CONFIG_MAX_LINE_WIDTH];
|
|
|
|
const char *tegra_config = KERNEL_CONFIG_TEGRA_MAGIC;
|
|
|
|
const char *tegra2_config = KERNEL_CONFIG_TEGRA2_MAGIC;
|
|
|
|
const char *tegra3_config = KERNEL_CONFIG_TEGRA3_MAGIC;
|
2013-03-18 16:12:17 +08:00
|
|
|
const char *tegra4_config = KERNEL_CONFIG_TEGRA4_MAGIC;
|
2012-10-24 16:47:43 +08:00
|
|
|
int len = strlen(tegra_config);
|
|
|
|
int len2 = strlen(tegra2_config);
|
|
|
|
int len3 = strlen(tegra3_config);
|
2013-03-18 16:12:17 +08:00
|
|
|
int len4 = strlen(tegra4_config);
|
2012-10-24 16:47:43 +08:00
|
|
|
while (0 != gzgets(kernelConfig, tmpbuf, KERNEL_CONFIG_MAX_LINE_WIDTH))
|
2012-10-17 07:18:30 +08:00
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
if (0 == strncmp(tmpbuf, tegra_config, len))
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
}
|
2012-06-21 22:50:05 +08:00
|
|
|
|
2012-10-24 16:47:43 +08:00
|
|
|
if (0 == strncmp(tmpbuf, tegra2_config, len2))
|
|
|
|
{
|
|
|
|
result = 2;
|
|
|
|
break;
|
|
|
|
}
|
2012-10-02 19:02:04 +08:00
|
|
|
|
2012-10-24 16:47:43 +08:00
|
|
|
if (0 == strncmp(tmpbuf, tegra3_config, len3))
|
|
|
|
{
|
|
|
|
result = 3;
|
|
|
|
break;
|
|
|
|
}
|
2012-06-21 22:50:05 +08:00
|
|
|
|
2013-03-18 16:12:17 +08:00
|
|
|
if (0 == strncmp(tmpbuf, tegra4_config, len4))
|
|
|
|
{
|
|
|
|
result = 4;
|
|
|
|
break;
|
|
|
|
}
|
2012-10-24 16:47:43 +08:00
|
|
|
}
|
|
|
|
gzclose(kernelConfig);
|
2012-06-21 22:50:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-24 16:47:43 +08:00
|
|
|
result = TEGRA_DETECTOR_ERROR;
|
2012-06-21 22:50:05 +08:00
|
|
|
}
|
2012-10-02 19:02:04 +08:00
|
|
|
|
2012-06-21 22:50:05 +08:00
|
|
|
return result;
|
|
|
|
}
|