github.com/usbarmory/armory-boot@v0.0.0-20240307133412-208c66a380b9/disk/disk.go (about) 1 // https://github.com/usbarmory/armory-boot 2 // 3 // Copyright (c) WithSecure Corporation 4 // https://foundry.withsecure.com 5 // 6 // Use of this source code is governed by the license 7 // that can be found in the LICENSE file. 8 9 package disk 10 11 import ( 12 "errors" 13 "fmt" 14 "strconv" 15 16 "github.com/usbarmory/tamago/soc/nxp/usdhc" 17 ) 18 19 // DefaultBootDevice is the default boot device 20 const DefaultBootDevice = "uSD" 21 22 // DefaultOffset is the default start offset of the ext4 partition 23 const DefaultOffset = 5242880 24 25 // Detect initializes the USB armory internal flash ("eMMC") or external 26 // microSD card ("uSD") as boot device, an ext4 partition must be present at 27 // the passed start offset. An empty value for device or start parameter selects 28 // its default value. 29 func Detect(card *usdhc.USDHC, start string) (part *Partition, err error) { 30 offset := int64(DefaultOffset) 31 32 if card == nil { 33 return nil, errors.New("invalid card") 34 } 35 36 if len(start) > 0 { 37 if offset, err = strconv.ParseInt(start, 10, 64); err != nil { 38 return nil, fmt.Errorf("invalid start offset, %v\n", err) 39 } 40 } 41 42 part = &Partition{ 43 Card: card, 44 Offset: offset, 45 } 46 47 if err := part.Card.Detect(); err != nil { 48 return nil, fmt.Errorf("could not detect card, %v\n", err) 49 } 50 51 return 52 }