diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-05-25 04:15:37 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-05-25 04:15:37 +0200 |
| commit | bf2af9acb28ed6d8bbe351d669daaa140d0239f0 (patch) | |
| tree | 3adba401caf5c25406f89ebe053a0d9dbb043b54 /miscutils | |
| parent | 4f26c97b9a2fdf6d967eafa06c67d04e432840a1 (diff) | |
| download | busybox-w32-bf2af9acb28ed6d8bbe351d669daaa140d0239f0.tar.gz busybox-w32-bf2af9acb28ed6d8bbe351d669daaa140d0239f0.tar.bz2 busybox-w32-bf2af9acb28ed6d8bbe351d669daaa140d0239f0.zip | |
flash_lock, flash_unlock: new applets
By Thierry Reding (thierry.reding AT avionic-design.de)
Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/Config.in | 14 | ||||
| -rw-r--r-- | miscutils/Kbuild | 4 | ||||
| -rw-r--r-- | miscutils/flash_lock_unlock.c | 69 |
3 files changed, 86 insertions, 1 deletions
diff --git a/miscutils/Config.in b/miscutils/Config.in index 7feaf4a87..06ff51a7c 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
| @@ -250,6 +250,20 @@ config FBSPLASH | |||
| 250 | "NN" (ASCII decimal number) - percentage to show on progress bar | 250 | "NN" (ASCII decimal number) - percentage to show on progress bar |
| 251 | "exit" - well you guessed it | 251 | "exit" - well you guessed it |
| 252 | 252 | ||
| 253 | config FLASH_LOCK | ||
| 254 | bool "flash_lock" | ||
| 255 | default n | ||
| 256 | help | ||
| 257 | The flash_lock binary from mtd-utils as of git head 5ec0c10d0. This | ||
| 258 | utility locks part or all of the flash device. | ||
| 259 | |||
| 260 | config FLASH_UNLOCK | ||
| 261 | bool "flash_unlock" | ||
| 262 | default n | ||
| 263 | help | ||
| 264 | The flash_unlock binary from mtd-utils as of git head 5ec0c10d0. This | ||
| 265 | utility unlocks part or all of the flash device. | ||
| 266 | |||
| 253 | config FLASH_ERASEALL | 267 | config FLASH_ERASEALL |
| 254 | bool "flash_eraseall" | 268 | bool "flash_eraseall" |
| 255 | default n | 269 | default n |
diff --git a/miscutils/Kbuild b/miscutils/Kbuild index 23d7d8d49..8ae8a488a 100644 --- a/miscutils/Kbuild +++ b/miscutils/Kbuild | |||
| @@ -16,7 +16,9 @@ lib-$(CONFIG_DEVFSD) += devfsd.o | |||
| 16 | lib-$(CONFIG_DEVMEM) += devmem.o | 16 | lib-$(CONFIG_DEVMEM) += devmem.o |
| 17 | lib-$(CONFIG_EJECT) += eject.o | 17 | lib-$(CONFIG_EJECT) += eject.o |
| 18 | lib-$(CONFIG_FBSPLASH) += fbsplash.o | 18 | lib-$(CONFIG_FBSPLASH) += fbsplash.o |
| 19 | lib-$(CONFIG_FLASH_ERASEALL) += flash_eraseall.o | 19 | lib-$(CONFIG_FLASH_ERASEALL) += flash_eraseall.o |
| 20 | lib-$(CONFIG_FLASH_LOCK) += flash_lock_unlock.o | ||
| 21 | lib-$(CONFIG_FLASH_UNLOCK) += flash_lock_unlock.o | ||
| 20 | lib-$(CONFIG_IONICE) += ionice.o | 22 | lib-$(CONFIG_IONICE) += ionice.o |
| 21 | lib-$(CONFIG_HDPARM) += hdparm.o | 23 | lib-$(CONFIG_HDPARM) += hdparm.o |
| 22 | lib-$(CONFIG_INOTIFYD) += inotifyd.o | 24 | lib-$(CONFIG_INOTIFYD) += inotifyd.o |
diff --git a/miscutils/flash_lock_unlock.c b/miscutils/flash_lock_unlock.c new file mode 100644 index 000000000..f4e2f73b2 --- /dev/null +++ b/miscutils/flash_lock_unlock.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* Ported to busybox from mtd-utils. | ||
| 3 | * | ||
| 4 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | ||
| 5 | */ | ||
| 6 | #include "libbb.h" | ||
| 7 | #include <mtd/mtd-user.h> | ||
| 8 | |||
| 9 | int flash_lock_unlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
| 10 | int flash_lock_unlock_main(int argc UNUSED_PARAM, char **argv) | ||
| 11 | { | ||
| 12 | /* note: fields in these structs are 32-bits. | ||
| 13 | * apparently we can't win anything by using off_t | ||
| 14 | * or long long's for offset and/or sectors vars. */ | ||
| 15 | struct mtd_info_user info; | ||
| 16 | struct erase_info_user lock; | ||
| 17 | unsigned long offset; | ||
| 18 | long sectors; | ||
| 19 | int fd; | ||
| 20 | |||
| 21 | #define do_lock (ENABLE_FLASH_LOCK && (!ENABLE_FLASH_UNLOCK || (applet_name[6] == 'l'))) | ||
| 22 | |||
| 23 | if (!argv[1]) | ||
| 24 | bb_show_usage(); | ||
| 25 | |||
| 26 | /* parse offset and number of sectors to lock */ | ||
| 27 | offset = 0; | ||
| 28 | sectors = -1; | ||
| 29 | if (do_lock) { | ||
| 30 | if (!argv[2] || !argv[3]) | ||
| 31 | bb_show_usage(); | ||
| 32 | offset = xstrtoul(argv[2], 0); | ||
| 33 | sectors = xstrtol(argv[3], 0); | ||
| 34 | } | ||
| 35 | |||
| 36 | fd = xopen(argv[1], O_RDWR); | ||
| 37 | |||
| 38 | xioctl(fd, MEMGETINFO, &info); | ||
| 39 | |||
| 40 | lock.start = 0; | ||
| 41 | lock.length = info.size; | ||
| 42 | if (do_lock) { | ||
| 43 | unsigned long size = info.size - info.erasesize; | ||
| 44 | if (offset > size) { | ||
| 45 | bb_error_msg_and_die("%lx is beyond device size %lx\n", | ||
| 46 | offset, size); | ||
| 47 | } | ||
| 48 | |||
| 49 | if (sectors == -1) { | ||
| 50 | sectors = info.size / info.erasesize; | ||
| 51 | } else { | ||
| 52 | // isn't this useless? | ||
| 53 | unsigned long num = info.size / info.erasesize; | ||
| 54 | if (sectors > num) { | ||
| 55 | bb_error_msg_and_die("%ld are too many " | ||
| 56 | "sectors, device only has " | ||
| 57 | "%ld\n", sectors, num); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | lock.start = offset; | ||
| 62 | lock.length = sectors * info.erasesize; | ||
| 63 | xioctl(fd, MEMLOCK, &lock); | ||
| 64 | } else { | ||
| 65 | xioctl(fd, MEMUNLOCK, &lock); | ||
| 66 | } | ||
| 67 | |||
| 68 | return EXIT_SUCCESS; | ||
| 69 | } | ||
