summaryrefslogtreecommitdiff
path: root/include/ubi_uboot.h
blob: bdf5645de3d2984df27865c3ab0306e83250a286 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Header file for UBI support for U-Boot
 *
 * Adaptation from kernel to U-Boot
 *
 *  Copyright (C) 2005-2007 Samsung Electronics
 *  Kyungmin Park <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __UBOOT_UBI_H
#define __UBOOT_UBI_H

#include <compiler.h>
#include <linux/compat.h>
#include <malloc.h>
#include <div64.h>
#include <linux/math64.h>
#include <linux/crc32.h>
#include <linux/types.h>
#include <linux/list.h>
#include <linux/rbtree.h>
#include <linux/string.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/ubi.h>

#ifdef CONFIG_CMD_ONENAND
#include <onenand_uboot.h>
#endif

#include <linux/errno.h>

/* build.c */
#define get_device(...)
#define put_device(...)
#define ubi_sysfs_init(...)		0
#define ubi_sysfs_close(...)		do { } while (0)

#ifndef __UBIFS_H__
#include "../drivers/mtd/ubi/ubi.h"
#endif

/* functions */
int ubi_mtd_param_parse(const char *val, struct kernel_param *kp);
int ubi_init(void);
void ubi_exit(void);

/**
 * ubi_detach() - detach UBI from MTD partition
 *
 * This function performs the cleanup of the UBI subsystem to make sure the
 * MTD partition can be safely used for another purpose, or be attached again
 * with ubi_part().
 *
 * Any mounted UBIFS will be unmounted automatically.
 *
 * Return: 0
 */
int ubi_detach(void);

/**
 * ubi_part() - attach UBI to MTD partition
 * @part_name: name of the MTD partition to attach
 * @vid_header_offset: VID header offset (string)
 *
 * This function detaches any existing UBI device, then probes for the
 * specified MTD partition, and then scans it to initialize UBI.
 *
 * @vid_header_offset is optional and is usually set to NULL.
 *
 * Return: 0 on success, or -ve on error.
 */
int ubi_part(const char *part_name, const char *vid_header_offset);

/**
 * ubi_volume_write() - write data to UBI volume
 * @volume: name of the volume to write to
 * @buf: data buffer to be written
 * @offset: start offset for writing
 * @size: number of bytes to write
 *
 * This function writes data to the specific UBI volume. If the offset is zero,
 * it initiates a full volume update. Otherwise, it performs an offset-based
 * write using LEB changes.
 *
 * Return: 0 on success, or -ve on error.
 */
int ubi_volume_write(const char *volume, const void *buf, loff_t offset,
		     size_t size);

/**
 * ubi_volume_read() - read data from UBI volume
 * @volume: name of the volume to read from
 * @buf: buffer to hold the read data
 * @offset: start offset for reading
 * @size: number of bytes to read
 *
 * This function reads data from the specified UBI volume. If @size is zero,
 * the function reads the entire volume content starting from @offset.
 *
 * Return: 0 on success, or -ve on error.
 */
int ubi_volume_read(const char *volume, void *buf, loff_t offset, size_t size);

/**
 * ubi_create_vol() - create UBI volume
 * @volume: name of the volume to create
 * @size: size of the volume in bytes
 * @dynamic: create dynamic volume if set to true
 * @vol_id: volume ID
 * @skipcheck: skip CRC check on this volume if set to true
 *
 * This function creates a new UBI volume with the specified parameters.
 * If @size is negative, all available space will be used.
 * For volume ID auto assignment, pass %UBI_VOL_NUM_AUTO to @vol_id.
 *
 * Return: 0 on success, or -ve on error.
 */
int ubi_create_vol(const char *volume, int64_t size, bool dynamic, int vol_id,
		   bool skipcheck);

/**
 * ubi_find_volume() - find UBI volume by name
 * @volume: name of the volume to find
 *
 * This function searches for a UBI volume with the specified name in the
 * current UBI device.
 *
 * Return: pointer to the UBI volume structure, or %NULL if not found.
 */
struct ubi_volume *ubi_find_volume(const char *volume);

/**
 * ubi_remove_vol() - remove UBI volume
 * @volume: name of the volume to remove
 *
 * This function removes an existing UBI volume from the current UBI device.
 *
 * Return: 0 on success, or -ve on error.
 */
int ubi_remove_vol(const char *volume);

extern struct ubi_device *ubi_devices[];
int cmd_ubifs_mount(const char *vol_name);
int cmd_ubifs_umount(void);

#if IS_ENABLED(CONFIG_UBI_BLOCK)
int ubi_bind(struct udevice *dev);
#else
static inline int ubi_bind(struct udevice *dev)
{
	return -EOPNOTSUPP;
}
#endif

#endif