summaryrefslogtreecommitdiffstats
path: root/utils/nwztools/upgtools/upg.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2020-07-21 15:15:10 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2020-10-11 13:08:03 +0200
commit1b5e82440549ab161e26863baa1bb06cc9f2aa64 (patch)
treebcc40634dcd7720de1a950174a9c1d2b2a291ce7 /utils/nwztools/upgtools/upg.c
parent1f338f70789fdb7d6bbd954cc1444f59a156e83c (diff)
downloadrockbox-1b5e824405.tar.gz
rockbox-1b5e824405.tar.bz2
rockbox-1b5e824405.zip
nwztool/upgtool: add support for compression
To decompress some output file(s), simply pass -z <idx> where idx is the index of the file to decompress, starting from 0. For example upgtool -e NW_WM_FW.UPG -o tmp/ -m nw-wm1a -z 6 -z 7 to decompress files 6 and 7. To compress file, use the same options: upgtool -c NW_WM_FW.UPG -m nw-wm1a -z 2 script.sh md5sum.txt system.img Change-Id: I1ef0b3e02c98e58154f1a959fb1ad70ad2ce6500
Diffstat (limited to 'utils/nwztools/upgtools/upg.c')
-rw-r--r--utils/nwztools/upgtools/upg.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/utils/nwztools/upgtools/upg.c b/utils/nwztools/upgtools/upg.c
index 47b1acb07b..67de12455f 100644
--- a/utils/nwztools/upgtools/upg.c
+++ b/utils/nwztools/upgtools/upg.c
@@ -319,13 +319,6 @@ void *upg_write_memory(struct upg_file_t *file, const char *key,
err_printf(GREY, "A UPG file must have at least one file\n");
return NULL;
}
- if(key_len == 16 && file->nr_files == 1)
- {
- err_printf(RED, "This will probably not work: the firmware updater for this device expects at least two files in the archive.\n");
- err_printf(RED, "The first one is a shell script and the second is a MD5 file. You can probably put whatever you want in this file,\n");
- err_printf(RED, "even make it empty, but it needs to be there.\n");
- /* let it run just in case */
- }
bool is_v2 = false;
size_t min_chunk_size, hdr_sz, ent_sz;
@@ -337,7 +330,7 @@ void *upg_write_memory(struct upg_file_t *file, const char *key,
}
else if(key_len == 16)
{
- min_chunk_size = 16;
+ min_chunk_size = 4096; /* experimentally, V2 UPG files always seem to have 4k sizes */
hdr_sz = sizeof(struct upg_header_v2_t);
ent_sz = sizeof(struct upg_entry_v2_t);
is_v2 = true;
@@ -348,6 +341,15 @@ void *upg_write_memory(struct upg_file_t *file, const char *key,
return NULL;
}
+ /* V2 wants at least two files, the second of which is supposed to contain MD5 sums */
+ if(is_v2 && file->nr_files == 1)
+ {
+ err_printf(RED, "This will probably not work: the firmware updater for this device expects at least two files in the archive.\n");
+ err_printf(RED, "The first one is a shell script and the second is a MD5 file. You can probably put whatever you want in this file,\n");
+ err_printf(RED, "even make it empty, but it needs to be there.\n");
+ /* let it run just in case */
+ }
+
/* compute total size and create buffer */
size_t tot_hdr_siz = hdr_sz + file->nr_files * ent_sz;
size_t tot_size = sizeof(struct upg_md5_t) + tot_hdr_siz;
@@ -386,17 +388,6 @@ void *upg_write_memory(struct upg_file_t *file, const char *key,
cprintf(RED, " %d\n", i);
cprintf_field(" Offset: ", "0x%lx\n", offset);
cprintf_field(" Size: ", "0x%lx\n", file->files[i].size);
- if(!is_v2)
- {
- entry_v1[i].offset = offset;
- entry_v1[i].size = file->files[i].size;
- }
- else
- {
- entry_v2[i].offset = offset;
- entry_v2[i].size = file->files[i].size;
- entry_v2[i].pad[0] = entry_v2[i].pad[1] = 0;
- }
/* copy data to buffer, with padding */
size_t r_size = ROUND_UP(file->files[i].size, min_chunk_size);
void *data_ptr = (uint8_t *)buf + offset;
@@ -413,6 +404,18 @@ void *upg_write_memory(struct upg_file_t *file, const char *key,
aes_cbc_enc_set_key_iv((uint8_t *)key, (uint8_t *)g_aes_iv);
aes_cbc_enc(data_ptr, r_size, data_ptr);
}
+ /* write header */
+ if(!is_v2)
+ {
+ entry_v1[i].offset = offset;
+ entry_v1[i].size = file->files[i].size;
+ }
+ else
+ {
+ entry_v2[i].offset = offset;
+ entry_v2[i].size = r_size; /* the V2 seems to write the padded size here */
+ entry_v2[i].pad[0] = entry_v2[i].pad[1] = 0;
+ }
offset += r_size;
}