aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-25 04:15:37 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-25 04:15:37 +0200
commitbf2af9acb28ed6d8bbe351d669daaa140d0239f0 (patch)
tree3adba401caf5c25406f89ebe053a0d9dbb043b54 /miscutils
parent4f26c97b9a2fdf6d967eafa06c67d04e432840a1 (diff)
downloadbusybox-bf2af9acb28ed6d8bbe351d669daaa140d0239f0.tar.gz
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.in14
-rw-r--r--miscutils/Kbuild4
-rw-r--r--miscutils/flash_lock_unlock.c69
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
"NN" (ASCII decimal number) - percentage to show on progress bar
"exit" - well you guessed it
+config FLASH_LOCK
+ bool "flash_lock"
+ default n
+ help
+ The flash_lock binary from mtd-utils as of git head 5ec0c10d0. This
+ utility locks part or all of the flash device.
+
+config FLASH_UNLOCK
+ bool "flash_unlock"
+ default n
+ help
+ The flash_unlock binary from mtd-utils as of git head 5ec0c10d0. This
+ utility unlocks part or all of the flash device.
+
config FLASH_ERASEALL
bool "flash_eraseall"
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
lib-$(CONFIG_DEVMEM) += devmem.o
lib-$(CONFIG_EJECT) += eject.o
lib-$(CONFIG_FBSPLASH) += fbsplash.o
-lib-$(CONFIG_FLASH_ERASEALL) += flash_eraseall.o
+lib-$(CONFIG_FLASH_ERASEALL) += flash_eraseall.o
+lib-$(CONFIG_FLASH_LOCK) += flash_lock_unlock.o
+lib-$(CONFIG_FLASH_UNLOCK) += flash_lock_unlock.o
lib-$(CONFIG_IONICE) += ionice.o
lib-$(CONFIG_HDPARM) += hdparm.o
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 @@
+/* vi: set sw=4 ts=4: */
+/* Ported to busybox from mtd-utils.
+ *
+ * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ */
+#include "libbb.h"
+#include <mtd/mtd-user.h>
+
+int flash_lock_unlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int flash_lock_unlock_main(int argc UNUSED_PARAM, char **argv)
+{
+ /* note: fields in these structs are 32-bits.
+ * apparently we can't win anything by using off_t
+ * or long long's for offset and/or sectors vars. */
+ struct mtd_info_user info;
+ struct erase_info_user lock;
+ unsigned long offset;
+ long sectors;
+ int fd;
+
+#define do_lock (ENABLE_FLASH_LOCK && (!ENABLE_FLASH_UNLOCK || (applet_name[6] == 'l')))
+
+ if (!argv[1])
+ bb_show_usage();
+
+ /* parse offset and number of sectors to lock */
+ offset = 0;
+ sectors = -1;
+ if (do_lock) {
+ if (!argv[2] || !argv[3])
+ bb_show_usage();
+ offset = xstrtoul(argv[2], 0);
+ sectors = xstrtol(argv[3], 0);
+ }
+
+ fd = xopen(argv[1], O_RDWR);
+
+ xioctl(fd, MEMGETINFO, &info);
+
+ lock.start = 0;
+ lock.length = info.size;
+ if (do_lock) {
+ unsigned long size = info.size - info.erasesize;
+ if (offset > size) {
+ bb_error_msg_and_die("%lx is beyond device size %lx\n",
+ offset, size);
+ }
+
+ if (sectors == -1) {
+ sectors = info.size / info.erasesize;
+ } else {
+// isn't this useless?
+ unsigned long num = info.size / info.erasesize;
+ if (sectors > num) {
+ bb_error_msg_and_die("%ld are too many "
+ "sectors, device only has "
+ "%ld\n", sectors, num);
+ }
+ }
+
+ lock.start = offset;
+ lock.length = sectors * info.erasesize;
+ xioctl(fd, MEMLOCK, &lock);
+ } else {
+ xioctl(fd, MEMUNLOCK, &lock);
+ }
+
+ return EXIT_SUCCESS;
+}