# Crochet i386 setup



## Phishfry (Sep 13, 2016)

I am using Crochet with the I386 board file and it is works very well.

I found these instructions very helpful for crochet setup:
https://project.altservice.com/issues/688
I simply edited my config.sh for I386.

The magic for including packages. (option Package <pkg name> in your config.sh)
https://github.com/freebsd/crochet/blob/master/option/Package
https://github.com/freebsd/crochet/tree/master/option/PackageInit

I wonder why there is no amd64 board file.
This seems like a good way to build an embedded install.


----------



## Phishfry (Sep 14, 2016)

I have found that the I386 crochet image I produced is no good and looking at the log it failed at the very end on bsdlabel.
Undeterred I tried to use crochet for a BeagleBone image. That failed as well. Desperate I tried the RPI2 board file and it worked. Whew.
Thought I was going nuts. I had broken it down to a simple board build with `./crochet.sh -b RaspberryPi2` and that worked so I made a config.conf for it and that burned a 2GB image that worked. So it works as advertised but some board profiles are broken. I386 board file is dated from 2013 and it appears the structure has changed since then. Not sure why BBB failed. Will work back to it.

Here is a sucessful build for RPI2

```
Overlaying board-specific files from /usr/local/src/crochet/board/RaspberryPi2/overlay
3 blocks
Installing FreeBSD kernel at Wed Sep 14 03:42:23 EDT 2016
  Destination: /usr/local/src/crochet/work/_.mount.freebsd
Installing ubldr in boot
SwapFile: Swapfile will be 768 MB
SwapFile: sizing swap file to 768 MiB
SwapFile: swap file created and configured.
Unmounting /usr/local/src/crochet/work/_.mount.boot
Unmounting /usr/local/src/crochet/work/_.mount.freebsd
Releasing md0
DONE.
Completed disk image is in: /usr/local/src/crochet/work/FreeBSD-RPI2.img

Copy to a suitable memory card using a command such as:
dd if=/usr/local/src/crochet/work/FreeBSD-RPI2.img of=/dev/da0 bs=1m
(Replace /dev/da0 with the appropriate path for your card reader.)

Finished at Wed Sep 14 03:43:14 EDT 2016
root@DEV:/usr/local/src/crochet #
```


----------



## Phishfry (Sep 14, 2016)

Here is a sucessful BBB build. I had a bad setting earlier. So only I386 not working.

```
Mounting FAT partition 1 at /usr/local/src/crochet/work/_.mount.boot
Mounting UFS partition 1 at /usr/local/src/crochet/work/_.mount.freebsd
Installing U-Boot from: /usr/local/share/u-boot/u-boot-beaglebone
Installing ubldr in /usr/local/src/crochet/work/_.mount.boot
Installing FreeBSD world at Wed Sep 14 05:04:53 EDT 2016
  Destination: /usr/local/src/crochet/work/_.mount.freebsd
Overlaying board-specific files from /usr/local/src/crochet/board/BeagleBone/overlay
8 blocks
Installing FreeBSD kernel at Wed Sep 14 05:07:38 EDT 2016
  Destination: /usr/local/src/crochet/work/_.mount.freebsd
Installing all ubldr files in boot
6577 blocks
Unmounting /usr/local/src/crochet/work/_.mount.boot
Unmounting /usr/local/src/crochet/work/_.mount.freebsd
Releasing md1
DONE.
Completed disk image is in: /usr/local/src/crochet/work/FreeBSD-armv6-11-BEAGLEBONE.img

Copy to a suitable memory card using a command such as:
dd if=/usr/local/src/crochet/work/FreeBSD-armv6-11-BEAGLEBONE.img of=/dev/da0 bs=1m
(Replace /dev/da0 with the appropriate path for your card reader.)

Finished at Wed Sep 14 05:08:05 EDT 2016
root@DEV:/usr/local/src/crochet #
```


----------



## Phishfry (Sep 14, 2016)

Here is the failed I386 board build.

```
Object files are at: /usr/local/src/crochet/work/obj/i386.i386/usr/src
Found suitable FreeBSD source tree in:
  /usr/src
Using FreeBSD i386 world from previous build
Using FreeBSD i386-GENERIC kernel from previous build
Creating a 600MB raw disk image in:
  /usr/local/src/crochet/work/FreeBSD-i386-11-GENERIC.img
Partitioning the raw disk image with MBR at Wed Sep 14 05:24:25 EDT 2016
gpart create -s MBR md1
md1 created
Creating an auto-sized UFS partition at Wed Sep 14 05:24:25 EDT 2016
md1s1 created
/dev/md1s1a: 572.1MB (1171712 sectors) block size 32768, fragment size 4096
  using 4 cylinder groups of 143.06MB, 4578 blks, 18432 inodes.
super-block backups (for fsck_ffs -b #) at:
 192, 293184, 586176, 879168
tunefs: soft updates set
Using inode 4 in cg 0 for 4194304 byte journal
tunefs: soft updates journaling set
tunefs: NFSv4 ACLs set
Installing bootblocks
Boot files are at: /usr/local/src/crochet/work/obj/i386.i386/usr/src/sys/boot/i386
bootcode written to md1
active set on md1s1
bsdlabel: /dev/md1s1a: no valid label found
root@DEV:/usr/local/src/crochet #
```


----------



## SirDice (Sep 14, 2016)

Looking at the last one, it looks like it's missing `gpart create -s BSD md1` and `gpart add -t freebsd-ufs -s <size> md1s1`. It looks like it creates a proper MBR slice but doesn't create the BSD partitions inside it.


----------



## Phishfry (Sep 14, 2016)

Looking at the BeagleBonePlusRaspberryPi board file comments there was a rework of crochet calls. The date on the last I386 commit was 2014 and the date on BeagleBonePlusRPi board file is 2015 so I am guessing there are broken routines in the older one too. I would like to fix the I386 script with the right calls(strategy list approach).

I am guessing there is no interest in a AMD64 version or maybe it's an EFI thing. Maybe building amd64 requires a different approach then building x86.


----------



## SirDice (Sep 15, 2016)

Phishfry said:


> I am guessing there is no interest in a AMD64 version or maybe it's an EFI thing.


One is not depending on the other. I've had AMD64 systems with an old fashioned BIOS. I would guess it's because there are very few AMD64 based development boards (for which the crochet tool is intended). 



> Maybe building amd64 requires a different approach then building x86.


It most likely isn't, the process on a "normal" desktop/server system is exactly the same for both architectures.


----------



## Phishfry (Sep 15, 2016)

Here is a complete build for the BananaPi:

```
root@DEV:/usr/local/src/crochet # ./crochet.sh -b BananaPi
Starting at Thu Sep 15 18:44:51 EDT 2016
Board: BananaPi
Source version is: unknown
Building FreeBSD version: 11.0
Image name is:
    /usr/local/src/crochet/work/FreeBSD-armv6-11-ALLWINNER.img
Building FreeBSD version: 11.0
Object files are at: /usr/local/src/crochet/work/obj/arm.armv6/usr/src
Found suitable FreeBSD source tree in:
    /usr/src
Found U-Boot port in:
    /usr/local/share/u-boot/u-boot-bananapi
Using FreeBSD armv6 world from previous build
Building FreeBSD armv6-ALLWINNER kernel at Thu Sep 15 18:44:51 EDT 2016
    (Logging to /usr/local/src/crochet/work/_.buildkernel.armv6-ALLWINNER.log)
Building FreeBSD armv6-ALLWINNER ubldr at Thu Sep 15 18:52:37 EDT 2016
    (Logging to /usr/local/src/crochet/work/ubldr-armv6ALLWINNER_.ubldr.armv6-ALLWINNER.build.log)
Creating a 1000MB raw disk image in:
    /usr/local/src/crochet/work/FreeBSD-armv6-11-ALLWINNER.img
Installing U-Boot files
21+1 records in
21+1 records out
22016 bytes transferred in 0.045748 secs (481249 bytes/sec)
335+1 records in
336+0 records out
344064 bytes transferred in 0.891903 secs (385764 bytes/sec)
Partitioning the raw disk image with MBR at Thu Sep 15 18:52:53 EDT 2016
gpart create -s MBR md3
md3 created
Creating a 32m FAT partition at Thu Sep 15 18:52:53 EDT 2016 with start block 1m and label BOOT
active set on md3s1
Creating an auto-sized UFS partition at Thu Sep 15 18:52:53 EDT 2016
md3s2 created
/dev/md3s2a: 920.6MB (1885312 sectors) block size 32768, fragment size 4096
        using 4 cylinder groups of 230.16MB, 7365 blks, 29568 inodes.
super-block backups (for fsck_ffs -b #) at:
 192, 471552, 942912, 1414272
tunefs: soft updates set
Using inode 4 in cg 0 for 4194304 byte journal
tunefs: soft updates journaling set
tunefs: NFSv4 ACLs set
Mounting all file systems:
Mounting FAT partition 1 at /usr/local/src/crochet/work/_.mount.boot
Mounting UFS partition 1 at /usr/local/src/crochet/work/_.mount.freebsd
Installing ubldr in /usr/local/src/crochet/work/_.mount.boot
Installing FreeBSD world at Thu Sep 15 18:52:55 EDT 2016
    Destination: /usr/local/src/crochet/work/_.mount.freebsd
Overlaying board-specific files from /usr/local/src/crochet/board/BananaPi/overlay
5 blocks
Installing FreeBSD kernel at Thu Sep 15 18:56:47 EDT 2016
    Destination: /usr/local/src/crochet/work/_.mount.freebsd
Installing all ubldr files in boot
1316 blocks
Unmounting /usr/local/src/crochet/work/_.mount.boot
Unmounting /usr/local/src/crochet/work/_.mount.freebsd
Releasing md3
DONE.
Completed disk image is in: /usr/local/src/crochet/work/FreeBSD-armv6-11-ALLWINNER.img

Copy to a suitable memory card using a command such as:
dd if=/usr/local/src/crochet/work/FreeBSD-armv6-11-ALLWINNER.img of=/dev/da0 bs=1m
(Replace /dev/da0 with the appropriate path for your card reader.)

Finished at Thu Sep 15 18:57:15 EDT 2016
```


----------



## Phishfry (May 8, 2017)

Finally got time to work on the GenericI386 board file. Copied some stuff from the Alix board file.

```
root@gigabyte:~ # cd /crochet
root@gigabyte:/crochet # ./crochet.sh -b GenericI386
Starting at Mon May 8 06:36:17 EDT 2017
Board: GenericI386
Source version is: unknown
Building FreeBSD version: 11.0
Image name is:
    /crochet/work/FreeBSD-i386-11-GENERIC.img
Building FreeBSD version: 11.0
Object files are at: /crochet/work/obj/i386.i386/usr/src
Found suitable FreeBSD source tree in:
    /usr/src
Using FreeBSD i386 world from previous build
Using FreeBSD i386-GENERIC kernel from previous build
Creating a 1600MB raw disk image in:
    /crochet/work/FreeBSD-i386-11-GENERIC.img
Partitioning the raw disk image with MBR at Mon May 8 06:36:18 EDT 2017
gpart create -s MBR md2
md2 created
Creating an auto-sized UFS partition at Mon May 8 06:36:18 EDT 2017
md2s1 created
/dev/md2s1a: 1524.9MB (3123072 sectors) block size 32768, fragment size 4096
   using 4 cylinder groups of 381.25MB, 12200 blks, 48896 inodes.
super-block backups (for fsck_ffs -b #) at:
 192, 780992, 1561792, 2342592
tunefs: soft updates set
Using inode 4 in cg 0 for 4194304 byte journal
tunefs: soft updates journaling set
tunefs: NFSv4 ACLs set
Installing bootblocks
Boot files are at: /crochet/work/obj/i386.i386/usr/src/sys/boot/i386
 gpart bootcode -b /crochet/work/obj/i386.i386/usr/src/sys/boot/i386/mbr/mbr md2
bootcode written to md2
 gpart set -a active -i 1 md2
active set on md2s1
 gpart bootcode -b /crochet/work/obj/i386.i386/usr/src/sys/boot/i386/boot2/boot md2s1
bootcode written to md2s1
=>     63  3124937  md2  MBR  (1.5G)
       63      961       - free -  (481K)
     1024  3123200    1  freebsd  [active]  (1.5G)
  3124224      776       - free -  (388K)

Mounting all file systems:
Mounting UFS partition 1 at /crochet/work/_.mount.freebsd
Installing FreeBSD world at Mon May 8 06:36:18 EDT 2017
    Destination: /crochet/work/_.mount.freebsd
Overlaying board-specific files from /crochet/board/GenericI386/overlay
1 block
Installing FreeBSD kernel at Mon May 8 06:37:03 EDT 2017
    Destination: /crochet/work/_.mount.freebsd
Unmounting /crochet/work/_.mount.freebsd
Releasing md2
DONE.
Completed disk image is in: /crochet/work/FreeBSD-i386-11-GENERIC.img

Copy to a suitable memory card using a command such as:
dd if=/crochet/work/FreeBSD-i386-11-GENERIC.img of=/dev/da0 bs=1m
(Replace /dev/da0 with the appropriate path for your card reader.)

Finished at Mon May 8 06:37:13 EDT 2017
root@gigabyte:/crochet #
```


----------



## Phishfry (May 9, 2017)

I have `crochet` writing i386 images with packages pre-installed.
That was what I wanted all along.

Making an amd64 board file has been much harder with GPT used and option of BIOS boot or EFI boot. Not sure I will finish that one.
Regardless building i386 images with pre-selected packages is awesome. I could even do a Wireless AP image with `dnsmasq` installed and dnsmasq.conf and hostapd.conf files in the overlay folder pre-configured along with /etc/rc.conf

Really useful stuff. I could also see it being useful for image deployment on scale.

So I fixed the crochet i386board setup.sh file and created an i386.cfg file for my options.
i386.cfg

```
board_setup GenericI386
option Resolv
option PackageInit
option Package /misc/ytree
```
 Then I run do this to make an image:

```
cd/ crochet
./crochet.sh -c i386.cfg
cd /crochet/work
dd if=FreeBSD-i386-11-GENERIC.img of=/dev/ada1 bs=64K conv=sync
```

Here is the fixed /crochet/board/GenericI386/setup.sh

```
TARGET_ARCH=i386
KERNCONF=GENERIC
IMAGE_SIZE=$((1600 * 1000 * 1000))

generic_i386_partition_image ( ) {
# basic setup
disk_partition_mbr
disk_ufs_create

# boot loader
echo "Installing bootblocks"

# TODO: This is broken; should use 'make install' to copy
# bootfiles to workdir, then install to disk image from there.

BOOTFILES=${FREEBSD_OBJDIR}/sys/boot/i386
echo "Boot files are at: "${BOOTFILES}

echo " gpart bootcode -b ${BOOTFILES}/mbr/mbr ${DISK_MD}"
gpart bootcode -b ${BOOTFILES}/mbr/mbr ${DISK_MD} || exit 1

echo " gpart set -a active -i 1 ${DISK_MD}"
gpart set -a active -i 1 ${DISK_MD} || exit 1

echo " gpart bootcode -b ${BOOTFILES}/boot2/boot ${DISK_MD}s1"
gpart bootcode -b ${BOOTFILES}/boot2/boot ${DISK_MD}s1 || exit 1

#show the disk
gpart show ${DISK_MD}
}

strategy_add $PHASE_PARTITION_LWW generic_i386_partition_image

# Kernel installs in UFS partition
strategy_add $PHASE_FREEBSD_BOARD_INSTALL board_default_installkernel .
```


----------

