Skip to content

Commit 1430003

Browse files
committed
Initial release
1 parent 7bf0531 commit 1430003

22 files changed

+1380
-0
lines changed

.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export CARGO_HOME=debian/cargo_home
2+
export CARGO_REGISTRY=debian/cargo_registry

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Rust build artifacts
2+
/target/
3+
Cargo.lock
4+
5+
# Debian packaging artifacts
6+
/debian/.debhelper/
7+
/debian/bmap2simg/
8+
/debian/bmap2simg.substvars
9+
/debian/cargo_home/
10+
/debian/cargo_out_dir
11+
/debian/cargo_registry/
12+
/debian/debhelper-build-stamp
13+
*.debhelper.log
14+
/debian/files
15+
.cargo-checksum.json
16+
17+
# Editor and IDE files
18+
.vscode/
19+
.idea/
20+
*.swp
21+
*.swo
22+
*~
23+
24+
# OS generated files
25+
.DS_Store
26+
.DS_Store?
27+
._*
28+
.Spotlight-V100
29+
.Trashes
30+
ehthumbs.db
31+
Thumbs.db

Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "bmap2simg"
3+
description = "Convert bmap images to Android sparse"
4+
homepage = "https://raspberrypi.com/software"
5+
repository = "https://github.com/raspberrypi/bmap2simg"
6+
version = "0.1.0"
7+
license = "BSD-3-Clause"
8+
edition = "2024"
9+
10+
[dependencies]
11+
clap = { version = "4.5", features = ["derive"] }
12+
openssl = "0.10.72"
13+
quick-xml = { version = "0.36.1", features = ["serialize"] }
14+
serde = { version = "1.0.217", features = ["derive"] }
15+
zerocopy = { version = "0.7", features = ["derive"] }
16+
17+
[build-dependencies]
18+
clap = { version = "4.5", features = ["derive"] }
19+
clap_mangen = "0.2.20"

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Redistribution and use in source and binary forms, with or without
2+
modification, are permitted provided that the following conditions are met:
3+
4+
1. Redistributions of source code must retain the above copyright notice,
5+
this list of conditions and the following disclaimer.
6+
7+
2. Redistributions in binary form must reproduce the above copyright notice,
8+
this list of conditions and the following disclaimer in the documentation
9+
and/or other materials provided with the distribution.
10+
11+
3. Neither the name of the copyright holder nor the names of its contributors
12+
may be used to endorse or promote products derived from this software
13+
without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25+
POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# bmap2simg
2+
3+
A utility that converts disk images with block map (bmap) sparse information to the Android sparse image format. The tool reads bmap files that describe which blocks of a disk image contain actual data, then creates an Android sparse image that efficiently stores only the mapped blocks whilst preserving the original image structure. This is particularly useful for creating compact, flashable images from larger disk images that contain significant amounts of empty space. Many fastboot implementations directly support sparse images.
4+
5+
## Building for Debian
6+
7+
This project is packaged as a native Debian package and uses Debian's `librust-*` packages for dependencies rather than downloading crates from crates.io, ensuring an isolated and reproducible build environment.
8+
9+
### Build Instructions
10+
11+
Install build dependencies:
12+
```bash
13+
sudo mk-build-deps -i
14+
```
15+
16+
Build the package:
17+
```bash
18+
debuild -b -uc -us
19+
```
20+
21+
The built `.deb` package will be created in the parent directory.
22+
23+
Cargo may be used directly in support of incremental builds by setting the
24+
following environment variables:
25+
```bash
26+
export CARGO_HOME=debian/cargo_home
27+
export CARGO_REGISTRY=debian/cargo_registry
28+
```
29+
30+
### Dependencies
31+
32+
All Rust dependencies are satisfied by Debian's `librust-*` packages as specified in `debian/control`. This ensures the build is completely isolated from external package registries and uses only packages that have been reviewed and packaged by Debian maintainers.

build.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use clap::CommandFactory;
2+
use clap_mangen::Man;
3+
use clap_mangen::roff::{Roff, roman};
4+
use std::env;
5+
use std::fs;
6+
7+
include!("src/cli.rs");
8+
9+
fn main() -> std::io::Result<()> {
10+
// Use OUT_DIR for build artifacts, not source directory
11+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
12+
13+
let cmd = Args::command();
14+
let man = Man::new(cmd);
15+
16+
let mut buffer: Vec<u8> = Default::default();
17+
18+
// Render standard sections
19+
man.render_title(&mut buffer)?;
20+
man.render_name_section(&mut buffer)?;
21+
man.render_synopsis_section(&mut buffer)?;
22+
man.render_description_section(&mut buffer)?;
23+
man.render_options_section(&mut buffer)?;
24+
25+
// Add custom EXAMPLES section
26+
let mut roff = Roff::default();
27+
roff.control("SH", ["EXAMPLES"]);
28+
roff.text([roman("Basic usage (stdin/stdout):")]);
29+
roff.text([roman(" bmap2simg file.bmap < input.img > output.simg")]);
30+
roff.text([roman("")]);
31+
roff.text([roman("With input file flag:")]);
32+
roff.text([roman(" bmap2simg file.bmap -i input.img > output.simg")]);
33+
roff.text([roman("")]);
34+
roff.text([roman("With output file flag:")]);
35+
roff.text([roman(" bmap2simg file.bmap -o output.simg < input.img")]);
36+
roff.text([roman("")]);
37+
roff.text([roman("With both flags:")]);
38+
roff.text([roman(" bmap2simg file.bmap -i input.img -o output.simg")]);
39+
roff.text([roman("")]);
40+
roff.text([roman("Pipeline with XZ compression:")]);
41+
roff.text([roman(" xzcat 2025-10-01-raspios-trixie-arm64.img.xz \\")]);
42+
roff.text([roman(
43+
" | bmap2simg 2025-10-01-raspios-trixie-arm64.bmap \\",
44+
)]);
45+
roff.text([roman(" | xz -6 \\")]);
46+
roff.text([roman(" > 2025-10-01-raspios-trixie-arm64.simg.xz")]);
47+
roff.text([roman("")]);
48+
roff.text([roman("This example demonstrates efficient processing of compressed images: decompress the XZ-compressed")]);
49+
roff.text([roman("image on-the-fly, convert it to sparse format using the block map, then recompress the sparse")]);
50+
roff.text([roman("image. This avoids storing the full uncompressed image on disk while creating a compressed")]);
51+
roff.text([roman(
52+
"sparse image that preserves the original block structure.",
53+
)]);
54+
55+
roff.to_writer(&mut buffer)?;
56+
57+
fs::write(out_dir.join("bmap2simg.1"), buffer)?;
58+
59+
println!("cargo:rerun-if-changed=src/cli.rs");
60+
println!("cargo:rerun-if-changed=src/main.rs");
61+
62+
Ok(())
63+
}

debian/cargo-checksum.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"package":"Could not get crate checksum","files":{}}

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bmap2simg (0.1.0) trixie; urgency=medium
2+
3+
* Initial release
4+
5+
-- Richard Oliver <[email protected]> Mon, 27 Oct 2025 10:10:57 +0000

debian/control

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Source: bmap2simg
2+
Section: utils
3+
Priority: optional
4+
Maintainer: Richard Oliver <[email protected]>
5+
Build-Depends: debhelper-compat (= 13),
6+
dh-cargo (>= 25),
7+
librust-clap-mangen-dev,
8+
librust-openssl-dev,
9+
librust-quick-xml-dev,
10+
librust-zerocopy-derive-dev
11+
Standards-Version: 4.7.2
12+
Homepage: https://raspberrypi.com/software
13+
Vcs-Git: https://github.com/raspberrypi/bmap2simg.git
14+
Vcs-Browser: https://github.com/raspberrypi/bmap2simg
15+
Rules-Requires-Root: no
16+
17+
Package: bmap2simg
18+
Architecture: any
19+
Built-Using: ${cargo:Built-Using}
20+
Static-Built-Using: ${cargo:Static-Built-Using}
21+
Depends: ${shlibs:Depends}, ${misc:Depends}
22+
Description: convert bmap images to sparse
23+
This utility converts disk images that have been supplied with bmap sparse
24+
information to the Android sparse format.

debian/copyright

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: bmap2simg
3+
Upstream-Contact: Richard Oliver <[email protected]>
4+
Source: https://www.raspberrypi.com/software
5+
6+
Files: *
7+
Copyright: 2025 Raspberry Pi Ltd
8+
License: BSD-3-Clause
9+
10+
Files: debian/*
11+
Copyright: 2025 Raspberry Pi Ltd
12+
License: BSD-3-Clause
13+
14+
License: BSD-3-Clause
15+
Redistribution and use in source and binary forms, with or without
16+
modification, are permitted provided that the following conditions are met:
17+
.
18+
1. Redistributions of source code must retain the above copyright notice,
19+
this list of conditions and the following disclaimer.
20+
.
21+
2. Redistributions in binary form must reproduce the above copyright notice,
22+
this list of conditions and the following disclaimer in the documentation
23+
and/or other materials provided with the distribution.
24+
.
25+
3. Neither the name of the copyright holder nor the names of its contributors
26+
may be used to endorse or promote products derived from this software
27+
without specific prior written permission.
28+
.
29+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
33+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39+
POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)