Skip to content

Commit

Permalink
Add initial implementation fwpkg_init()
Browse files Browse the repository at this point in the history
  • Loading branch information
matwey committed Aug 4, 2019
1 parent 16bbe89 commit e65e3b7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions include/fwpkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ struct fwpkg {
const char* error_str;
};

int fwpkg_from_file(struct fwpkg* fwpkg, const char* filename);
int fwpkg_from_preload(struct fwpkg* fwpkg);
int fwpkg_init(struct fwpkg* fwpkg, const char* filename);
int fwpkg_init_from_file(struct fwpkg* fwpkg, const char* filename);
int fwpkg_init_from_preload(struct fwpkg* fwpkg);
void fwpkg_destroy(struct fwpkg* fwpkg);

const char* fwpkg_get_error_string(struct fwpkg* fwpkg);
Expand Down
8 changes: 6 additions & 2 deletions src/fwpkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ static int fwpkg_locate_files(struct fwpkg* fwpkg) {
return 0;
}

int fwpkg_from_file(struct fwpkg* fwpkg, const char* filename) {
int fwpkg_init(struct fwpkg* fwpkg, const char* filename) {
return (filename ? fwpkg_init_from_file(fwpkg, filename) : fwpkg_init_from_preload(fwpkg));
}

int fwpkg_init_from_file(struct fwpkg* fwpkg, const char* filename) {
zip_error_t ze;
int error;

Expand All @@ -88,7 +92,7 @@ int fwpkg_from_file(struct fwpkg* fwpkg, const char* filename) {
return fwpkg_locate_files(fwpkg);
}

int fwpkg_from_preload(struct fwpkg* fwpkg) {
int fwpkg_init_from_preload(struct fwpkg* fwpkg) {
zip_error_t error;
zip_source_t *src = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/ov.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int ov_load_firmware(struct ov_device* ov, const char* filename) {
void* tmp = NULL;
int ret = 0;

ret = (filename ? fwpkg_from_file(&fwpkg, filename) : fwpkg_from_preload(&fwpkg));
ret = fwpkg_init(&fwpkg, filename);
if (ret < 0) {
ov->error_str = fwpkg_get_error_string(&fwpkg);
goto fail_fwpkg_from;
Expand Down
14 changes: 7 additions & 7 deletions test/fwpkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
START_TEST (test_fwpkg_load1) {
struct fwpkg fwpkg;
int ret;
ret = fwpkg_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg");
ret = fwpkg_init_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg");
ck_assert_int_eq(ret, 0);
fwpkg_destroy(&fwpkg);
}
END_TEST
START_TEST (test_fwpkg_load2) {
struct fwpkg fwpkg;
int ret;
ret = fwpkg_from_preload(&fwpkg);
ret = fwpkg_init_from_preload(&fwpkg);
ck_assert_int_eq(ret, 0);
fwpkg_destroy(&fwpkg);
}
END_TEST
START_TEST (test_fwpkg_size1) {
struct fwpkg fwpkg;
int ret;
ret = fwpkg_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg");
ret = fwpkg_init_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg");
ck_assert_int_eq(ret, 0);
ck_assert_uint_eq(fwpkg_map_size(&fwpkg), 2080);
ck_assert_uint_eq(fwpkg_bitstream_size(&fwpkg), 340972);
Expand All @@ -34,7 +34,7 @@ START_TEST (test_fwpkg_read1) {
size_t size;
struct fwpkg fwpkg;
int ret;
ret = fwpkg_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg");
ret = fwpkg_init_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg");
ck_assert_int_eq(ret, 0);
size = fwpkg_map_size(&fwpkg);
buf = malloc(size);
Expand All @@ -49,7 +49,7 @@ START_TEST (test_fwpkg_read2) {
size_t size;
struct fwpkg fwpkg;
int ret;
ret = fwpkg_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg");
ret = fwpkg_init_from_file(&fwpkg, PROJECT_ROOT "/ov3.fwpkg");
ck_assert_int_eq(ret, 0);
size = fwpkg_bitstream_size(&fwpkg);
buf = malloc(size);
Expand All @@ -64,7 +64,7 @@ START_TEST (test_fwpkg_read3) {
size_t size;
struct fwpkg fwpkg;
int ret;
ret = fwpkg_from_preload(&fwpkg);
ret = fwpkg_init_from_preload(&fwpkg);
ck_assert_int_eq(ret, 0);
size = fwpkg_map_size(&fwpkg);
buf = malloc(size);
Expand All @@ -79,7 +79,7 @@ START_TEST (test_fwpkg_read4) {
size_t size;
struct fwpkg fwpkg;
int ret;
ret = fwpkg_from_preload(&fwpkg);
ret = fwpkg_init_from_preload(&fwpkg);
ck_assert_int_eq(ret, 0);
size = fwpkg_bitstream_size(&fwpkg);
buf = malloc(size);
Expand Down

0 comments on commit e65e3b7

Please sign in to comment.