github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/mount/mtd/types.go (about)

     1  // Copyright 2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package mtd
     6  
     7  // Flasher defines the interface to flash drivers.
     8  //
     9  // Many devices must have lazy writes; SyncWrite should always be
    10  // called after a sequence of QueueWrite commands.  Close should
    11  // return an error if there are queued write commands. To erase a
    12  // device, one calls chip Blank(), QueueWrite(), and SyncWrite(). The
    13  // operators are deined for the Flasher, not the Chipper, since
    14  // flashing can involve driver-level operations such as unlocking
    15  // protection bits on a bridge that are more than just a chip
    16  // operation.
    17  type Flasher interface {
    18  	// ReadAt implements io.ReadAt for a flash device.
    19  	ReadAt([]byte, int64) (int, error)
    20  	// QueueWrite queues a sequence of writes into a flash device.
    21  	QueueWrite([]byte, int64) (int, error)
    22  	// SyncWrite assembles the queued writes and figures out a reasonable
    23  	// plan for actually writing the part.
    24  	SyncWrite() error
    25  	// Close implements io.Close for a flash device.
    26  	Close() error
    27  }
    28  
    29  // VendorName is the manufacturers name
    30  type VendorName string
    31  
    32  // VendorID is the integer associated with a VendorName
    33  // It began as 8 bits, and never stopped growing.
    34  type VendorID uint64
    35  
    36  // ChipName is the device name
    37  type ChipName string
    38  
    39  // ChipID is the integer associated with a ChipName
    40  // It began as 8 bits, and never stopped growing.
    41  type ChipID uint64
    42  
    43  // ChipSize is the size in bytes of the chip.
    44  type ChipSize uint
    45  
    46  // Vendor defines operations on vendor data.
    47  type Vendor interface {
    48  	// Chip returns a Chip, given a DeviceID
    49  	Chip(ChipID) (Chip, error)
    50  	// ID Returns the VendorID
    51  	ID() VendorID
    52  	// Name() returns the canonical name
    53  	Name() VendorName
    54  	// Synonyms returns all the names
    55  	Synonyms() []VendorName
    56  }
    57  
    58  // Chip defines operations on Chips.
    59  type Chip interface {
    60  	// Name returns the chip name
    61  	Name() ChipName
    62  	// ID returns the chip ID
    63  	ID() ChipID
    64  	// Size returns the chip size.
    65  	Size() ChipSize
    66  	// Synonyms returns all the alternate names for a chip
    67  	Synonyms() []ChipName
    68  	// String returns as much information as one can stand about a chip.
    69  	String() string
    70  }
    71  
    72  // These struct are not designed to be efficient; rather, they are
    73  // designed to compress efficiently into firmware. Several experiments
    74  // show that this is about the best way to go, absent encoding it as a
    75  // string and unpacking it. We leave dead vendors in for reference
    76  // but comment them out.
    77  type vendor struct {
    78  	names []VendorName
    79  	id    VendorID
    80  }
    81  
    82  // ChipDevice has information about a chip, include Vendor, Device,
    83  // sizes, and so on; and a reference to common properties.
    84  // As in Vendors, there are several names for a chip.
    85  type ChipDevice struct {
    86  	vendor   VendorName
    87  	devices  []ChipName
    88  	remarks  string
    89  	id       ChipID
    90  	pageSize int
    91  	numPages int
    92  }