Skip to content

Commit f0642d0

Browse files
committed
Add BCM support
1 parent f17eb6c commit f0642d0

File tree

13 files changed

+76
-12
lines changed

13 files changed

+76
-12
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ include_directories(./src/)
3838
set(COMMON_LIB_SRC
3939
src/chipid.c
4040
src/chipid.h
41+
src/hal/bcm.c
42+
src/hal/bcm.h
4143
src/hal/common.c
4244
src/hal/common.h
4345
src/hal/fh.c

src/chipid.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static long get_uart0_address() {
3535
}
3636

3737
typedef struct {
38-
const char *hardware_pattern;
38+
const char *pattern;
3939
bool (*detect_fn)(char *);
4040
const char *override_vendor;
4141
void (*setup_hal_fn)(void);
@@ -50,9 +50,10 @@ static const manufacturers_t manufacturers[] = {
5050
{"MStar", mstar_detect_cpu, NULL, sstar_setup_hal},
5151
{"Novatek", novatek_detect_cpu, NULL, novatek_setup_hal},
5252
{"Grain-Media", gm_detect_cpu, NULL, gm_setup_hal},
53-
{"FH", fh_detect_cpu, "Fullhan", setup_hal_fh},
54-
{NULL /* Generic */, rockchip_detect_cpu, "Rockchip", setup_hal_rockchip},
55-
{"Xilinx", xilinx_detect_cpu, NULL, setup_hal_xilinx},
53+
{"FH", fh_detect_cpu, "Fullhan", fh_setup_hal},
54+
{NULL /* Generic */, rockchip_detect_cpu, "Rockchip", rockchip_setup_hal},
55+
{"Xilinx", xilinx_detect_cpu, NULL, xilinx_setup_hal},
56+
{"BCM", bcm_detect_cpu, NULL, bcm_setup_hal}
5657
#endif
5758
#if defined(__aarch64__) || defined(_M_ARM64)
5859
{NULL, tegra_detect_cpu, "Nvidia", tegra_setup_hal},
@@ -72,8 +73,9 @@ static bool generic_detect_cpu() {
7273
strcpy(chip_manufacturer, buf);
7374

7475
for (size_t i = 0; i < ARRCNT(manufacturers); i++) {
75-
if (manufacturers[i].hardware_pattern &&
76-
strcmp(manufacturers[i].hardware_pattern, chip_manufacturer))
76+
if (manufacturers[i].pattern &&
77+
strncmp(manufacturers[i].pattern, chip_manufacturer,
78+
strlen(manufacturers[i].pattern)))
7779
continue;
7880

7981
if (manufacturers[i].detect_fn(chip_name)) {

src/ethernet.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "ethernet.h"
2+
23
#include "cjson/cYAML.h"
34
#include "hal/common.h"
45
#include "network.h"

src/ethernet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef ETHERNET_H
22
#define ETHERNET_H
33

4+
#include "cjson/cJSON.h"
5+
46
cJSON *detect_ethernet();
57

68
#endif /* ETHERNET_H */

src/hal/bcm.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "hal/bcm.h"
2+
3+
#include "hal/common.h"
4+
#include "tools.h"
5+
6+
#include <string.h>
7+
8+
#ifndef STANDALONE_LIBRARY
9+
#include "cjson/cJSON.h"
10+
#endif
11+
12+
bool bcm_detect_cpu(char *chip_name) {
13+
char buf[256];
14+
15+
if (!get_regex_line_from_file("/proc/cpuinfo", "Hardware.+: (BCM[0-9-]+)",
16+
buf, sizeof(buf)))
17+
return false;
18+
19+
strcpy(chip_name, buf);
20+
21+
return true;
22+
}
23+
24+
#ifndef STANDALONE_LIBRARY
25+
static void cpuinfo_param(cJSON *j_inner, char *name) {
26+
char out[256], pattern[256];
27+
28+
snprintf(pattern, sizeof(pattern), "%s.+: (.+)", name);
29+
if (!get_regex_line_from_file("/proc/cpuinfo", pattern, out, sizeof(out)))
30+
return;
31+
32+
lsnprintf(pattern, sizeof(pattern), name);
33+
ADD_PARAM(pattern, out);
34+
}
35+
36+
static void chip_properties(cJSON *j_inner) {
37+
cpuinfo_param(j_inner, "Revision");
38+
cpuinfo_param(j_inner, "Serial");
39+
cpuinfo_param(j_inner, "Model");
40+
}
41+
#endif
42+
43+
void bcm_setup_hal() {
44+
#ifndef STANDALONE_LIBRARY
45+
hal_chip_properties = chip_properties;
46+
#endif
47+
}

src/hal/bcm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef BCM_H
2+
#define BCM_H
3+
4+
#include <stdbool.h>
5+
6+
bool bcm_detect_cpu(char *chip_name);
7+
void bcm_setup_hal();
8+
9+
#endif /* BCM_H */

src/hal/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sys/ioctl.h>
88

99
#include "cjson/cJSON.h"
10+
#include "hal/bcm.h"
1011
#include "hal/fh.h"
1112
#include "hal/gm.h"
1213
#include "hal/hisi/hal_hisi.h"

src/hal/fh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ float fh_get_temp() {
130130
return ret;
131131
}
132132

133-
void setup_hal_fh() {
133+
void fh_setup_hal() {
134134
possible_i2c_addrs = fh_possible_i2c_addrs;
135135
if (!access("/sys/class/thermal/thermal_zone0/temp", R_OK))
136136
hal_temperature = fh_get_temp;

src/hal/fh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
bool fh_detect_cpu(char *chip_name);
1313
unsigned long fh_totalmem(unsigned long *media_mem);
14-
void setup_hal_fh();
14+
void fh_setup_hal();
1515

1616
#endif /* HAL_FH_H */

src/hal/rockchip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static int i2c1_open_sensor_fd() {
8585
return universal_open_sensor_fd("/dev/i2c-1");
8686
}
8787

88-
void setup_hal_rockchip() {
88+
void rockchip_setup_hal() {
8989
possible_i2c_addrs = rockchip_possible_i2c_addrs;
9090
open_i2c_sensor_fd = i2c1_open_sensor_fd;
9191
if (!access("/sys/class/thermal/thermal_zone0/temp", R_OK))

0 commit comments

Comments
 (0)