📄 busybox-0.51-flash.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:28 2001+++ busybox-0.51/Config.h Sat Jun 2 17:26:58 2001@@ -37,6 +37,8 @@ //#define BB_FBSET //#define BB_FDFLUSH //#define BB_FIND+#define BB_FLASH_ERASE+#define BB_FLASH_INFO #define BB_FREE //#define BB_FREERAMDISK //#define BB_FSCK_MINIX+ diff -u busybox-0.51/applets.h.ORIG busybox-0.51/applets.h--- busybox-0.51/applets.h.ORIG Wed Apr 4 19:31:15 2001+++ busybox-0.51/applets.h Sat Jun 2 17:26:58 2001@@ -149,6 +149,12 @@ #ifdef BB_FIND APPLET(find, find_main, _BB_DIR_USR_BIN) #endif+#ifdef BB_FLASH_ERASE+ APPLET(flash_erase, flash_erase_main, _BB_DIR_BIN)+#endif+#ifdef BB_FLASH_INFO+ APPLET(flash_info, flash_info_main, _BB_DIR_BIN)+#endif #ifdef BB_FREE APPLET(free, free_main, _BB_DIR_USR_BIN) #endif+ diff -u busybox-0.51/flash_erase.c.ORIG busybox-0.51/flash_erase.c--- busybox-0.51/flash_erase.c.ORIG Sat Jun 2 17:26:58 2001+++ busybox-0.51/flash_erase.c Sat Jun 2 17:26:58 2001@@ -0,0 +1,253 @@+/*+ * (C) Copyright 2000+ * DENX Software Engineering+ * Wolfgang Denk, wd@denx.de+ * All rights reserved.+ *+ * $Date: 2002/02/04 09:32:25 $+ * $Revision: 1.2 $+ */++#include "busybox.h"+#include <errno.h>+#include <fcntl.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <unistd.h>+#include <sys/ioctl.h>+#include <sys/stat.h>+#include <sys/types.h>+#include "flash.h"+#include <linux/fs.h>++int get_number (const char *, unsigned long *);++static const char *cmdname;++extern int flash_erase_main (int argc, char **argv)+{+ int i, fd, part;+ struct stat stb;+ flash_info_t info;+ flash_region_info_t *region;+ flash_partition_t *partition;+ erase_info_t erase;+ unsigned long offset, size, p_offset, p_size;++ cmdname = *argv;++ if ((argc != 2) && (argc != 4)) {+ show_usage ();+ }++ if ((fd = open (argv[1], O_RDWR)) < 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ if (fstat(fd, &stb) < 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ part = MINOR(stb.st_rdev) & FLASH_PART_MASK;++ if (ioctl (fd, FLASHGETINFO, &info) < 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ size = info.num_regions * sizeof (flash_region_info_t);++ if ((region = malloc (size)) == NULL) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ if (ioctl (fd, FLASHGETREGIONINFO, region) < 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ if (part) { /* read partition info */+ if ((partition = malloc(sizeof(flash_partition_t)*info.num_parts))+ == NULL) {+ perror ("malloc");+ return (EXIT_FAILURE);+ }++ if (ioctl (fd, FLASHGETPARTINFO, partition) < 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }+ p_offset = partition[part-1].start;+ p_size = partition[part-1].size;+ } else {+ p_offset = 0;+ p_size = 0;+ }+++ if (argc == 2) {+ if (part) {+ /*+ * erase whole partition+ */+ printf ("Erasing Partition %d (%ld kB at offset 0x%lx)\n",+ part, p_size >> 10, p_offset);+ erase.offset = 0;+ erase.size = p_size;+ if (ioctl (fd, FLASHERASE, &erase) < 0) {+ perror ("Erase failed");+ return (EXIT_FAILURE);+ }+ } else {+ /*+ * erase whole device+ */+ offset = 0;+ for (i = 0; i < info.num_regions; i++) {+ int reg_size = region[i].num_sectors * region[i].sector_size;++ erase.offset = offset;+ erase.size = reg_size;+ printf ("Erasing %2d sectors (%3d kB, total %4d kB)"+ " at offset 0x%lx\n",+ region[i].num_sectors,+ region[i].sector_size >> 10,+ reg_size >> 10,+ offset+ );+ if (ioctl (fd, FLASHERASE, &erase) < 0) {+ perror ("Erase sector failed");+ return (EXIT_FAILURE);+ }+ offset += reg_size;+ }+ }+ close (fd);+ return (EXIT_SUCCESS);+ }++ /*+ * Erase part of the device+ */+ if (get_number (argv[2], &offset) < 0) {+ fprintf (stderr, "%s: bad offset: %s\n", cmdname, argv[2]);+ show_usage ();+ }+ if (get_number (argv[3], &size) < 0) {+ fprintf (stderr, "%s: bad size: %s\n", cmdname, argv[3]);+ show_usage ();+ }++ /*+ * The Flash driver with partition support interprets+ * erase.offset relative to the current partition.+ *+ * "offset" is relative to the start of the current partition,+ * while "p_offset" relative to the start of the whole device.+ */++ p_size -= p_offset; /* remaining length of partititon */+ p_offset += offset; /* offset relative to device */++ for (i = 0; i < info.num_regions; i++) {+ unsigned long reg_size = region[i].num_sectors+ * region[i].sector_size;+ unsigned long reg_end = region[i].offset + reg_size;++ if ((reg_end <= p_offset) || /* region below erase area */+ (region[i].offset > p_offset + size)) { /* region above erase area */+ continue;+ }+ /* region contains at least part of erase area */+ if (p_offset % region[i].sector_size) {+ fprintf (stderr, "%s: offset 0x%lx not on sector boundary "+ "(region %u: sector size=0x%x=%dkB)\n",+ cmdname, offset, i,+ region[i].sector_size, region[i].sector_size >> 10);++ return (EXIT_FAILURE);+ }+ erase.offset = offset;+ erase.size = reg_end - p_offset;+ if (erase.size > size) {+ erase.size = size;+ }+ if (p_size && erase.size > p_size) {+ erase.size = p_size; /* don't delete beyond partition */+ }++ printf ("Erasing %4ld kB = %2ld sectors (%3d kB) at offset 0x%lx",+ erase.size >> 10, erase.size / region[i].sector_size,+ region[i].sector_size >> 10, offset);+ if (part) {+ printf (" in partition %d", part);+ }+ printf ("\n");+ if (ioctl (fd, FLASHERASE, &erase) < 0) {+ fprintf (stderr, "%s: Erase sector failed on %s: %s\n",+ cmdname, argv[1], strerror (errno));+ return (EXIT_FAILURE);+ }+ p_offset += erase.size;+ offset += erase.size;+ size -= erase.size;+ if (!size) {+ break;+ }+ }++ if (size) {+ printf ("Warning: %ld kB not erased (size bigger than %s)\n",+ size, part ? "partition" : "device");+ }++ close (fd);++ return (EXIT_SUCCESS);+}++int get_number (const char *s, unsigned long *val)+{+ unsigned long ret;+ unsigned char c = 0;++ if (*s == '0') { /* hex or octal number */+ ++s;+ /* just 0 ? */+ if (*s == '\0') {+ *val = 0;+ return (0);+ }+ /* is it hex? */+ if ((sscanf (s, "x%lx%c", &ret, &c) <= 0) &&+ (sscanf (s, "X%lx%c", &ret, &c) <= 0)) {+ /* not hex, maybe oct ? */+ if (sscanf (s, "%lo%c", &ret, &c) <= 0) {+ return (-1);+ }+ }+ } else {+ /* must be dec then */+ if (sscanf (s, "%ld%c", &ret, &c) <= 0) {+ return (-1);+ }+ }++ switch (c) {+ case 'k':+ case 'K':+ ret <<= 10; /* kB */+ break;+ case 'm':+ case 'M':+ ret <<= 20; /* MB */+ break;+ }++ *val = ret;+ return (0);+}+ diff -u busybox-0.51/flash_info.c.ORIG busybox-0.51/flash_info.c--- busybox-0.51/flash_info.c.ORIG Sat Jun 2 17:26:58 2001+++ busybox-0.51/flash_info.c Sat Jun 2 17:26:58 2001@@ -0,0 +1,112 @@+/*+ * (C) Copyright 2000+ * DENX Software Engineering+ * Wolfgang Denk, wd@denx.de+ * All rights reserved.+ * + * $Date: 2002/02/04 09:32:25 $+ * $Revision: 1.2 $+ */++#include "busybox.h"+#include <errno.h>+#include <fcntl.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <unistd.h>+#include <sys/ioctl.h>+#include <sys/stat.h>+#include <sys/types.h>+#include "flash.h"+++extern int flash_info_main (int argc, char **argv)+{+ int i, fd, part;+ struct stat stb;+ flash_info_t info;+ flash_region_info_t *region;+ flash_partition_t *partition;++ if (argc != 2) {+ show_usage ();+ }++ if ((fd = open(argv[1], O_RDONLY)) < 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ if (fstat(fd, &stb) < 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ part = stb.st_rdev & FLASH_PART_MASK;++ if (ioctl (fd, FLASHGETINFO, &info) != 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ printf ("Information for %s", argv[1]);+ if (part) {+ printf (" = Partition %d on this device", part);+ }+ printf (":\n\nSize: %2d MB, Configuration: %dx%d bit,"+ " %d Regions, %d Partitions\n\n",+ info.size >> 20, info.chip_config, info.bitwidth,+ info.num_regions, info.num_parts);++ if ((region = malloc (sizeof (flash_region_info_t) * info.num_regions))+ == NULL) {+ perror ("malloc");+ return (EXIT_FAILURE);+ }++ if (ioctl (fd, FLASHGETREGIONINFO, region) != 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ for (i = 0; i < info.num_regions; i++) {+ printf ("Region %d: Offset: 0x%08lx"+ " Size: %5d kB in %3d Sectors of %4d kB each\n",+ i,+ region[i].offset,+ region[i].num_sectors * region[i].sector_size >> 10,+ region[i].num_sectors,+ region[i].sector_size >> 10+ );+ }++ if (!part) {+ (void)close (fd);+ return (EXIT_SUCCESS);+ }++ if ((partition = malloc (sizeof (flash_partition_t) * info.num_parts))+ == NULL) {+ perror ("malloc");+ return (EXIT_FAILURE);+ }++ if (ioctl (fd, FLASHGETPARTINFO, partition) != 0) {+ perror (argv[1]);+ return (EXIT_FAILURE);+ }++ printf ("\n");++ for (i = 0; i < info.num_parts; i++) {+ printf ("Partition %d: Offset: 0x%08lx Size: %5d kB\n",+ i+1,+ partition[i].start,+ partition[i].size >> 10+ );+ }++ (void)close (fd);+ return (EXIT_SUCCESS);+}+ diff -u busybox-0.51/usage.h.ORIG busybox-0.51/usage.h--- busybox-0.51/usage.h.ORIG Tue Apr 10 01:26:31 2001+++ busybox-0.51/usage.h Sat Jun 2 17:26:58 2001@@ -449,6 +449,23 @@ "$ find / -name /etc/passwd\n" \ "/etc/passwd\n" +#define flash_info_trivial_usage \+ " flash_device\n"+#define flash_info_full_usage \+ "Print information for a Flash Memory Device\n"+#define flash_info_example_usage \+ "$ flash_info /dev/flasha1\n"++#define flash_erase_trivial_usage \+ " flash_device [OFFSET LENGTH]\n"+#define flash_erase_full_usage \+ "Erase a Flash Memory Device or some part of it.\n" \+ "offset, length: hex (0xNN), dec (NN) or oct (0NN) numbers,\n" \+ " plus optional 'k' or 'm' suffix" \+ " (for kB or MB, resp.)\n"+#define flash_erase_example_usage \+ "$ flash_erase /dev/flasha 3M 512k\n"+ #define free_trivial_usage \ "" #define free_full_usage \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -