static void assign_serial(void) { struct mmc *mmc = find_mmc_device(0); unsigned char ssn[16]; char usb0addr[18]; char serial[33]; int i; if (!mmc) return; md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn); snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x", ssn[13], ssn[14], ssn[15]); env_set("usb0addr", usb0addr); for (i = 0; i < 16; i++) snprintf(&serial[2 * i], 3, "%02x", ssn[i]); env_set("serial#", serial); #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) env_save(); #endif }
static int do_saveenv(int argc, const char* const* argv) { console_printf("Writing environment to flash.."); env_save(); console_printf(".DONE\n"); return 0; }
int board_late_init(void) { #if defined(CONFIG_REVISION_TAG) && \ defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) char env_str[256]; u32 rev; rev = get_board_rev(); snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev); env_set("board_rev", env_str); #ifndef CONFIG_TDX_APALIS_IMX6_V1_0 if ((rev & 0xfff0) == 0x0100) { char *fdt_env; /* reconfigure the UART to DCE mode dynamically if on V1.0 HW */ setup_iomux_dce_uart(); /* if using the default device tree, use version for V1.0 HW */ fdt_env = env_get("fdt_file"); if ((fdt_env != NULL) && (strcmp(FDT_FILE, fdt_env) == 0)) { env_set("fdt_file", FDT_FILE_V1_0); printf("patching fdt_file to " FDT_FILE_V1_0 "\n"); #ifndef CONFIG_ENV_IS_NOWHERE env_save(); #endif } } #endif /* CONFIG_TDX_APALIS_IMX6_V1_0 */ #endif /* CONFIG_REVISION_TAG */ return 0; }
int fastboot_set_reboot_flag(void) { printf("Setting reboot to fastboot flag ...\n"); env_set("dofastboot", "1"); env_save(); return 0; }
void env_reset(void) { current_env->occupied=0; current_env_end=0; current_env->data[0]=0xFF; request_default_environment(); env_save(); }
void setenv_helper(int connfd) { if(argc != 3) { socket_error_message(connfd); return; } setenv(argv[1], argv[2], TRUE); env_save(clients_get_id_from_socket(connfd)); }
static void assign_hardware_id(void) { struct ipc_ifwi_version v; char hardware_id[4]; int ret; ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4); if (ret < 0) printf("Can't retrieve hardware revision\n"); snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id); env_set("hardware_id", hardware_id); #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) env_save(); #endif }
/* ed is not valid anymore! */ return 0; } else { printk(KERN_ERR\ "%s: Cannot find a valid env!\n",\ __func__); return -1; } #ifdef DEBUGME printk(KERN_ERR\ "%s: All done, exiting!\n",\ __func__); #endif /*DEBUGME*/ return 0; } #else /*CONFIG_CIRRUS_DUAL_MTD_ENV*/ int rtcnvet_do_setenv(char *name, char *val) { int len, oldval; unsigned char *env, *nxt = NULL; unsigned char *env_data = NULL; rtcnvet_reload_env(); env_data = (unsigned char *)&env_buf[0]; if (!env_valid) return -1; if (strchr(name, '=')) { printk(KERN_ERR \ "Illegal character '=' in variable name \"%s\"\n", name); return -2; } /* * search if variable with this name already exists */ oldval = -1; for (env = env_data; *env; env = nxt+1) { for (nxt = env; *nxt; ++nxt) ; oldval = envmatch((unsigned char *)name, env-env_data); if (oldval >= 0) break; } /* * Delete any existing definition */ if (oldval >= 0) { if (*++nxt == '\0') if (env > env_data) { env--; } else { *env = '\0'; } else { for (;;) { *env = *nxt++; if ((*env == '\0') && (*nxt == '\0')) break; ++env; } } *++env = '\0'; } /* * Append new definition at the end */ for (env = env_data; *env || *(env+1); ++env) ; if (env > env_data) ++env; /* * Overflow when: * "name" + "=" + "val" +"\0\0" > ENV_SIZE - (env-env_data) */ len = strlen(name) + 2; /* add '=' for first arg, ' ' for all others */ len += strlen(val) + 1; if (len > (&env_data[env_size]-env)) { printk(KERN_ERR \ "Environment overflow, \"%s\" deleted\n", name); return 1; } while ((*env = *name++) != '\0') env++; *env = '='; while ((*++env = *val++) != '\0') ; /* end is marked with double '\0' */ *++env = '\0'; /* Update CRC */ env_crc_update(); /* save every time */ env_save(); return 0; }
int rtcnvet_do_setenv(char *name, char *val) { struct env_data ed; char *p, *q; int j, k, nxt; unsigned int crc32; int len; #ifdef DEBUGME printk(KERN_ERR\ "********* %s called! ***********\n",\ __func__); #endif /*DEBUGME*/ /*sanity*/ if (NULL == name) { printk(KERN_ERR\ "%s: Called with incorrect data!\n", __func__); return -1; } if (strchr(name, '=')) { printk(KERN_ERR\ "%s: Illegal character '=' in variable name \"%s\"\n",\ __func__, name); return -2; } /*read env*/ if (0 == env_read(&ed)) { #ifdef DEBUGME printk(KERN_ERR\ "%s: Env read, processing!\n",\ __func__); #endif /*DEBUGME*/ /* find prev. value, if any * If found, move env over it! */ k = -1; nxt = 0; p = ed.data + ENV_HEADER_SIZE; for (j = 0; *(p+j) != '\0' && j+ENV_HEADER_SIZE < ed.size; j = nxt+1) { for (nxt = j; *(p+nxt) != '\0' && nxt+ENV_HEADER_SIZE < ed.size; ++nxt); /* search name in *(p+j) ~ key=value*/ if (j+ENV_HEADER_SIZE < ed.size) { q = strstr(p+j, "="); if (NULL != q) { *q = 0; if (0 == strcmp(name, p+j)) { /* remove it! */ *q = '='; k = 1; break; } *q = '='; } } } if ( 1 == k) { #ifdef DEBUGME printk(KERN_ERR\ "%s: Prev. value found, removing...!\n",\ __func__); #endif /*DEBUGME*/ /* p+j - start of env */ /* p+nxt - start of next env - 1 */ nxt = nxt + 1; /* last thing on the env? */ if (*(p+nxt) == '\0') { *(p+j) = '\0'; } else { for (;;) { *(p+j) = *(p+nxt); nxt++; if ((*(p+j) == '\0') && (*(p+nxt) == '\0')) break; j++; } } j++; *(p+j) = '\0'; } /* set something? */ if (NULL != val) { #ifdef DEBUGME printk(KERN_ERR\ "%s: Inserting a new value!\n",\ __func__); #endif /*DEBUGME*/ for (j = 0; (*(p+j) || *(p+j+1)) && (j < ed.size - ENV_HEADER_SIZE); j++); if (j > 0 && j < ed.size - ENV_HEADER_SIZE) j++; /* j is before the last 0 */ /* check for overflow */ /* name + "=" + val + "\0\0" > ed.size - ENV_HEADER_SIZE - j */ len = strlen(name); len = len + 1; len = strlen(val); len = len + 2; if (len > ed.size - ENV_HEADER_SIZE - j) { printk(KERN_ERR \ "%s: Environment overflow, \"%s\" deleted!\n",\ __func__, name); } else { /* set it */ while ((*(p+j) = *name++) != '\0') j++; *(p+j) = '='; j++; while ((*(p+j) = *val++) != '\0') j++; /* end is marked with double '\0' */ j++; *(p+j) = '\0'; } } #ifdef DEBUGME printk(KERN_ERR\ "%s: Env changed, updating CRC!\n",\ __func__); #endif /*DEBUGME*/ /* update crc now */ crc32 = ubcrc32(0, &ed.data[ENV_HEADER_SIZE], ed.size - ENV_HEADER_SIZE); *((uint32_t *)&(ed.data[0])) = crc32; env_save(&ed); /* ed is not valid anymore! */ return 0; } else { printk(KERN_ERR\ "%s: Cannot find a valid env!\n",\ __func__); return -1; } #ifdef DEBUGME printk(KERN_ERR\ "%s: All done, exiting!\n",\ __func__); #endif /*DEBUGME*/ return 0; }