summaryrefslogtreecommitdiff
path: root/utils/imxtools/sbtools/rsrc.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/imxtools/sbtools/rsrc.h')
-rw-r--r--utils/imxtools/sbtools/rsrc.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/utils/imxtools/sbtools/rsrc.h b/utils/imxtools/sbtools/rsrc.h
new file mode 100644
index 0000000000..fc310e348d
--- /dev/null
+++ b/utils/imxtools/sbtools/rsrc.h
@@ -0,0 +1,76 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 Amaury Pouly
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __RSRC_H__
22#define __RSRC_H__
23
24#include <stdint.h>
25#include <stdbool.h>
26
27#include "misc.h"
28
29#define RSRC_SECTOR_SIZE 2048
30
31#define RSRC_TABLE_ENTRY_TYPE(e) ((e) >> 28)
32#define RSRC_TABLE_ENTRY_OFFSET(e) ((e) & 0xfffffff)
33
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 */
40
41struct rsrc_file_t
42{
43 void *data;
44 int size;
45};
46
47enum rsrc_error_t
48{
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,
59};
60
61enum rsrc_error_t rsrc_write_file(struct rsrc_file_t *rsrc, const char *filename);
62
63typedef void (*rsrc_color_printf)(void *u, bool err, color_t c, const char *f, ...);
64struct 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 */
67struct 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);
69struct rsrc_file_t *rsrc_read_memory(void *buffer, size_t size, void *u,
70 rsrc_color_printf printf, enum rsrc_error_t *err);
71
72void rsrc_dump(struct rsrc_file_t *file, void *u, rsrc_color_printf printf);
73void rsrc_free(struct rsrc_file_t *file);
74
75#endif /* __RSRC_H__ */
76