From e4d8431211eef3236a0030b49ed307ce6c048f6c Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Fri, 26 Nov 2021 14:46:26 +0000 Subject: Update microtar users to new library API Change-Id: I8e74efb53b8a8c9a4d69b2a20024434e2868e4e0 --- firmware/target/mips/ingenic_x1000/installer-x1000.c | 20 ++++++++++---------- rbutil/jztool/src/x1000.c | 13 +++++++------ 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 @@ #include "nand-x1000.h" #include "core_alloc.h" #include "file.h" -#include "microtar.h" +#include "microtar-rockbox.h" #include struct update_part { @@ -90,21 +90,21 @@ static void get_image_loc(nand_drv* ndrv, size_t* offptr, size_t* lenptr) static int patch_part(mtar_t* tar, const struct update_part* part, uint8_t* img_buf, size_t img_off) { - mtar_header_t h; - int rc = mtar_find(tar, part->filename, &h); + int rc = mtar_find(tar, part->filename); if(rc != MTAR_ESUCCESS) return IERR_BAD_FORMAT; - if(h.type != 0 && h.type != MTAR_TREG) + const mtar_header_t* h = mtar_get_header(tar); + if(h->type != 0 && h->type != MTAR_TREG) return IERR_BAD_FORMAT; - if(h.size > part->length) + if(h->size > part->length) return IERR_BAD_FORMAT; /* wipe the patched area, and read in the new data */ memset(&img_buf[part->offset - img_off], 0xff, part->length); - rc = mtar_read_data(tar, &img_buf[part->offset - img_off], h.size); - if(rc != MTAR_ESUCCESS) + rc = mtar_read_data(tar, &img_buf[part->offset - img_off], h->size); + if(rc < 0 || (unsigned)rc != h->size) return IERR_FILE_IO; return IERR_SUCCESS; @@ -165,7 +165,7 @@ static int updater_init(struct updater* u) CACHEALIGN_BUFFER(buffer, buf_len); u->tar = (mtar_t*)buffer; - memset(u->tar, 0, sizeof(struct mtar_t)); + memset(u->tar, 0, sizeof(mtar_t)); rc = IERR_SUCCESS; @@ -175,7 +175,7 @@ static int updater_init(struct updater* u) static void updater_cleanup(struct updater* u) { - if(u->tar && u->tar->close) + if(u->tar && mtar_is_open(u->tar)) mtar_close(u->tar); if(u->buf_hnd >= 0) @@ -202,7 +202,7 @@ int install_bootloader(const char* filename) } /* get the tarball */ - rc = mtar_open(u.tar, filename, "r"); + rc = mtar_open(u.tar, filename, O_RDONLY); if(rc != MTAR_ESUCCESS) { if(rc == MTAR_EOPENFAIL) 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 @@ #include "jztool.h" #include "jztool_private.h" -#include "microtar.h" +#include "microtar-stdio.h" #include #include @@ -52,21 +52,22 @@ static int get_file(jz_context* jz, mtar_t* tar, const char* file, bool decompress, jz_buffer** buf) { jz_buffer* buffer = NULL; - mtar_header_t h; + const mtar_header_t* h; int rc; - rc = mtar_find(tar, file, &h); + rc = mtar_find(tar, file); if(rc != MTAR_ESUCCESS) { jz_log(jz, JZ_LOG_ERROR, "can't find %s in boot file, tar error %d", file, rc); return JZ_ERR_BAD_FILE_FORMAT; } - buffer = jz_buffer_alloc(h.size, NULL); + h = mtar_get_header(tar); + buffer = jz_buffer_alloc(h->size, NULL); if(!buffer) return JZ_ERR_OUT_OF_MEMORY; rc = mtar_read_data(tar, buffer->data, buffer->size); - if(rc != MTAR_ESUCCESS) { + if(rc < 0 || (unsigned)rc != buffer->size) { jz_buffer_free(buffer); jz_log(jz, JZ_LOG_ERROR, "can't read %s in boot file, tar error %d", file, rc); return JZ_ERR_BAD_FILE_FORMAT; @@ -127,7 +128,7 @@ int jz_x1000_boot(jz_usbdev* dev, jz_device_type type, const char* filename) sprintf(spl_filename, "spl.%s", dev_info->file_ext); /* Now open the archive */ - rc = mtar_open(&tar, filename, "r"); + rc = mtar_open(&tar, filename, "rb"); if(rc != MTAR_ESUCCESS) { jz_log(dev->jz, JZ_LOG_ERROR, "cannot open file %s (tar error: %d)", filename, rc); return JZ_ERR_OPEN_FILE; -- cgit v1.2.3