Skip to content

Commit

Permalink
add registration of Mass storage gadget
Browse files Browse the repository at this point in the history
Use configfs to construct a mass storage gadget. This gadget requires
the mtdblock kernel driver.

company specific data is not final yet.
  • Loading branch information
svenrademakers committed Oct 23, 2023
1 parent c3a293e commit 2e2980e
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 60 deletions.
104 changes: 95 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ howudoin = {version="0.1.*", features=["term-line"]}
i2c-linux = "0.1.*"
income = "0.1.*"
nix = "0.26.*"
usb-gadget = "0.3.0"

[[bin]]
name= "sdcard"
path= "src/bin/sdcard.rs"

[[bin]]
name= "usb_gadget"
path= "src/bin/usb_gadget.rs"
82 changes: 31 additions & 51 deletions src/bin/sdcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
//! 4. The filesystem starts empty. Essential mountpoints like `/proc` and `/sys` need to be
//! established before any meaningful work can be done.
use nix::errno::Errno;
use nix::mount::{mount, MsFlags};

use std::{
fs,
io::{self, Read, Seek},
path::Path,
sync::{self, atomic, mpsc},
thread,
time::Duration,
};

use bmc_installer::{
bin_shared::*,
format, image,
nand::{mtd::MtdNand, Nand},
ubi::{
Expand All @@ -32,14 +29,6 @@ use bmc_installer::{
},
};

const BANNER: &str = r"
_____ _ _ ____ ___ _ _ ____
|_ _| | | | _ \|_ _| \ | |/ ___|
| | | | | | |_) || || \| | | _
| | | |_| | _ < | || |\ | |_| |
|_| \___/|_| \_\___|_| \_|\____|
";

const INSTRUCTIONS: &str = "\
This utility will perform a fresh installation of the Turing Pi 2 BMC firmware.
Expand All @@ -64,38 +53,6 @@ const BOOTLOADER_PATH: &str = "/dev/mmcblk0";
const BOOTLOADER_OFFSET: u64 = 8192; // Boot ROM expects this offset, so it will never change
const BOOTLOADER_SIZE: u64 = 5 * 64 * 2048;

/// Set up the basic environment (e.g. mount points).
fn setup_initramfs() -> anyhow::Result<()> {
// Handle mounts
for (mount_dev, mount_path, mount_type) in [
(None, "/dev", "devtmpfs"),
(None, "/proc", "proc"),
(None, "/sys", "sysfs"),
] {
let path = Path::new(mount_path);

if !path.is_dir() {
fs::create_dir(path)?;
}

let result = mount(
mount_dev.or(Some(path)),
path,
Some(mount_type),
MsFlags::empty(),
None::<&str>,
);

match result {
// Ignore EBUSY, which indicates that the mountpoint is already mounted.
Err(errno) if errno == Errno::EBUSY => (),
r => r?,
};
}

Ok(())
}

/// LED blink patterns
mod led {
use std::time::Duration;
Expand Down Expand Up @@ -138,13 +95,37 @@ mod led {

pub const LED_BUSY: &[LedState] = &[
Custom(Duration::from_millis(66), true, [true, false, false, false]),
Custom(Duration::from_millis(66), false, [false, true, false, false]),
Custom(
Duration::from_millis(66),
false,
[false, true, false, false],
),
Custom(Duration::from_millis(66), true, [false, false, true, false]),
Custom(Duration::from_millis(66), false, [false, false, false, true]),
Custom(Duration::from_millis(66), true, [false, false, false, false]),
Custom(Duration::from_millis(66), false, [false, false, false, false]),
Custom(Duration::from_millis(66), true, [false, false, false, false]),
Custom(Duration::from_millis(66), false, [false, false, false, false]),
Custom(
Duration::from_millis(66),
false,
[false, false, false, true],
),
Custom(
Duration::from_millis(66),
true,
[false, false, false, false],
),
Custom(
Duration::from_millis(66),
false,
[false, false, false, false],
),
Custom(
Duration::from_millis(66),
true,
[false, false, false, false],
),
Custom(
Duration::from_millis(66),
false,
[false, false, false, false],
),
];

pub const LED_DONE: &[LedState] = &[
Expand Down Expand Up @@ -253,7 +234,6 @@ fn rtl8370mb_led_thread(rx: mpsc::Receiver<[bool; 4]>) {
}
}


/// This runs in a thread and manages the LED blinking.
///
/// Send new blink patterns through the MPSC channel to change the active pattern.
Expand Down
Loading

0 comments on commit 2e2980e

Please sign in to comment.