Skip to content

Commit

Permalink
ipcinfo: add info usage label (#93)
Browse files Browse the repository at this point in the history
* ipcinfo: add info usage label

* ipcinfo: add hisilicon to info usage
  • Loading branch information
viktorxda authored Sep 16, 2023
1 parent bb4308c commit 616ac07
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set(COMMON_LIB_SRC
src/hal/gm.h
src/hal/hisi/hal_hisi.c
src/hal/hisi/hal_hisi.h
src/hal/hisi/ispreg.c
src/hal/ingenic.c
src/hal/ingenic.h
src/hal/novatek.c
Expand Down
22 changes: 21 additions & 1 deletion example/ipcinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <unistd.h>

#include <ipchw.h>
#include <hal/common.h>

#include "tools.h"
#include "version.h"
Expand Down Expand Up @@ -64,6 +65,7 @@ static void print_usage() {
" -s, --short-sensor read sensor model\n"
" -F, --flash-type read flash type (nor, nand)\n"
" -t, --temp read chip temperature (where supported)\n"
" -i, --info read chip serial (where supported)\n"
" -x, --xm-mac read MAC address (for XM chips)\n"
" -S, --streamer read streamer name\n"
" -V, --version display version\n"
Expand Down Expand Up @@ -93,6 +95,20 @@ static void print_chip_temperature() {
printf("%.2f\n", temp);
}

static void print_serial() {
char serial[512];

const char *vendor = getchipvendor();
if (strstr(vendor, "HiSilicon"))
hisi_ev300_get_die_id(serial, sizeof serial);
if (strstr(vendor, "SigmaStar"))
sstar_get_die_id(serial, sizeof serial);

if (!serial)
exit(EXIT_FAILURE);
puts(serial);
}

static void print_sensor_long() {
const char *sensor = getsensoridentity();
if (!sensor)
Expand Down Expand Up @@ -188,7 +204,7 @@ static void print_xm_mac() {
}

int main(int argc, char **argv) {
const char *short_options = "cfvhlstFSxV";
const char *short_options = "cfvhlstiFSxV";
const struct option long_options[] = {
{"chip-name", no_argument, NULL, 'c'},
{"family", no_argument, NULL, 'f'},
Expand All @@ -198,6 +214,7 @@ int main(int argc, char **argv) {
{"short-sensor", no_argument, NULL, 's'},
{"flash-type", no_argument, NULL, 'F'},
{"temp", no_argument, NULL, 't'},
{"info", no_argument, NULL, 'i'},
{"streamer", no_argument, NULL, 'S'},
{"xm-mac", no_argument, NULL, 'x'},
{"version", no_argument, NULL, 'V'},
Expand Down Expand Up @@ -229,6 +246,9 @@ int main(int argc, char **argv) {
case 't':
print_chip_temperature();
break;
case 'i':
print_serial();
break;
case 'v':
print_vendor();
break;
Expand Down
12 changes: 7 additions & 5 deletions src/hal/hisi/ispreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ static void hisi_ev300_sensor_clock(cJSON *j_inner) {
}

bool hisi_ev300_get_die_id(char *buf, ssize_t len) {
if (chip_generation != HISI_V4) {
return false;
}

uint32_t base_id_addr = 0x12020400;
char *ptr = buf;
for (uint32_t id_addr = base_id_addr + 5 * 4; id_addr >= base_id_addr;
Expand Down Expand Up @@ -922,10 +926,8 @@ struct PT_OFFSET {
// PT_UNIFY_TIMING_CFG

void hisi_chip_properties(cJSON *j_inner) {
if (chip_generation == HISI_V4) {
char buf[1024];
if (hisi_ev300_get_die_id(buf, sizeof buf)) {
ADD_PARAM("id", buf);
}
char buf[1024];
if (hisi_ev300_get_die_id(buf, sizeof buf)) {
ADD_PARAM("id", buf);
}
}
2 changes: 1 addition & 1 deletion src/hal/sstar.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool sstar_detect_cpu(char *chip_name) {
return false;
}

static bool sstar_get_die_id(char *buf, ssize_t len) {
bool sstar_get_die_id(char *buf, size_t len) {
uint32_t base = 0, val = 0;

if (!chip_generation) {
Expand Down
1 change: 1 addition & 0 deletions src/hal/sstar.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
bool mstar_detect_cpu(char *chip_name);
bool sstar_detect_cpu(char *chip_name);
void sstar_setup_hal();
bool sstar_get_die_id(char *buf, size_t len);

#endif /* HAL_SSTAR_H */

0 comments on commit 616ac07

Please sign in to comment.