blob: 6e6964742e89275803b0d6e659464d9da7819037 [file] [log] [blame]
Marat Dukhan006461a2017-08-24 16:10:46 -07001#include <stdbool.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <stddef.h>
5#include <string.h>
6
Marat Dukhan3c1df682017-09-22 17:09:49 -07007#include <sys/system_properties.h>
Marat Dukhand1565252017-09-12 00:29:01 -07008
Marat Dukhan006461a2017-08-24 16:10:46 -07009#include <linux/api.h>
10#include <arm/android/api.h>
11#include <arm/linux/api.h>
Marat Dukhand0b37602018-12-09 01:59:26 -080012#include <cpuinfo/log.h>
Marat Dukhan006461a2017-08-24 16:10:46 -070013
Marat Dukhand1565252017-09-12 00:29:01 -070014#if CPUINFO_MOCK
15 #include <cpuinfo-mock.h>
Marat Dukhand1565252017-09-12 00:29:01 -070016
Marat Dukhand1565252017-09-12 00:29:01 -070017 static struct cpuinfo_mock_property* cpuinfo_mock_properties = NULL;
18
19 void CPUINFO_ABI cpuinfo_mock_android_properties(struct cpuinfo_mock_property* properties) {
20 cpuinfo_log_info("Android properties mocking enabled");
21 cpuinfo_mock_properties = properties;
22 }
23
Marat Dukhan3c1df682017-09-22 17:09:49 -070024 static int cpuinfo_android_property_get(const char* key, char* value) {
25 if (cpuinfo_mock_properties != NULL) {
26 for (const struct cpuinfo_mock_property* prop = cpuinfo_mock_properties; prop->key != NULL; prop++) {
27 if (strncmp(key, prop->key, CPUINFO_BUILD_PROP_NAME_MAX) == 0) {
28 strncpy(value, prop->value, CPUINFO_BUILD_PROP_VALUE_MAX);
29 return (int) strnlen(prop->value, CPUINFO_BUILD_PROP_VALUE_MAX);
30 }
Marat Dukhand1565252017-09-12 00:29:01 -070031 }
32 }
33 *value = '\0';
34 return 0;
35 }
Marat Dukhand1565252017-09-12 00:29:01 -070036#else
Marat Dukhan3c1df682017-09-22 17:09:49 -070037 static inline int cpuinfo_android_property_get(const char* key, char* value) {
38 return __system_property_get(key, value);
Marat Dukhand1565252017-09-12 00:29:01 -070039 }
40#endif
41
Marat Dukhan3c1df682017-09-22 17:09:49 -070042void cpuinfo_arm_android_parse_properties(struct cpuinfo_android_properties properties[restrict static 1]) {
43 const int ro_product_board_length =
44 cpuinfo_android_property_get("ro.product.board", properties->ro_product_board);
45 cpuinfo_log_debug("read ro.product.board = \"%.*s\"", ro_product_board_length, properties->ro_product_board);
Marat Dukhand1565252017-09-12 00:29:01 -070046
Marat Dukhan3c1df682017-09-22 17:09:49 -070047 const int ro_board_platform_length =
48 cpuinfo_android_property_get("ro.board.platform", properties->ro_board_platform);
49 cpuinfo_log_debug("read ro.board.platform = \"%.*s\"", ro_board_platform_length, properties->ro_board_platform);
50
51 const int ro_mediatek_platform_length =
52 cpuinfo_android_property_get("ro.mediatek.platform", properties->ro_mediatek_platform);
53 cpuinfo_log_debug("read ro.mediatek.platform = \"%.*s\"",
54 ro_mediatek_platform_length, properties->ro_mediatek_platform);
55
Marat Dukhane5d60492018-03-08 12:47:27 -080056 const int ro_arch_length =
57 cpuinfo_android_property_get("ro.arch", properties->ro_arch);
58 cpuinfo_log_debug("read ro.arch = \"%.*s\"", ro_arch_length, properties->ro_arch);
59
Marat Dukhan3c1df682017-09-22 17:09:49 -070060 const int ro_chipname_length =
61 cpuinfo_android_property_get("ro.chipname", properties->ro_chipname);
62 cpuinfo_log_debug("read ro.chipname = \"%.*s\"", ro_chipname_length, properties->ro_chipname);
Marat Dukhan006461a2017-08-24 16:10:46 -070063}