mtdabi

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2021 License: MIT Imports: 2 Imported by: 0

README

Go MTD ABI

Godoc Linux

Golang implementation of helper functions for the ioctl calls in the Linux MTD ABI, kernel version v5.12.

Status

EXPERIMENTAL.

No warranties--use at your own risk!

Usage

Opens a file pointing to an MTD device (/dev/mtd0) and obtains MTD info using MEMGETINFO.

package main

import (
	"fmt"
	"os"

	mtdabi "github.com/lhl2617/go-mtd-abi"
	"golang.org/x/sys/unix"
)

const mtdPath = "/dev/mtd0"

func main() {
	mtdFile, err := os.OpenFile(mtdPath, os.O_RDWR, 0644)
	check(err)

	// ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
	var mtdInfo unix.MtdInfo
	err = mtdabi.MemGetInfo(mtdFile.Fd(), &mtdInfo)
	check(err)
	// ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲

	fmt.Printf("%#v\n", mtdInfo)

	check(mtdFile.Close())
}

// check panics if the error is non-nil.
func check(err error) {
	if err != nil {
		panic(err)
	}
}

See more usage examples in the test file (mtdabi_test.go).

Development Guide

Please run tests in the Vagrant box given. You may spin up the Vagrant box and run tests as such:

# Set up and boot up the Vagrant box
vagrant up
# SSH into the box
vagrant ssh
# cd into the repo
cd /vagrant
# Run tests
sudo go test ./...

Contributing

Documentation

Overview

Package mtdabi is a Golang implementation of helper functions for the `ioctl` calls in the Linux MTD ABI found at https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/mtd/mtd-abi.h.

This package is currently based on version `v5.12` of the Linux kernel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EccGetLayout

func EccGetLayout(fd uintptr, value *unix.NandEcclayout) error

EccGetLayout gets ECC layout (deprecated)

#define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout_user)

func EccGetStats

func EccGetStats(fd uintptr, value *unix.MtdEccStats) error

EccGetStats gets statistics about corrected/uncorrected errors

#define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)

func MemErase

func MemErase(fd uintptr, value *unix.EraseInfo) error

MemErase erases segment of MTD

#define MEMERASE _IOW('M', 2, struct erase_info_user)

func MemErase64

func MemErase64(fd uintptr, value *unix.EraseInfo64) error

MemErase64 erases segment of MTD (supports 64-bit address)

#define MEMERASE64 _IOW('M', 20, struct erase_info_user64)

func MemGetBadBlock

func MemGetBadBlock(fd uintptr, value *int64) error

MemGetBadBlock checks if an eraseblock is bad

#define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t)

func MemGetInfo

func MemGetInfo(fd uintptr, value *unix.MtdInfo) error

MemGetInfo gets MTD characteristics info (better to use sysfs)

#define MEMGETINFO _IOR('M', 1, struct mtd_info_user)

func MemGetOobSel

func MemGetOobSel(fd uintptr, value *unix.NandOobinfo) error

MemGetOobSel gets info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface

#define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)

func MemGetRegionCount

func MemGetRegionCount(fd uintptr, value *int32) error

MemGetRegionCount gets the number of different erase regions

#define MEMGETREGIONCOUNT _IOR('M', 7, int)

func MemGetRegionInfo

func MemGetRegionInfo(fd uintptr, value *unix.RegionInfo) error

MemGetRegionInfo gets information about the erase region for a specific index

#define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)

func MemIsLocked

func MemIsLocked(fd uintptr, value *unix.EraseInfo) error

MemIsLocked checks if chip is locked (for MTD that supports it)

#define MEMISLOCKED _IOR('M', 23, struct erase_info_user)

func MemLock

func MemLock(fd uintptr, value *unix.EraseInfo) error

MemLock locks a chip (for MTD that supports it)

#define MEMLOCK _IOW('M', 5, struct erase_info_user)

func MemReadOob

func MemReadOob(fd uintptr, value *unix.MtdOobBuf) error

MemReadOob reads out-of-band data from MTD

#define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)

func MemReadOob64

func MemReadOob64(fd uintptr, value *unix.MtdOobBuf64) error

MemReadOob64 reads data from OOB (64-bit version)

#define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64)

func MemSetBadBlock

func MemSetBadBlock(fd uintptr, value *int64) error

MemSetBadBlock marks an eraseblock as bad

#define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t)

func MemUnlock

func MemUnlock(fd uintptr, value *unix.EraseInfo) error

MemUnlock unlocks a chip (for MTD that supports it)

#define MEMUNLOCK _IOW('M', 6, struct erase_info_user)

func MemWrite

func MemWrite(fd uintptr, value *unix.MtdWriteReq) error

MemWrite is the most generic write interface; can write in-band and/or out-of-band in various modes (see "struct mtd_write_req"). This ioctl is not supported for flashes without OOB, e.g., NOR flash.

#define MEMWRITE _IOWR('M', 24, struct mtd_write_req)

func MemWriteOob

func MemWriteOob(fd uintptr, value *unix.MtdOobBuf) error

MemWriteOob writes out-of-band data from MTD

#define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)

func MemWriteOob64

func MemWriteOob64(fd uintptr, value *unix.MtdOobBuf64) error

MemWriteOob64 writes data to OOB (64-bit version)

#define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64)

func MtdFileMode

func MtdFileMode(fd, value uintptr) error

MtdFileMode sets MTD mode on a per-file-descriptor basis (see "MTD file modes")

#define MTDFILEMODE _IO('M', 19)

func OtpGetRegionCount

func OtpGetRegionCount(fd uintptr, value *int32) error

OtpGetRegionCount gets number of OTP (One-Time Programmable) regions

#define OTPGETREGIONCOUNT _IOW('M', 14, int)

func OtpGetRegionInfo

func OtpGetRegionInfo(fd uintptr, value *unix.OtpInfo) error

OtpGetRegionInfo gets all OTP (One-Time Programmable) info about MTD

#define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)

func OtpLock

func OtpLock(fd uintptr, value *unix.OtpInfo) error

OtpLock locks a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER)

#define OTPLOCK _IOR('M', 16, struct otp_info)

func OtpSelect

func OtpSelect(fd uintptr, value *int32) error

OtpSelect sets OTP (One-Time Programmable) mode (factory vs. user)

#define OTPSELECT _IOR('M', 13, int)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL