summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-11-26 14:46:26 +0000
committerAidan MacDonald <amachronic@protonmail.com>2021-11-27 13:13:39 +0000
commite4d8431211eef3236a0030b49ed307ce6c048f6c (patch)
tree7125ad78575aaa49d6127b6b4bd812ee9e54bae0
parentc1709e3194855b93ffd6f68eaa750c6704b3e52f (diff)
downloadrockbox-e4d8431211eef3236a0030b49ed307ce6c048f6c.tar.gz
rockbox-e4d8431211eef3236a0030b49ed307ce6c048f6c.zip
Update microtar users to new library API
Change-Id: I8e74efb53b8a8c9a4d69b2a20024434e2868e4e0
-rw-r--r--firmware/target/mips/ingenic_x1000/installer-x1000.c20
-rw-r--r--rbutil/jztool/src/x1000.c13
2 files changed, 17 insertions, 16 deletions
diff --git a/firmware/target/mips/ingenic_x1000/installer-x1000.c b/firmware/target/mips/ingenic_x1000/installer-x1000.c
index 617e6645b7..0a09ad0e91 100644
--- a/firmware/target/mips/ingenic_x1000/installer-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/installer-x1000.c
@@ -23,7 +23,7 @@
23#include "nand-x1000.h" 23#include "nand-x1000.h"
24#include "core_alloc.h" 24#include "core_alloc.h"
25#include "file.h" 25#include "file.h"
26#include "microtar.h" 26#include "microtar-rockbox.h"
27#include <stddef.h> 27#include <stddef.h>
28 28
29struct update_part { 29struct update_part {
@@ -90,21 +90,21 @@ static void get_image_loc(nand_drv* ndrv, size_t* offptr, size_t* lenptr)
90static int patch_part(mtar_t* tar, const struct update_part* part, 90static int patch_part(mtar_t* tar, const struct update_part* part,
91 uint8_t* img_buf, size_t img_off) 91 uint8_t* img_buf, size_t img_off)
92{ 92{
93 mtar_header_t h; 93 int rc = mtar_find(tar, part->filename);
94 int rc = mtar_find(tar, part->filename, &h);
95 if(rc != MTAR_ESUCCESS) 94 if(rc != MTAR_ESUCCESS)
96 return IERR_BAD_FORMAT; 95 return IERR_BAD_FORMAT;
97 96
98 if(h.type != 0 && h.type != MTAR_TREG) 97 const mtar_header_t* h = mtar_get_header(tar);
98 if(h->type != 0 && h->type != MTAR_TREG)
99 return IERR_BAD_FORMAT; 99 return IERR_BAD_FORMAT;
100 100
101 if(h.size > part->length) 101 if(h->size > part->length)
102 return IERR_BAD_FORMAT; 102 return IERR_BAD_FORMAT;
103 103
104 /* wipe the patched area, and read in the new data */ 104 /* wipe the patched area, and read in the new data */
105 memset(&img_buf[part->offset - img_off], 0xff, part->length); 105 memset(&img_buf[part->offset - img_off], 0xff, part->length);
106 rc = mtar_read_data(tar, &img_buf[part->offset - img_off], h.size); 106 rc = mtar_read_data(tar, &img_buf[part->offset - img_off], h->size);
107 if(rc != MTAR_ESUCCESS) 107 if(rc < 0 || (unsigned)rc != h->size)
108 return IERR_FILE_IO; 108 return IERR_FILE_IO;
109 109
110 return IERR_SUCCESS; 110 return IERR_SUCCESS;
@@ -165,7 +165,7 @@ static int updater_init(struct updater* u)
165 165
166 CACHEALIGN_BUFFER(buffer, buf_len); 166 CACHEALIGN_BUFFER(buffer, buf_len);
167 u->tar = (mtar_t*)buffer; 167 u->tar = (mtar_t*)buffer;
168 memset(u->tar, 0, sizeof(struct mtar_t)); 168 memset(u->tar, 0, sizeof(mtar_t));
169 169
170 rc = IERR_SUCCESS; 170 rc = IERR_SUCCESS;
171 171
@@ -175,7 +175,7 @@ static int updater_init(struct updater* u)
175 175
176static void updater_cleanup(struct updater* u) 176static void updater_cleanup(struct updater* u)
177{ 177{
178 if(u->tar && u->tar->close) 178 if(u->tar && mtar_is_open(u->tar))
179 mtar_close(u->tar); 179 mtar_close(u->tar);
180 180
181 if(u->buf_hnd >= 0) 181 if(u->buf_hnd >= 0)
@@ -202,7 +202,7 @@ int install_bootloader(const char* filename)
202 } 202 }
203 203
204 /* get the tarball */ 204 /* get the tarball */
205 rc = mtar_open(u.tar, filename, "r"); 205 rc = mtar_open(u.tar, filename, O_RDONLY);
206 if(rc != MTAR_ESUCCESS) { 206 if(rc != MTAR_ESUCCESS) {
207 if(rc == MTAR_EOPENFAIL) 207 if(rc == MTAR_EOPENFAIL)
208 rc = IERR_FILE_NOT_FOUND; 208 rc = IERR_FILE_NOT_FOUND;
diff --git a/rbutil/jztool/src/x1000.c b/rbutil/jztool/src/x1000.c
index aacad0ef01..f59727a2ca 100644
--- a/rbutil/jztool/src/x1000.c
+++ b/rbutil/jztool/src/x1000.c
@@ -21,7 +21,7 @@
21 21
22#include "jztool.h" 22#include "jztool.h"
23#include "jztool_private.h" 23#include "jztool_private.h"
24#include "microtar.h" 24#include "microtar-stdio.h"
25#include <stdbool.h> 25#include <stdbool.h>
26#include <string.h> 26#include <string.h>
27 27
@@ -52,21 +52,22 @@ static int get_file(jz_context* jz, mtar_t* tar, const char* file,
52 bool decompress, jz_buffer** buf) 52 bool decompress, jz_buffer** buf)
53{ 53{
54 jz_buffer* buffer = NULL; 54 jz_buffer* buffer = NULL;
55 mtar_header_t h; 55 const mtar_header_t* h;
56 int rc; 56 int rc;
57 57
58 rc = mtar_find(tar, file, &h); 58 rc = mtar_find(tar, file);
59 if(rc != MTAR_ESUCCESS) { 59 if(rc != MTAR_ESUCCESS) {
60 jz_log(jz, JZ_LOG_ERROR, "can't find %s in boot file, tar error %d", file, rc); 60 jz_log(jz, JZ_LOG_ERROR, "can't find %s in boot file, tar error %d", file, rc);
61 return JZ_ERR_BAD_FILE_FORMAT; 61 return JZ_ERR_BAD_FILE_FORMAT;
62 } 62 }
63 63
64 buffer = jz_buffer_alloc(h.size, NULL); 64 h = mtar_get_header(tar);
65 buffer = jz_buffer_alloc(h->size, NULL);
65 if(!buffer) 66 if(!buffer)
66 return JZ_ERR_OUT_OF_MEMORY; 67 return JZ_ERR_OUT_OF_MEMORY;
67 68
68 rc = mtar_read_data(tar, buffer->data, buffer->size); 69 rc = mtar_read_data(tar, buffer->data, buffer->size);
69 if(rc != MTAR_ESUCCESS) { 70 if(rc < 0 || (unsigned)rc != buffer->size) {
70 jz_buffer_free(buffer); 71 jz_buffer_free(buffer);
71 jz_log(jz, JZ_LOG_ERROR, "can't read %s in boot file, tar error %d", file, rc); 72 jz_log(jz, JZ_LOG_ERROR, "can't read %s in boot file, tar error %d", file, rc);
72 return JZ_ERR_BAD_FILE_FORMAT; 73 return JZ_ERR_BAD_FILE_FORMAT;
@@ -127,7 +128,7 @@ int jz_x1000_boot(jz_usbdev* dev, jz_device_type type, const char* filename)
127 sprintf(spl_filename, "spl.%s", dev_info->file_ext); 128 sprintf(spl_filename, "spl.%s", dev_info->file_ext);
128 129
129 /* Now open the archive */ 130 /* Now open the archive */
130 rc = mtar_open(&tar, filename, "r"); 131 rc = mtar_open(&tar, filename, "rb");
131 if(rc != MTAR_ESUCCESS) { 132 if(rc != MTAR_ESUCCESS) {
132 jz_log(dev->jz, JZ_LOG_ERROR, "cannot open file %s (tar error: %d)", filename, rc); 133 jz_log(dev->jz, JZ_LOG_ERROR, "cannot open file %s (tar error: %d)", filename, rc);
133 return JZ_ERR_OPEN_FILE; 134 return JZ_ERR_OPEN_FILE;