📄 busybox-0.51-env.ppc.patch
字号:
+ diff -u busybox-0.51/Config.h.ORIG busybox-0.51/Config.h--- busybox-0.51/Config.h.ORIG Sat Jun 2 17:26:58 2001+++ busybox-0.51/Config.h Sat Jun 2 17:27:57 2001@@ -82,6 +82,7 @@ #define BB_PING //#define BB_PIVOT_ROOT //#define BB_POWEROFF+#define BB_PRINTENV //#define BB_PRINTF #define BB_PS #define BB_PWD@@ -96,6 +97,7 @@ //#define BB_ROUTE //#define BB_RPMUNPACK #define BB_SED+#define BB_SETENV //#define BB_SETKEYCODES #define BB_SH #define BB_SLEEP+ diff -u busybox-0.51/applets.h.ORIG busybox-0.51/applets.h--- busybox-0.51/applets.h.ORIG Sat Jun 2 17:26:58 2001+++ busybox-0.51/applets.h Sat Jun 2 17:31:32 2001@@ -293,6 +293,9 @@ #ifdef BB_POWEROFF APPLET(poweroff, poweroff_main, _BB_DIR_SBIN) #endif+#ifdef BB_PRINTENV+ APPLET(printenv, printenv_main, _BB_DIR_BIN)+#endif #ifdef BB_PRINTF APPLET(printf, printf_main, _BB_DIR_USR_BIN) #endif@@ -334,6 +337,9 @@ #endif #ifdef BB_SED APPLET(sed, sed_main, _BB_DIR_BIN)+#endif+#ifdef BB_SETENV+ APPLET(setenv, setenv_main, _BB_DIR_BIN) #endif #ifdef BB_SETKEYCODES APPLET(setkeycodes, setkeycodes_main, _BB_DIR_USR_BIN)+ diff -u busybox-0.51/setenv.c.ORIG busybox-0.51/setenv.c--- busybox-0.51/setenv.c.ORIG Sun Jun 3 17:02:09 2001+++ busybox-0.51/setenv.c Sun Jun 3 17:12:12 2001@@ -0,0 +1,533 @@+/*+ * (C) Copyright 2000+ * DENX Software Engineering+ * Wolfgang Denk, wd@denx.de+ * All rights reserved.+ *+ * $Date: 2001/12/13 22:31:05 $+ * $Revision: 1.2 $+ */++#include "busybox.h"+#include <errno.h>+#include <fcntl.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/types.h>+#include <unistd.h>++#include "setenv.h"++extern int errno;+unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);++#define CMD_GETENV "fw_printenv"+#define CMD_SETENV "fw_setenv"++static char *device = "/dev/flasha";++#define ENV_SIZE (CFG_ENV_SIZE - sizeof(long))++typedef struct environment_s {+ unsigned long crc; /* CRC32 over data bytes */+ char data[ENV_SIZE];+} env_t;++static env_t environment;+static int valid = 0;+++#define XMK_STR(x) #x+#define MK_STR(x) XMK_STR(x)++static char default_environment[] = {+#ifdef CONFIG_BOOTARGS+ "bootargs=" CONFIG_BOOTARGS "\0"+#endif+#ifdef CONFIG_BOOTCOMMAND+ "bootcmd=" CONFIG_BOOTCOMMAND "\0"+#endif+#if (CONFIG_BOOTDELAY >= 0)+ "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"+#endif+#if (CONFIG_BAUDRATE >= 0)+ "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"+#endif+#ifdef CONFIG_ETHADDR+ "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"+#endif+#ifdef CONFIG_IPADDR+ "ipaddr=" MK_STR(CONFIG_IPADDR) "\0"+#endif+#ifdef CONFIG_SERVERIP+ "serverip=" MK_STR(CONFIG_SERVERIP) "\0"+#endif+ "\0"+};++static int flash_io (int mode);+static char *envmatch(char *s1, char *s2);+static int env_init(void);+++/*+ * Search the environment for a variable.+ * Return the value, if found, or NULL, if not found.+ */+char *fw_getenv (char *name)+{+ char *env, *nxt;++ if (env_init())+ return (NULL);++ for (env=environment.data; *env; env=nxt+1) {+ char *val;++ for (nxt=env; *nxt; ++nxt) {+ if (nxt >= &environment.data[CFG_ENV_SIZE]) {+ fprintf (stderr, "## Error: "+ "environment not terminated\n");+ return (NULL);+ }+ }+ val=envmatch(name, env);+ if (!val)+ continue;+ return (val);+ }+ return (NULL);+}++/*+ * Print the current definition of one, or more, or all+ * environment variables+ */+int printenv_main(int argc, char *argv[])+{+ char *env, *nxt;+ int i, rc, n_flag;++ if (env_init())+ return (EXIT_FAILURE);++ rc = EXIT_SUCCESS;++ if (argc == 1) { /* Print all env variables */+ for (env=environment.data; *env; env=nxt+1) {+ for (nxt=env; *nxt; ++nxt) {+ if (nxt >= &environment.data[CFG_ENV_SIZE]) {+ fprintf (stderr, "## Error: "+ "environment not terminated\n");+ return (EXIT_FAILURE);+ }+ }+ puts (env);+ }+ return (rc);+ }++ if (strcmp(argv[1], "-n") == 0) {+ n_flag = 1;+ ++argv;+ --argc;+ if (argc != 2) {+ fprintf (stderr, "## Error: "+ "`-n' option requires exactly one argument\n");+ return (EXIT_FAILURE);+ }+ } else {+ n_flag = 0;+ }++ for (i=1; i<argc; ++i) { /* print single env variables */+ char *name = argv[i];+ char *val = NULL;++ for (env=environment.data; *env; env=nxt+1) {+ for (nxt=env; *nxt; ++nxt) {+ if (nxt >= &environment.data[CFG_ENV_SIZE]) {+ fprintf (stderr, "## Error: "+ "environment not terminated\n");+ return (EXIT_FAILURE);+ }+ }+ val=envmatch(name, env);+ if (val) {+ if (!n_flag) {+ fputs (name, stdout);+ putc ('=', stdout);+ }+ puts (val);+ break;+ }+ }+ if (!val) {+ printf ("## Error: \"%s\" not defined\n", name);+ rc = EXIT_FAILURE;+ }+ }+ return (rc);+}++/*+ * Deletes or sets environment variables.+ */+int setenv_main (int argc, char *argv[])+{+ int i, len;+ char *env, *nxt;+ char *oldval = NULL;+ char *name;++ if (argc < 2) {+ show_usage ();+ }++ if (env_init()) {+ perror (device);+ return (EXIT_FAILURE);+ }++ name = argv[1];++ /*+ * search if variable with this name already exists+ */+ for (nxt=env=environment.data; *env; env=nxt+1) {+ for (nxt=env; *nxt; ++nxt) {+ if (nxt >= &environment.data[CFG_ENV_SIZE]) {+ fprintf (stderr, "## Error: "+ "environment not terminated\n");+ return (EINVAL);+ }+ }+ if ((oldval=envmatch(name, env)) != NULL)+ break;+ }++ /*+ * Delete any existing definition+ */+ if (oldval) {+ /*+ * Ethernet Address and serial# can be set only once+ */+ if ((strcmp (name, "ethaddr") == 0) ||+ (strcmp (name, "serial#") == 0) ) {+ fprintf (stderr, "Can't overwrite \"%s\"\n", name);+ return (EXIT_FAILURE);+ }++ if (*++nxt == '\0') {+ *env = '\0';+ } else {+ for (;;) {+ *env = *nxt++;+ if ((*env == '\0') && (*nxt == '\0'))+ break;+ ++env;+ }+ }+ *++env = '\0';+ }++ /* Delete only ? */+ if (argc < 3)+ goto WRITE_FLASH;++ /*+ * Append new definition at the end+ */+ for (env=environment.data; *env || *(env+1); ++env)+ ;+ if (env > environment.data)+ ++env;+ /*+ * Overflow when:+ * "name" + "=" + "val" +"\0\0" > CFG_ENV_SIZE - (env-environment)+ */+ len = strlen(name) + 2;+ /* add '=' for first arg, ' ' for all others */+ for (i=2; i<argc; ++i) {+ len += strlen(argv[i]) + 1;+ }+ if (len > (&environment.data[CFG_ENV_SIZE]-env)) {+ fprintf (stderr,+ "Error: environment overflow, \"%s\" deleted\n",+ name);+ return (-1);+ }+ while ((*env = *name++) != '\0')+ env++;+ for (i=2; i<argc; ++i) {+ char *val = argv[i];++ *env = (i==2) ? '=' : ' ';+ while ((*++env = *val++) != '\0')+ ;+ }++ /* end is marked with double '\0' */+ *++env = '\0';++WRITE_FLASH:++ /* Update CRC */+ environment.crc = crc32(0, environment.data, ENV_SIZE);++ /* write environment back to flash */+ if (flash_io (O_WRONLY)) {+ perror (device);+ return (EXIT_FAILURE);+ }++ return (EXIT_SUCCESS);+}++static int flash_io (int mode)+{+ int fd;++ if ((fd = open(device, mode)) < 0) {+ perror(device);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -