/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ static void env_restore(const char *env_name) { char *env_src; env_src = env_read(env_flash_dram_base, env_name); if(!env_src) { __inf("env error: no env need be rewrite\n"); } else { strcpy(mac_addr_store, env_src); env_write(env_data_dram_base, env_src, env_name); } }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ int env_exit(void) { char env_name[48]; int env_count; int i, tmp; __inf("env exit\n"); if(env_exist == 1) { env_count = wBoot_script_parser_subkey_count("env_restore"); if(env_count <= 0) { env_restore("mac"); } else { char env_sub_name[32]; i = 0; do { tmp = i; memset(env_name, 0, 48); memset(env_sub_name, 0, 32); strcpy(env_sub_name, "env_sub00"); env_sub_name[7] = '0' + (tmp/10); tmp %= 10; env_sub_name[8] = '0' + (tmp); __inf("env_sub_name=%s\n",env_sub_name); wBoot_script_parser_fetch("env_restore", env_sub_name, (int *)env_name, 48/4); env_restore(env_name); i ++; } while(i < env_count); } } else if(env_exist == 2) { __inf("env_flash_dram_base = %s\n", env_flash_dram_base); strcpy(mac_addr_store, env_flash_dram_base); __inf("mac_addr_store = %s\n", mac_addr_store); env_write(env_data_dram_base, env_flash_dram_base, "mac"); } sprite_flash_write(env_flash_flash_start, env_data_dram_size>>9, env_data_dram_base); return 0; }
static ssize_t set_fan_speed(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int fan_nr = to_sensor_dev_attr(attr)->index; int rpm = simple_strtol(buf, NULL, 10); struct env *p = dev_get_drvdata(dev); int period; u8 val; if (!rpm) return -EINVAL; period = FAN_RPM_TO_PERIOD(rpm); val = period >> 8; env_write(p, IREG_FAN0 + fan_nr, val); return count; }
static ssize_t set_fan_speed(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int fan_nr = to_sensor_dev_attr(attr)->index; unsigned long rpm; struct env *p = dev_get_drvdata(dev); int period; u8 val; int err; err = kstrtoul(buf, 10, &rpm); if (err) return err; if (!rpm) return -EINVAL; period = FAN_RPM_TO_PERIOD(rpm); val = period >> 8; env_write(p, IREG_FAN0 + fan_nr, val); return count; }
int main(int argc, char *argv[]) { FILE *f = NULL; int count; int err = 0; int len; int idx; int i; char *name; char *value; init_private(); f = fopen(BOOTENV_MMCBLK, "rb+"); if (NULL==f) { println("can not open " BOOTENV_MMCBLK); err = -1; goto exit; } if (env_read(f)) { err = -1; goto exit; } /* * display all */ if (1==argc) { for (i=1; i<AT_ENV_COUNT; i++) { if (bootenv[i][0] && !(ENV_HIDDEN & envctl[i].flag)) { println("%s=%s", envctl[i].name, bootenv[i]); } } err = 0; goto exit; } else if (2==argc) { char *name = argv[1]; /* * help */ if (0==strcmp("-h", name) || 0==strcmp("--help", name)) { usage(argc, argv); err = 0; goto exit; } /* * get by name */ else if (NULL==strchr(name, '=')) { value = getvalue_byname(name); if (NULL==value) { println("argv[1](%s) bad name", name); err = -1; } else if (0==value[0]) { /* empty */ err = 0; } else { println("%s", value); err = 0; } goto exit; } } /* * set by name */ for (i=1; i<argc; i++) { char line[2*AT_ENV_LINE_SIZE] = {0}; len = strlen(argv[i]); /* * check input length */ if (len > (2*AT_ENV_LINE_SIZE-1)) { println("argv[%d](%s) too long", i, argv[i]); err = -1; goto exit; } strcpy(line, argv[i]); /* * get name */ name = line; value = strchr(line, '='); if (NULL==value) { println("argv[%d](%s) should as xxx=xxxx", i, argv[i]); err = -1; goto exit; } *value = 0; value++; /* * check name */ idx = getidx_byname(name); if (idx<0) { println("argv[%d](%s) bad name(%s)", i, argv[i], name); err = -1; goto exit; } /* * check value */ if (0==value[0]) { bootenv[idx][0] = 0; } else if (strlen(value) > (AT_ENV_LINE_SIZE-1)) { println("argv[%d](%s) value length max %d", i, argv[i], (AT_ENV_LINE_SIZE-1)); err = -1; goto exit; } else if (env_check(idx, value) < 0) { println("argv[%d](%s) value is invalid", i, argv[i]); err = -1; goto exit; } else if (ENV_READONLY & envctl[idx].flag) { println("argv[%d](%s) is readonly", i, argv[i]); err = -1; goto exit; } else { strcpy(bootenv[idx], value); envctl[idx].flag |= ENV_CHANGED; } } if (env_write(f)) { err = -1; goto exit; } exit: fclose(f); return err; }