forked from len0rd/rockbox
Update microtar users to new library API
Change-Id: I8e74efb53b8a8c9a4d69b2a20024434e2868e4e0
This commit is contained in:
parent
c1709e3194
commit
e4d8431211
2 changed files with 17 additions and 16 deletions
|
@ -23,7 +23,7 @@
|
||||||
#include "nand-x1000.h"
|
#include "nand-x1000.h"
|
||||||
#include "core_alloc.h"
|
#include "core_alloc.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "microtar.h"
|
#include "microtar-rockbox.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
struct update_part {
|
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,
|
static int patch_part(mtar_t* tar, const struct update_part* part,
|
||||||
uint8_t* img_buf, size_t img_off)
|
uint8_t* img_buf, size_t img_off)
|
||||||
{
|
{
|
||||||
mtar_header_t h;
|
int rc = mtar_find(tar, part->filename);
|
||||||
int rc = mtar_find(tar, part->filename, &h);
|
|
||||||
if(rc != MTAR_ESUCCESS)
|
if(rc != MTAR_ESUCCESS)
|
||||||
return IERR_BAD_FORMAT;
|
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;
|
return IERR_BAD_FORMAT;
|
||||||
|
|
||||||
if(h.size > part->length)
|
if(h->size > part->length)
|
||||||
return IERR_BAD_FORMAT;
|
return IERR_BAD_FORMAT;
|
||||||
|
|
||||||
/* wipe the patched area, and read in the new data */
|
/* wipe the patched area, and read in the new data */
|
||||||
memset(&img_buf[part->offset - img_off], 0xff, part->length);
|
memset(&img_buf[part->offset - img_off], 0xff, part->length);
|
||||||
rc = mtar_read_data(tar, &img_buf[part->offset - img_off], h.size);
|
rc = mtar_read_data(tar, &img_buf[part->offset - img_off], h->size);
|
||||||
if(rc != MTAR_ESUCCESS)
|
if(rc < 0 || (unsigned)rc != h->size)
|
||||||
return IERR_FILE_IO;
|
return IERR_FILE_IO;
|
||||||
|
|
||||||
return IERR_SUCCESS;
|
return IERR_SUCCESS;
|
||||||
|
@ -165,7 +165,7 @@ static int updater_init(struct updater* u)
|
||||||
|
|
||||||
CACHEALIGN_BUFFER(buffer, buf_len);
|
CACHEALIGN_BUFFER(buffer, buf_len);
|
||||||
u->tar = (mtar_t*)buffer;
|
u->tar = (mtar_t*)buffer;
|
||||||
memset(u->tar, 0, sizeof(struct mtar_t));
|
memset(u->tar, 0, sizeof(mtar_t));
|
||||||
|
|
||||||
rc = IERR_SUCCESS;
|
rc = IERR_SUCCESS;
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ static int updater_init(struct updater* u)
|
||||||
|
|
||||||
static void updater_cleanup(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);
|
mtar_close(u->tar);
|
||||||
|
|
||||||
if(u->buf_hnd >= 0)
|
if(u->buf_hnd >= 0)
|
||||||
|
@ -202,7 +202,7 @@ int install_bootloader(const char* filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the tarball */
|
/* 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_ESUCCESS) {
|
||||||
if(rc == MTAR_EOPENFAIL)
|
if(rc == MTAR_EOPENFAIL)
|
||||||
rc = IERR_FILE_NOT_FOUND;
|
rc = IERR_FILE_NOT_FOUND;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include "jztool.h"
|
#include "jztool.h"
|
||||||
#include "jztool_private.h"
|
#include "jztool_private.h"
|
||||||
#include "microtar.h"
|
#include "microtar-stdio.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -52,21 +52,22 @@ static int get_file(jz_context* jz, mtar_t* tar, const char* file,
|
||||||
bool decompress, jz_buffer** buf)
|
bool decompress, jz_buffer** buf)
|
||||||
{
|
{
|
||||||
jz_buffer* buffer = NULL;
|
jz_buffer* buffer = NULL;
|
||||||
mtar_header_t h;
|
const mtar_header_t* h;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = mtar_find(tar, file, &h);
|
rc = mtar_find(tar, file);
|
||||||
if(rc != MTAR_ESUCCESS) {
|
if(rc != MTAR_ESUCCESS) {
|
||||||
jz_log(jz, JZ_LOG_ERROR, "can't find %s in boot file, tar error %d", file, rc);
|
jz_log(jz, JZ_LOG_ERROR, "can't find %s in boot file, tar error %d", file, rc);
|
||||||
return JZ_ERR_BAD_FILE_FORMAT;
|
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)
|
if(!buffer)
|
||||||
return JZ_ERR_OUT_OF_MEMORY;
|
return JZ_ERR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
rc = mtar_read_data(tar, buffer->data, buffer->size);
|
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_buffer_free(buffer);
|
||||||
jz_log(jz, JZ_LOG_ERROR, "can't read %s in boot file, tar error %d", file, rc);
|
jz_log(jz, JZ_LOG_ERROR, "can't read %s in boot file, tar error %d", file, rc);
|
||||||
return JZ_ERR_BAD_FILE_FORMAT;
|
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);
|
sprintf(spl_filename, "spl.%s", dev_info->file_ext);
|
||||||
|
|
||||||
/* Now open the archive */
|
/* Now open the archive */
|
||||||
rc = mtar_open(&tar, filename, "r");
|
rc = mtar_open(&tar, filename, "rb");
|
||||||
if(rc != MTAR_ESUCCESS) {
|
if(rc != MTAR_ESUCCESS) {
|
||||||
jz_log(dev->jz, JZ_LOG_ERROR, "cannot open file %s (tar error: %d)", filename, rc);
|
jz_log(dev->jz, JZ_LOG_ERROR, "cannot open file %s (tar error: %d)", filename, rc);
|
||||||
return JZ_ERR_OPEN_FILE;
|
return JZ_ERR_OPEN_FILE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue