diff mbox series

[LEDE-DEV,3/3] otrx: add support for -A (append) and -a (align) options

Message ID 20171113220747.31037-3-zajec5@gmail.com
State Accepted
Delegated to: Rafał Miłecki
Headers show
Series [LEDE-DEV,1/3] otrx: use helper function when checking image's CRC32 | expand

Commit Message

Rafał Miłecki Nov. 13, 2017, 10:07 p.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

They are inspired and compatible with the original and mjn3's trx tool.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 package/utils/otrx/src/otrx.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Comments

Hauke Mehrtens Nov. 15, 2017, 9:41 p.m. UTC | #1
On 11/13/2017 11:07 PM, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> They are inspired and compatible with the original and mjn3's trx tool.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>  package/utils/otrx/src/otrx.c | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 

Acked-by: Hauke Mehrtens <hauke@hauke-m.de>

for all patches, I commended in the full patch, but mostly on old code.

Hauke
diff mbox series

Patch

diff --git a/package/utils/otrx/src/otrx.c b/package/utils/otrx/src/otrx.c
index d08507f685..7e117c6e0d 100644
--- a/package/utils/otrx/src/otrx.c
+++ b/package/utils/otrx/src/otrx.c
@@ -346,7 +346,7 @@  static int otrx_create(int argc, char **argv) {
 	fseek(trx, curr_offset, SEEK_SET);
 
 	optind = 3;
-	while ((c = getopt(argc, argv, "f:b:")) != -1) {
+	while ((c = getopt(argc, argv, "f:A:a:b:")) != -1) {
 		switch (c) {
 		case 'f':
 			if (curr_idx >= TRX_MAX_PARTS) {
@@ -370,6 +370,27 @@  static int otrx_create(int argc, char **argv) {
 				curr_offset += sbytes;
 
 			break;
+		case 'A':
+			sbytes = otrx_create_append_file(trx, optarg);
+			if (sbytes < 0) {
+				fprintf(stderr, "Failed to append file %s\n", optarg);
+			} else {
+				curr_offset += sbytes;
+			}
+
+			sbytes = otrx_create_align(trx, curr_offset, 4);
+			if (sbytes < 0)
+				fprintf(stderr, "Failed to append zeros\n");
+			else
+				curr_offset += sbytes;
+			break;
+		case 'a':
+			sbytes = otrx_create_align(trx, curr_offset, strtol(optarg, NULL, 0));
+			if (sbytes < 0)
+				fprintf(stderr, "Failed to append zeros\n");
+			else
+				curr_offset += sbytes;
+			break;
 		case 'b':
 			sbytes = strtol(optarg, NULL, 0) - curr_offset;
 			if (sbytes < 0) {
@@ -541,6 +562,8 @@  static void usage() {
 	printf("Creating new TRX file:\n");
 	printf("\totrx create <file> [options] [partitions]\n");
 	printf("\t-f file\t\t\t\t[partition] start new partition with content copied from file\n");
+	printf("\t-A file\t\t\t\t[partition] append current partition with content copied from file\n");
+	printf("\t-a alignment\t\t\t[partition] align current partition\n");
 	printf("\t-b offset\t\t\t[partition] append zeros to partition till reaching absolute offset\n");
 	printf("\n");
 	printf("Extracting from TRX file:\n");