Skip to content

Commit

Permalink
Sigmastar: get soc from uboot environment (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorxda authored Aug 13, 2023
1 parent 29ac506 commit 7c0489d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ set(COMMON_LIB_SRC
src/hwinfo.c
src/hwinfo.h
src/mmap.h
src/mtd.c
src/sensors.c
src/sensors.h
src/tools.c
src/tools.h
src/uboot.c
src/version.h)

set(IPCTOOL_SRC
Expand Down
6 changes: 4 additions & 2 deletions src/hal/sstar.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "hal/common.h"
#include "hal/sstar.h"
#include "tools.h"
#include "uboot.h"

static unsigned char onsemi_addrs[] = {0x20, 0};
static unsigned char sony_addrs[] = {0x34, 0};
Expand Down Expand Up @@ -51,8 +52,9 @@ bool sstar_detect_cpu(char *chip_name) {
if (mem_reg(SSTAR_ADDR, &val, OP_READ)) {
chip_generation = val;

char *soc_env = getenv("SOC");
if (soc_env && *soc_env) {
cmd_getenv_initial();
const char *soc_env = uboot_env_get_param("soc");
if (soc_env) {
strcpy(chip_name, soc_env);
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/hal/sstar.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
bool mstar_detect_cpu(char *chip_name);
bool sstar_detect_cpu(char *chip_name);
void sstar_setup_hal();
void cmd_getenv_initial();

#endif /* HAL_SSTAR_H */
2 changes: 2 additions & 0 deletions src/mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ void enum_mtd_info(void *ctx, cb_mtd cb) {
}
}

#ifndef STANDALONE_LIBRARY
cJSON *get_mtd_info() {
enum_mtd_ctx ctx;
memset(&ctx, 0, sizeof(ctx));
Expand Down Expand Up @@ -472,3 +473,4 @@ int mtd_unlock_cmd() {

return EXIT_SUCCESS;
}
#endif
13 changes: 13 additions & 0 deletions src/uboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ static void uboot_setenv_cb(int mtd, uint32_t offset, const char *env,
towrite = newenv;

rewrite:
#ifndef STANDALONE_LIBRARY
if (fop == FOP_INTERACTIVE || fop == FOP_ROM) {
crc32(towrite + CRC_SZ, env_len - CRC_SZ, &res_crc);
*(uint32_t *)towrite = res_crc;
mtd_write(mtd, offset, erasesize, towrite, env_len);
}
#endif
if (uenv != towrite)
memcpy(uenv, towrite, env_len);

Expand All @@ -197,6 +199,7 @@ static void uboot_setenv_cb(int mtd, uint32_t offset, const char *env,
enum {
OP_PRINTENV = 0,
OP_SETENV,
OP_GETENV,
};

typedef struct {
Expand Down Expand Up @@ -226,6 +229,9 @@ static bool cb_uboot_env(int i, const char *name, struct mtd_info_user *mtd,
uboot_setenv_cb(i, u_off, addr + u_off, c->key, c->value,
mtd->erasesize, c->fop);
break;
case OP_GETENV:
uenv = addr + u_off;
break;
}
close(fd);
return false;
Expand All @@ -249,6 +255,13 @@ int cmd_printenv() {
return EXIT_SUCCESS;
}

void cmd_getenv_initial() {
ctx_uboot_t ctx = {
.op = OP_GETENV,
};
enum_mtd_info(&ctx, cb_uboot_env);
}

void set_env_param_ram(const char *key, const char *value) {
uboot_setenv_cb(0, 0, 0, key, value, 0, FOP_RAM);
}
Expand Down

0 comments on commit 7c0489d

Please sign in to comment.