2011-06-27 14:39:51 +08:00
|
|
|
#ifndef __PTX_IMAGE_H
|
|
|
|
#define __PTX_IMAGE_H
|
|
|
|
|
2019-01-16 17:12:04 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <confuse.h>
|
2011-06-27 14:39:51 +08:00
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
struct image_handler;
|
|
|
|
|
|
|
|
struct image *image_get(const char *filename);
|
|
|
|
|
|
|
|
int systemp(struct image *image, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
|
|
|
void error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
|
2018-02-14 22:54:14 +08:00
|
|
|
void info(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
|
|
|
|
void debug(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
|
2011-06-27 14:39:51 +08:00
|
|
|
void image_error(struct image *image, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
2018-02-14 22:54:14 +08:00
|
|
|
void image_info(struct image *image, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
|
|
|
void image_debug(struct image *image, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
2017-11-12 01:02:34 +08:00
|
|
|
void xasprintf(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
2021-02-24 20:19:51 +08:00
|
|
|
void xstrcatf(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
2011-06-27 14:39:51 +08:00
|
|
|
|
2022-03-25 20:44:31 +08:00
|
|
|
void disable_rootpath(void);
|
2011-06-27 14:39:51 +08:00
|
|
|
const char *imagepath(void);
|
|
|
|
const char *inputpath(void);
|
|
|
|
const char *rootpath(void);
|
|
|
|
const char *tmppath(void);
|
2020-08-28 21:36:48 +08:00
|
|
|
const char *mountpath(const struct image *);
|
2011-06-27 14:39:51 +08:00
|
|
|
struct flash_type;
|
|
|
|
|
|
|
|
struct mountpoint {
|
|
|
|
char *path;
|
|
|
|
struct list_head list;
|
|
|
|
char *mountpath;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct partition {
|
|
|
|
unsigned long long offset;
|
|
|
|
unsigned long long size;
|
2021-01-11 05:54:22 +08:00
|
|
|
unsigned long long align;
|
2011-06-27 14:39:51 +08:00
|
|
|
unsigned char partition_type;
|
2011-10-10 22:38:27 +08:00
|
|
|
cfg_bool_t bootable;
|
2011-11-06 06:27:46 +08:00
|
|
|
cfg_bool_t extended;
|
2016-01-04 20:49:49 +08:00
|
|
|
cfg_bool_t read_only;
|
2020-03-24 02:01:50 +08:00
|
|
|
cfg_bool_t hidden;
|
|
|
|
cfg_bool_t no_automount;
|
2023-02-24 18:52:22 +08:00
|
|
|
cfg_bool_t fill;
|
2011-06-27 14:39:51 +08:00
|
|
|
const char *image;
|
|
|
|
struct list_head list;
|
|
|
|
int autoresize;
|
2011-10-10 22:38:22 +08:00
|
|
|
int in_partition_table;
|
2011-06-27 14:39:51 +08:00
|
|
|
const char *name;
|
2019-01-16 17:12:04 +08:00
|
|
|
const char *partition_type_uuid;
|
|
|
|
const char *partition_uuid;
|
2021-10-22 21:11:19 +08:00
|
|
|
cfg_t *cfg;
|
2011-06-27 14:39:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct image {
|
|
|
|
const char *name;
|
|
|
|
const char *file;
|
|
|
|
unsigned long long size;
|
2021-03-25 20:24:48 +08:00
|
|
|
struct extent *holes;
|
|
|
|
int n_holes;
|
2019-05-06 14:58:42 +08:00
|
|
|
cfg_bool_t size_is_percent;
|
2011-06-27 14:39:51 +08:00
|
|
|
const char *mountpoint;
|
2022-03-19 00:26:27 +08:00
|
|
|
const char *srcpath;
|
2019-09-21 18:20:03 +08:00
|
|
|
cfg_bool_t empty;
|
2020-11-17 22:15:18 +08:00
|
|
|
cfg_bool_t temporary;
|
2011-10-10 22:38:28 +08:00
|
|
|
const char *exec_pre;
|
|
|
|
const char *exec_post;
|
2011-06-27 14:39:51 +08:00
|
|
|
unsigned char partition_type;
|
|
|
|
void *handler_priv;
|
|
|
|
struct image_handler *handler;
|
|
|
|
struct list_head list;
|
|
|
|
int done;
|
|
|
|
struct flash_type *flash_type;
|
|
|
|
cfg_t *imagesec;
|
|
|
|
struct list_head partitions;
|
|
|
|
struct mountpoint *mp;
|
2011-06-27 15:55:09 +08:00
|
|
|
char *outfile;
|
2011-06-27 16:06:38 +08:00
|
|
|
int seen;
|
2018-12-17 20:45:31 +08:00
|
|
|
off_t last_offset;
|
2011-06-27 14:39:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct image_handler {
|
|
|
|
char *type;
|
2022-03-25 20:44:31 +08:00
|
|
|
cfg_bool_t no_rootpath;
|
2012-06-26 14:32:28 +08:00
|
|
|
int (*parse)(struct image *i, cfg_t *cfg);
|
2011-06-27 14:39:51 +08:00
|
|
|
int (*setup)(struct image *i, cfg_t *cfg);
|
|
|
|
int (*generate)(struct image *i);
|
|
|
|
cfg_opt_t *opts;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct flash_type {
|
|
|
|
const char *name;
|
|
|
|
int pebsize;
|
|
|
|
int lebsize;
|
|
|
|
int numpebs;
|
|
|
|
int minimum_io_unit_size;
|
|
|
|
int vid_header_offset;
|
|
|
|
int sub_page_size;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct flash_type *flash_type_get(const char *name);
|
|
|
|
|
2021-01-12 15:46:22 +08:00
|
|
|
extern struct image_handler android_sparse_handler;
|
2012-11-25 05:59:58 +08:00
|
|
|
extern struct image_handler cpio_handler;
|
2016-09-06 17:54:49 +08:00
|
|
|
extern struct image_handler cramfs_handler;
|
2011-06-27 14:39:51 +08:00
|
|
|
extern struct image_handler ext2_handler;
|
2011-10-11 17:05:01 +08:00
|
|
|
extern struct image_handler ext3_handler;
|
|
|
|
extern struct image_handler ext4_handler;
|
2022-03-21 18:30:29 +08:00
|
|
|
extern struct image_handler f2fs_handler;
|
2011-06-27 14:39:51 +08:00
|
|
|
extern struct image_handler file_handler;
|
2012-11-25 05:59:58 +08:00
|
|
|
extern struct image_handler flash_handler;
|
|
|
|
extern struct image_handler hdimage_handler;
|
|
|
|
extern struct image_handler iso_handler;
|
|
|
|
extern struct image_handler jffs2_handler;
|
2018-03-20 04:44:53 +08:00
|
|
|
extern struct image_handler qemu_handler;
|
2016-08-05 17:51:05 +08:00
|
|
|
extern struct image_handler rauc_handler;
|
2014-02-19 18:16:54 +08:00
|
|
|
extern struct image_handler squashfs_handler;
|
2012-11-25 05:59:58 +08:00
|
|
|
extern struct image_handler tar_handler;
|
|
|
|
extern struct image_handler ubi_handler;
|
|
|
|
extern struct image_handler ubifs_handler;
|
2012-06-22 14:27:52 +08:00
|
|
|
extern struct image_handler vfat_handler;
|
2018-02-14 23:03:55 +08:00
|
|
|
extern struct image_handler fit_handler;
|
2022-04-01 20:00:53 +08:00
|
|
|
extern struct image_handler fip_handler;
|
2011-06-27 14:39:51 +08:00
|
|
|
|
|
|
|
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
|
|
|
|
|
|
|
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* container_of - cast a member of a structure out to the containing structure
|
|
|
|
* @ptr: the pointer to the member.
|
|
|
|
* @type: the type of the container struct this is embedded in.
|
|
|
|
* @member: the name of the member within the struct.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
|
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
|
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
|
|
|
|
|
|
|
void *xzalloc(size_t n);
|
2020-11-27 18:35:05 +08:00
|
|
|
void *xrealloc(void *ptr, size_t size);
|
2019-05-06 14:48:24 +08:00
|
|
|
unsigned long long strtoul_suffix(const char *str, char **endp,
|
|
|
|
cfg_bool_t *percent);
|
2011-06-27 14:39:51 +08:00
|
|
|
|
|
|
|
int init_config(void);
|
2011-06-27 15:38:33 +08:00
|
|
|
cfg_opt_t *get_confuse_opts(void);
|
2011-06-27 14:39:51 +08:00
|
|
|
const char *get_opt(const char *name);
|
|
|
|
int set_config_opts(int argc, char *argv[], cfg_t *cfg);
|
|
|
|
|
2021-01-12 15:45:22 +08:00
|
|
|
static inline size_t min(size_t a, size_t b)
|
|
|
|
{
|
|
|
|
return a < b ? a : b;
|
|
|
|
}
|
|
|
|
|
2011-06-27 14:39:51 +08:00
|
|
|
enum pad_mode {
|
|
|
|
MODE_APPEND,
|
|
|
|
MODE_OVERWRITE,
|
|
|
|
};
|
|
|
|
|
2021-01-12 15:45:22 +08:00
|
|
|
struct extent {
|
|
|
|
unsigned long long start, end;
|
|
|
|
};
|
|
|
|
|
|
|
|
int open_file(struct image *image, const char *filename, int extra_flags);
|
|
|
|
int map_file_extents(struct image *image, const char *filename, int fd,
|
|
|
|
size_t size, struct extent **extents, size_t *extent_count);
|
2018-12-17 20:45:31 +08:00
|
|
|
int is_block_device(const char *filename);
|
image-hd.c: use size of destination block device as image size
Currently, when writing a GPT image directly to a block device, the
image generation fails when hdimage_insert_gpt() calls extend_file(),
because the computed size of the image (based on the defined
partitions etc.) is smaller than what extend_file() sees when it does
the SEEK_END sanity check.
So when the target is a block device and the image size has not been
set explicitly, set image->size from the actual size of the block
device. In case one has a few board variants with slightly differing
eMMC sizes, that will automatically DTRT - we still do all the sanity
checks that the defined partitions do not exceed the image size etc.
In fact, when writing directly to a block device, we are implicitly
populating the whole device - and in particular, when writing a GPT
image, the backup header must be placed at the end of the
device. There is currently no known use case for setting a non-zero
image size (and having genimage check that is <= the actual size
etc...), so for now enforce that image->size is not set for a block
device target.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2021-12-22 20:24:36 +08:00
|
|
|
int block_device_size(struct image *image, const char *blkdev,
|
|
|
|
unsigned long long *size);
|
2022-03-25 16:39:57 +08:00
|
|
|
int prepare_image(struct image *image, unsigned long long size);
|
2021-03-26 21:18:16 +08:00
|
|
|
int insert_image(struct image *image, struct image *sub,
|
2021-04-26 01:42:54 +08:00
|
|
|
unsigned long long size, unsigned long long offset,
|
|
|
|
unsigned char byte);
|
2020-11-18 03:54:27 +08:00
|
|
|
int insert_data(struct image *image, const void *data, const char *outfile,
|
2023-02-08 20:38:35 +08:00
|
|
|
size_t size, unsigned long long offset);
|
2019-05-07 13:51:31 +08:00
|
|
|
int extend_file(struct image *image, size_t size);
|
2018-12-17 22:37:23 +08:00
|
|
|
int reload_partitions(struct image *image);
|
2021-10-22 21:11:19 +08:00
|
|
|
int parse_holes(struct image *image, cfg_t *cfg);
|
2011-06-27 14:39:51 +08:00
|
|
|
|
2011-06-27 15:47:48 +08:00
|
|
|
unsigned long long cfg_getint_suffix(cfg_t *sec, const char *name);
|
2019-05-06 14:48:24 +08:00
|
|
|
unsigned long long cfg_getint_suffix_percent(cfg_t *sec, const char *name,
|
|
|
|
cfg_bool_t *percent);
|
2011-06-27 15:47:48 +08:00
|
|
|
|
2015-09-06 04:05:11 +08:00
|
|
|
static inline const char *imageoutfile(const struct image *image)
|
2011-06-27 15:55:09 +08:00
|
|
|
{
|
|
|
|
return image->outfile;
|
|
|
|
}
|
2019-01-16 17:12:04 +08:00
|
|
|
|
2020-01-31 18:39:36 +08:00
|
|
|
char *sanitize_path(const char *path);
|
|
|
|
|
2019-01-16 17:12:04 +08:00
|
|
|
int uuid_validate(const char *str);
|
|
|
|
void uuid_parse(const char *str, unsigned char *uuid);
|
|
|
|
char *uuid_random(void);
|
|
|
|
|
2019-05-06 14:50:05 +08:00
|
|
|
unsigned long long image_dir_size(struct image *image);
|
|
|
|
|
2019-01-16 17:12:04 +08:00
|
|
|
uint32_t crc32(const void *data, size_t len);
|
2021-01-12 15:43:44 +08:00
|
|
|
uint32_t crc32_next(const void *data, size_t len, uint32_t last_crc);
|
2019-01-16 17:12:04 +08:00
|
|
|
|
2020-11-18 03:23:10 +08:00
|
|
|
#define ct_assert(e) _Static_assert(e, #e)
|
|
|
|
|
2011-06-27 14:39:51 +08:00
|
|
|
#endif /* __PTX_IMAGE_H */
|