imxtools: introduce rsrctool to manipulate rsrc sections
[maemo-rb.git] / utils / imxtools / sbtools / rsrc.h
blobfc310e348dfdda338c84868d1f5290855a97bb6d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2012 Amaury Pouly
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef __RSRC_H__
22 #define __RSRC_H__
24 #include <stdint.h>
25 #include <stdbool.h>
27 #include "misc.h"
29 #define RSRC_SECTOR_SIZE 2048
31 #define RSRC_TABLE_ENTRY_TYPE(e) ((e) >> 28)
32 #define RSRC_TABLE_ENTRY_OFFSET(e) ((e) & 0xfffffff)
34 #define RSRC_TYPE_NONE 0 /* empty entry */
35 #define RSRC_TYPE_NESTED 1 /* nested entry: points to a sub-table */
36 #define RSRC_TYPE_IMAGE 2 /* image entry */
37 #define RSRC_TYPE_VALUE 3 /* value stored on 28-bits */
38 #define RSRC_TYPE_AUDIO 4 /* audio entry */
39 #define RSRC_TYPE_DATA 5 /* data entry */
41 struct rsrc_file_t
43 void *data;
44 int size;
47 enum rsrc_error_t
49 RSRC_SUCCESS = 0,
50 RSRC_ERROR = -1,
51 RSRC_OPEN_ERROR = -2,
52 RSRC_READ_ERROR = -3,
53 RSRC_WRITE_ERROR = -4,
54 RSRC_FORMAT_ERROR = -5,
55 RSRC_CHECKSUM_ERROR = -6,
56 RSRC_NO_VALID_KEY = -7,
57 RSRC_FIRST_CRYPTO_ERROR = -8,
58 RSRC_LAST_CRYPTO_ERROR = RSRC_FIRST_CRYPTO_ERROR - CRYPTO_NUM_ERRORS,
61 enum rsrc_error_t rsrc_write_file(struct rsrc_file_t *rsrc, const char *filename);
63 typedef void (*rsrc_color_printf)(void *u, bool err, color_t c, const char *f, ...);
64 struct rsrc_file_t *rsrc_read_file(const char *filename, void *u,
65 rsrc_color_printf printf, enum rsrc_error_t *err);
66 /* use size_t(-1) to use maximum size */
67 struct rsrc_file_t *rsrc_read_file_ex(const char *filename, size_t offset, size_t size, void *u,
68 rsrc_color_printf printf, enum rsrc_error_t *err);
69 struct rsrc_file_t *rsrc_read_memory(void *buffer, size_t size, void *u,
70 rsrc_color_printf printf, enum rsrc_error_t *err);
72 void rsrc_dump(struct rsrc_file_t *file, void *u, rsrc_color_printf printf);
73 void rsrc_free(struct rsrc_file_t *file);
75 #endif /* __RSRC_H__ */