summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratinm <atinm.dev@gmail.com>2011-05-12 14:46:02 -0400
committeratinm <atinm.dev@gmail.com>2011-05-12 14:46:51 -0400
commit306e030c5772b1cd1d38a4801db2bc128021003a (patch)
tree4082be3cfbfb08a0af681c625403640d44ae0903
parente4ae19652aabdcf5de5b0c74c47a3795eaac9b77 (diff)
downloaddevice_samsung_aries-common-306e030c5772b1cd1d38a4801db2bc128021003a.zip
device_samsung_aries-common-306e030c5772b1cd1d38a4801db2bc128021003a.tar.gz
device_samsung_aries-common-306e030c5772b1cd1d38a4801db2bc128021003a.tar.bz2
Added bmlwrite
Change-Id: I2a3e025987d950b60aff2a4587cf86c2177f836f
-rw-r--r--aries/bmlutils/Android.mk11
-rw-r--r--aries/bmlutils/bmlwrite.c35
2 files changed, 46 insertions, 0 deletions
diff --git a/aries/bmlutils/Android.mk b/aries/bmlutils/Android.mk
new file mode 100644
index 0000000..cb7ec37
--- /dev/null
+++ b/aries/bmlutils/Android.mk
@@ -0,0 +1,11 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := bmlwrite
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_PATH := releasetools/kernel-tools
+LOCAL_SRC_FILES := bmlwrite.c
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+LOCAL_STATIC_LIBRARIES += libstdc++ libc
+include $(BUILD_EXECUTABLE)
+
diff --git a/aries/bmlutils/bmlwrite.c b/aries/bmlutils/bmlwrite.c
new file mode 100644
index 0000000..74860c6
--- /dev/null
+++ b/aries/bmlutils/bmlwrite.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+#define BML_UNLOCK_ALL 0x8A29 ///< unlock all partition RO -> RW
+
+int main(int argc, char** argv) {
+ char buf[4096];
+ int dstfd, srcfd, bytes_read, bytes_written, total_read = 0;
+ if (argc != 3)
+ return 1;
+ if (argv[1][0] == '-' && argv[1][1] == 0)
+ srcfd = 0;
+ else {
+ srcfd = open(argv[1], O_RDONLY | O_LARGEFILE);
+ if (srcfd < 0)
+ return 2;
+ }
+ dstfd = open(argv[2], O_RDWR | O_LARGEFILE);
+ if (dstfd < 0)
+ return 3;
+ if (ioctl(dstfd, BML_UNLOCK_ALL, 0))
+ return 4;
+ do {
+ total_read += bytes_read = read(srcfd, buf, 4096);
+ if (!bytes_read)
+ break;
+ if (bytes_read < 4096)
+ memset(&buf[bytes_read], 0, 4096 - bytes_read);
+ if (write(dstfd, buf, 4096) < 4096)
+ return 5;
+ } while(bytes_read == 4096);
+ return 0;
+}