Skip to content

Commit 58822b5

Browse files
committed
feat: add support for mtd UAPI
This adds MTD (`mtd/mtd-user.h`) UAPI pieces, useful to manipulate MTD devices from Rust. This adds also a few `ioctl` exposed by this userspace API. Signed-off-by: Raito Bezarius <[email protected]>
1 parent a6a72df commit 58822b5

File tree

22 files changed

+4095
-1
lines changed

22 files changed

+4095
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static_assertions = "1.1.0"
2121
libc = "0.2.100"
2222

2323
[package.metadata.docs.rs]
24-
features = ["default", "ioctl", "netlink", "io_uring", "if_arp", "if_ether", "if_packet", "net", "prctl", "elf", "xdp", "mempolicy", "system"]
24+
features = ["default", "ioctl", "netlink", "io_uring", "if_arp", "if_ether", "if_packet", "net", "prctl", "elf", "xdp", "mempolicy", "system", "mtd"]
2525
targets = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
2626

2727
# The rest of this file is auto-generated!
@@ -34,6 +34,7 @@ if_packet = []
3434
io_uring = []
3535
ioctl = []
3636
mempolicy = []
37+
mtd = []
3738
net = []
3839
netlink = []
3940
prctl = []

gen/ioctl/list.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct sockaddr {
2525
struct __kernel_sockaddr_storage __storage;
2626
};
2727

28+
#include <mtd/mtd-abi.h>
2829
#include <linux/acrn.h>
2930
#include <linux/agpgart.h>
3031
#include <linux/am437x-vpfe.h>
@@ -2075,4 +2076,29 @@ void list(void) {
20752076
IOCTL_REQUEST(ACRN_IOCTL_RESET_VM);
20762077
IOCTL_REQUEST(ACRN_IOCTL_DESTROY_IOREQ_CLIENT);
20772078
IOCTL_REQUEST(ACRN_IOCTL_VM_INTR_MONITOR);
2079+
2080+
IOCTL_REQUEST(MEMGETINFO);
2081+
IOCTL_REQUEST(MEMERASE);
2082+
IOCTL_REQUEST(MEMWRITEOOB);
2083+
IOCTL_REQUEST(MEMLOCK);
2084+
IOCTL_REQUEST(MEMUNLOCK);
2085+
IOCTL_REQUEST(MEMGETREGIONCOUNT);
2086+
IOCTL_REQUEST(MEMGETREGIONINFO);
2087+
IOCTL_REQUEST(MEMGETOOBSEL);
2088+
IOCTL_REQUEST(MEMGETBADBLOCK);
2089+
IOCTL_REQUEST(MEMSETBADBLOCK);
2090+
IOCTL_REQUEST(OTPSELECT);
2091+
IOCTL_REQUEST(OTPGETREGIONINFO);
2092+
IOCTL_REQUEST(OTPGETREGIONCOUNT);
2093+
IOCTL_REQUEST(OTPLOCK);
2094+
IOCTL_REQUEST(ECCGETLAYOUT);
2095+
IOCTL_REQUEST(ECCGETSTATS);
2096+
IOCTL_REQUEST(MTDFILEMODE);
2097+
IOCTL_REQUEST(MEMERASE64);
2098+
IOCTL_REQUEST(MEMWRITEOOB64);
2099+
IOCTL_REQUEST(MEMREADOOB64);
2100+
IOCTL_REQUEST(MEMISLOCKED);
2101+
IOCTL_REQUEST(MEMWRITE);
2102+
IOCTL_REQUEST(OTPERASE);
2103+
IOCTL_REQUEST(MEMREAD);
20782104
}

gen/modules/mtd.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file includes selected Linux header files.
2+
3+
#include "support.h"
4+
5+
// Selected Linux headers.
6+
7+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
8+
#include <mtd/mtd-user.h>
9+
#endif

src/aarch64/mtd.rs

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/* automatically generated by rust-bindgen 0.66.1 */
2+
3+
pub type __s8 = crate::ctypes::c_schar;
4+
pub type __u8 = crate::ctypes::c_uchar;
5+
pub type __s16 = crate::ctypes::c_short;
6+
pub type __u16 = crate::ctypes::c_ushort;
7+
pub type __s32 = crate::ctypes::c_int;
8+
pub type __u32 = crate::ctypes::c_uint;
9+
pub type __s64 = crate::ctypes::c_longlong;
10+
pub type __u64 = crate::ctypes::c_ulonglong;
11+
pub type __kernel_key_t = crate::ctypes::c_int;
12+
pub type __kernel_mqd_t = crate::ctypes::c_int;
13+
pub type __kernel_old_uid_t = crate::ctypes::c_ushort;
14+
pub type __kernel_old_gid_t = crate::ctypes::c_ushort;
15+
pub type __kernel_long_t = crate::ctypes::c_long;
16+
pub type __kernel_ulong_t = crate::ctypes::c_ulong;
17+
pub type __kernel_ino_t = __kernel_ulong_t;
18+
pub type __kernel_mode_t = crate::ctypes::c_uint;
19+
pub type __kernel_pid_t = crate::ctypes::c_int;
20+
pub type __kernel_ipc_pid_t = crate::ctypes::c_int;
21+
pub type __kernel_uid_t = crate::ctypes::c_uint;
22+
pub type __kernel_gid_t = crate::ctypes::c_uint;
23+
pub type __kernel_suseconds_t = __kernel_long_t;
24+
pub type __kernel_daddr_t = crate::ctypes::c_int;
25+
pub type __kernel_uid32_t = crate::ctypes::c_uint;
26+
pub type __kernel_gid32_t = crate::ctypes::c_uint;
27+
pub type __kernel_old_dev_t = crate::ctypes::c_uint;
28+
pub type __kernel_size_t = __kernel_ulong_t;
29+
pub type __kernel_ssize_t = __kernel_long_t;
30+
pub type __kernel_ptrdiff_t = __kernel_long_t;
31+
pub type __kernel_off_t = __kernel_long_t;
32+
pub type __kernel_loff_t = crate::ctypes::c_longlong;
33+
pub type __kernel_old_time_t = __kernel_long_t;
34+
pub type __kernel_time_t = __kernel_long_t;
35+
pub type __kernel_time64_t = crate::ctypes::c_longlong;
36+
pub type __kernel_clock_t = __kernel_long_t;
37+
pub type __kernel_timer_t = crate::ctypes::c_int;
38+
pub type __kernel_clockid_t = crate::ctypes::c_int;
39+
pub type __kernel_caddr_t = *mut crate::ctypes::c_char;
40+
pub type __kernel_uid16_t = crate::ctypes::c_ushort;
41+
pub type __kernel_gid16_t = crate::ctypes::c_ushort;
42+
pub type __s128 = i128;
43+
pub type __u128 = u128;
44+
pub type __le16 = __u16;
45+
pub type __be16 = __u16;
46+
pub type __le32 = __u32;
47+
pub type __be32 = __u32;
48+
pub type __le64 = __u64;
49+
pub type __be64 = __u64;
50+
pub type __sum16 = __u16;
51+
pub type __wsum = __u32;
52+
pub type __poll_t = crate::ctypes::c_uint;
53+
pub type mtd_info_t = mtd_info_user;
54+
pub type erase_info_t = erase_info_user;
55+
pub type region_info_t = region_info_user;
56+
pub type nand_oobinfo_t = nand_oobinfo;
57+
pub type nand_ecclayout_t = nand_ecclayout_user;
58+
#[repr(C)]
59+
#[derive(Debug, Copy, Clone)]
60+
pub struct erase_info_user {
61+
pub start: __u32,
62+
pub length: __u32,
63+
}
64+
#[repr(C)]
65+
#[derive(Debug, Copy, Clone)]
66+
pub struct erase_info_user64 {
67+
pub start: __u64,
68+
pub length: __u64,
69+
}
70+
#[repr(C)]
71+
#[derive(Debug, Copy, Clone)]
72+
pub struct mtd_oob_buf {
73+
pub start: __u32,
74+
pub length: __u32,
75+
pub ptr: *mut crate::ctypes::c_uchar,
76+
}
77+
#[repr(C)]
78+
#[derive(Debug, Copy, Clone)]
79+
pub struct mtd_oob_buf64 {
80+
pub start: __u64,
81+
pub pad: __u32,
82+
pub length: __u32,
83+
pub usr_ptr: __u64,
84+
}
85+
#[repr(C)]
86+
#[derive(Debug, Copy, Clone)]
87+
pub struct mtd_write_req {
88+
pub start: __u64,
89+
pub len: __u64,
90+
pub ooblen: __u64,
91+
pub usr_data: __u64,
92+
pub usr_oob: __u64,
93+
pub mode: __u8,
94+
pub padding: [__u8; 7usize],
95+
}
96+
#[repr(C)]
97+
#[derive(Debug, Copy, Clone)]
98+
pub struct mtd_read_req_ecc_stats {
99+
pub uncorrectable_errors: __u32,
100+
pub corrected_bitflips: __u32,
101+
pub max_bitflips: __u32,
102+
}
103+
#[repr(C)]
104+
#[derive(Debug, Copy, Clone)]
105+
pub struct mtd_read_req {
106+
pub start: __u64,
107+
pub len: __u64,
108+
pub ooblen: __u64,
109+
pub usr_data: __u64,
110+
pub usr_oob: __u64,
111+
pub mode: __u8,
112+
pub padding: [__u8; 7usize],
113+
pub ecc_stats: mtd_read_req_ecc_stats,
114+
}
115+
#[repr(C)]
116+
#[derive(Debug, Copy, Clone)]
117+
pub struct mtd_info_user {
118+
pub type_: __u8,
119+
pub flags: __u32,
120+
pub size: __u32,
121+
pub erasesize: __u32,
122+
pub writesize: __u32,
123+
pub oobsize: __u32,
124+
pub padding: __u64,
125+
}
126+
#[repr(C)]
127+
#[derive(Debug, Copy, Clone)]
128+
pub struct region_info_user {
129+
pub offset: __u32,
130+
pub erasesize: __u32,
131+
pub numblocks: __u32,
132+
pub regionindex: __u32,
133+
}
134+
#[repr(C)]
135+
#[derive(Debug, Copy, Clone)]
136+
pub struct otp_info {
137+
pub start: __u32,
138+
pub length: __u32,
139+
pub locked: __u32,
140+
}
141+
#[repr(C)]
142+
#[derive(Debug, Copy, Clone)]
143+
pub struct nand_oobinfo {
144+
pub useecc: __u32,
145+
pub eccbytes: __u32,
146+
pub oobfree: [[__u32; 2usize]; 8usize],
147+
pub eccpos: [__u32; 32usize],
148+
}
149+
#[repr(C)]
150+
#[derive(Debug, Copy, Clone)]
151+
pub struct nand_oobfree {
152+
pub offset: __u32,
153+
pub length: __u32,
154+
}
155+
#[repr(C)]
156+
#[derive(Debug, Copy, Clone)]
157+
pub struct nand_ecclayout_user {
158+
pub eccbytes: __u32,
159+
pub eccpos: [__u32; 64usize],
160+
pub oobavail: __u32,
161+
pub oobfree: [nand_oobfree; 8usize],
162+
}
163+
#[repr(C)]
164+
#[derive(Debug, Copy, Clone)]
165+
pub struct mtd_ecc_stats {
166+
pub corrected: __u32,
167+
pub failed: __u32,
168+
pub badblocks: __u32,
169+
pub bbtblocks: __u32,
170+
}
171+
pub const MTD_ABSENT: u32 = 0;
172+
pub const MTD_RAM: u32 = 1;
173+
pub const MTD_ROM: u32 = 2;
174+
pub const MTD_NORFLASH: u32 = 3;
175+
pub const MTD_NANDFLASH: u32 = 4;
176+
pub const MTD_DATAFLASH: u32 = 6;
177+
pub const MTD_UBIVOLUME: u32 = 7;
178+
pub const MTD_MLCNANDFLASH: u32 = 8;
179+
pub const MTD_WRITEABLE: u32 = 1024;
180+
pub const MTD_BIT_WRITEABLE: u32 = 2048;
181+
pub const MTD_NO_ERASE: u32 = 4096;
182+
pub const MTD_POWERUP_LOCK: u32 = 8192;
183+
pub const MTD_SLC_ON_MLC_EMULATION: u32 = 16384;
184+
pub const MTD_CAP_ROM: u32 = 0;
185+
pub const MTD_CAP_RAM: u32 = 7168;
186+
pub const MTD_CAP_NORFLASH: u32 = 3072;
187+
pub const MTD_CAP_NANDFLASH: u32 = 1024;
188+
pub const MTD_CAP_NVRAM: u32 = 7168;
189+
pub const MTD_NANDECC_OFF: u32 = 0;
190+
pub const MTD_NANDECC_PLACE: u32 = 1;
191+
pub const MTD_NANDECC_AUTOPLACE: u32 = 2;
192+
pub const MTD_NANDECC_PLACEONLY: u32 = 3;
193+
pub const MTD_NANDECC_AUTOPL_USR: u32 = 4;
194+
pub const MTD_OTP_OFF: u32 = 0;
195+
pub const MTD_OTP_FACTORY: u32 = 1;
196+
pub const MTD_OTP_USER: u32 = 2;
197+
pub const MTD_MAX_OOBFREE_ENTRIES: u32 = 8;
198+
pub const MTD_MAX_ECCPOS_ENTRIES: u32 = 64;
199+
pub const MTD_OPS_PLACE_OOB: _bindgen_ty_1 = _bindgen_ty_1::MTD_OPS_PLACE_OOB;
200+
pub const MTD_OPS_AUTO_OOB: _bindgen_ty_1 = _bindgen_ty_1::MTD_OPS_AUTO_OOB;
201+
pub const MTD_OPS_RAW: _bindgen_ty_1 = _bindgen_ty_1::MTD_OPS_RAW;
202+
#[repr(u32)]
203+
#[non_exhaustive]
204+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
205+
pub enum _bindgen_ty_1 {
206+
MTD_OPS_PLACE_OOB = 0,
207+
MTD_OPS_AUTO_OOB = 1,
208+
MTD_OPS_RAW = 2,
209+
}
210+
#[repr(u32)]
211+
#[non_exhaustive]
212+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
213+
pub enum mtd_file_modes {
214+
MTD_FILE_MODE_NORMAL = 0,
215+
MTD_FILE_MODE_OTP_FACTORY = 1,
216+
MTD_FILE_MODE_OTP_USER = 2,
217+
MTD_FILE_MODE_RAW = 3,
218+
}

0 commit comments

Comments
 (0)