makefs help

I am trying to generate a makefs msdos/EFI filesystem like so:


But I want to add a 16M/32768 sector offset to begining of image file. For u-boot.

The manual shows -O as the flag for offset but if I dig deeper the at "@" symbol is used (as per the program help too)
https://man.freebsd.org/cgi/man.cgi?query=makefs ((see MSDOS Section for further manual linkage))

The makefs manual points to an invocation from newfs_msdosfs : -@63s (As found in example at bottom)
From all looks this should be the syntax needed.
Do I use it like this:
-O offset="-@63s"
-o offset="-@63s"

Nothing seems to be valid input.

makefs -t msdos -s 50m -o fat_type=16 -o sectors_per_cluster=1 -O -@63s test.img
makefs: offset `-@63s': illegal number

I also read a negative value is needed for a makefs offset.... I don't know how to do that.

More drilling down it looks like -@ is not valid.

Code:
~ # makefs -t msdos -s 50m -o fat_type=16 -o sectors_per_cluster=1 -O -@63 test.img
makefs: offset `-@63': illegal number

~ # makefs -t msdos -s 50m -o fat_type=16 -o sectors_per_cluster=1 -O -@ 63 test.img
makefs: offset `-@': illegal number

~ # makefs -t msdos -s 50m -o fat_type=16 -o sectors_per_cluster=1 -O -@ offset=63s test.img
makefs: offset `-@': illegal number

~ # makefs -t msdos -s 50m -o fat_type=16 -o sectors_per_cluster=1 -O -@ -o offset=63s test.img
makefs: offset `-@': illegal number

Please help me offset image file for u-boot.

Thanks
 
Well all the manuals in the world don't beat trying all possible combinations.
I am getting closer. I had made a blank image file for this but it apears it is done for you:

Code:
# makefs -t msdos -s 50m -o fat_type=16 -o sectors_per_cluster=1 -o offset=16m test.img /test/files
Creating `test.img'
makefs: warning: FAT type limits file system to 66069 sectors
test.img: 65524 sectors in 65524 FAT16 clusters (512 bytes/cluster)
BytesPerSec=512 SecPerClust=1 ResSectors=1 FATs=2 RootDirEnts=512 Media=0xf0 FATsecs=256 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=66069
makefs: msdosfs_mount: Invalid argument

So totally drop the -O and -@ and add size. Still not sure about last message there...

If you notice I did have to add a path to files.
 
This ended up being the solution I needed to create EFI/ESP Partion using makefs with a 16 Megabyte beginning offset for u-boot.

makefs -t msdos -o fat_type=32 -o sectors_per_cluster=1 -o volume_label=EFISYS -s 50m -o 16384 efi.img boot

The subdirectory of 'boot' in my command is populated with the ESP partition directories and files.

Code:
makefs: Unknown option `16384'
Creating `efi.img'
efi.img: 100792 sectors in 100792 FAT32 clusters (512 bytes/cluster)
BytesPerSec=512 SecPerClust=1 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=102400 FATsecs=788 RootCluster=2 FSInfo=1 Backup=2
Populating `efi.img'
Image `efi.img' complete

It shows an error but works fine. Mountable and has the correct EFI file structure from my 'boot' files directory. Correct offset.

So I create GPT scheme with gpart create -s GPT da0 and then I dd the efi.img file to da0 with offset.
dd if=efi.img of=/dev/da0 bs=512 seek=40 status=progress

Code:
# gpart show da0
=>      40  31686576  da0  GPT  (15G)
        40     32728       - free -  (16M)
     32768    102400    1  efi  (50M)
    135168  31551448       - free -  (15G)
 
Why would you try creating a filesystem with offset? You need a partition with offset, which you created.
Then you just create msdos filesystem on that partition or dd of=da0p1 if=efi.img.
Am I missing something?
 
I am trying to modify the poudriere image script for image building. It leaves no freespace space for bootloader u-boot.
I figured it was a good time to learn makefs. Test the makefs options before modifying a complex script.

Thanks for the advice. I will see if I can find where the scripts adds partitions.


I was looking at source code for Arm Images in /release thinking of ways to do this via script once I have free space.

Code:
arm_install_uboot() {
    UBOOT_DIR="/usr/local/share/u-boot/u-boot-rock64"
    UBOOT_FILE_1="idbloader.img"
    UBOOT_FILE_2="u-boot.itb"
    chroot ${CHROOTDIR} dd if=${UBOOT_DIR}/${UBOOT_FILE_1} \
        of=/dev/${mddev} bs=512 seek=64 conv=sync
    chroot ${CHROOTDIR} dd if=${UBOOT_DIR}/${UBOOT_FILE_2} \
        of=/dev/${mddev} bs=512 seek=16384 conv=sync
    return 0

nanobsd embedded common

Code:
dos_boot_part ( ) (
    local d=/usr/local/share/u-boot/${NANO_BOOT_PKG}
    local f=${NANO_FAT_DIR}

    # For now, just copy all the files. However, for iMX6 and Allwinner,
    # we'll need to put a special boot block at a fixed location
    # on the disk as well.
    rm -rf $f
    mkdir $f
    chdir $f
    cp ${d}/* .

    # Also copy ubldr. u-boot will load it and it will load the kernel
    # from the ufs partition
    cp ${NANO_WORLDDIR}/boot/ubldr .
    cp ${NANO_WORLDDIR}/boot/ubldr.bin .

I could write a post-install script. poudriere image has that option.

It seems stupid to let it build wrong then go back and copy ESP to directory, delete partion, then re-add partition with offset.
Then format, mount, copy back ESP and umount.

I am looking to help improve or implement new feature of poudriere image.
 
You need a partition with offset, which you created.
But I did not.
Here is what I did above.
gpart destroy -F /dev/da0
dd zero da0
gpart create -s GPT

Then I wrote efi.img to drive with offset of seek=40 To preserve GPT.

I gained my freespace and it created a efi partition with files intact.

So mission accomplished?

But how did GPT find partition I flashed it to the disk....How did partion table get updated?
Usually you have to do gpart recover to get second GPT table back when messing with end of disk.

I noticed when you makefs with offset you can no longer mount the filesystem via mdconfig.
But when you dd the image to a disk it works.
Maybe not proper way but sometimes it helps to just see it work,

I have a feeling something is wrong. Manpage seems different than program help for options.
I looked at source and was studying makefs.c to make sure -O is in fact what I need. It seems so.

Code:
               case 'O':
                        fsoptions.offset =
                            strsuftoll("offset", optarg, 0LL, LLONG_MAX);
                        break;
 
I am not trying to be a idiot. I realize a filesystem offset is not the same as a partition offset.

Usually I do this:
gpart create -s GPT da0
gpart add -t efi -s 50M -b 65536 da0

This is a larger offset for EDK2. But I do realize this is a partition offset, not filesystem (inside partition) offset.

I either write my own-use hack using gpart or learn to deal with makefs and what poudriere uses.

I really appreciate any guidance.
 
Mentally thinking this out.

Poudriere Image builds images for ESP, root1, root2, config, and data (optionally swap too)
So maybe I need to study the assembly process for the image. Add an offset there while combining these images.
Maybe after ${build_name}.raw disk image creation..

There is an option to add swap partiton to front of disk for expansion reasons.
Maybe I could abuse/repurpose that. Create and delete leaving freespace at front of disk structure..
 
There is an option to add swap partiton to front of disk for expansion reasons.
Maybe I could abuse/repurpose that. Create and delete leaving freespace at front of disk structure..
Exactly! That was my another idea: creating a partition of any type and then delete it.
 
Problem is with -t firmware style build it only puts swap next to last.
But with -t usb image it could work out.
Just reverse swap and efi and delete.

Code:
=>     34  8017920  md0  GPT  (3.8G)
       34    20480    1  efi  (10M)
    20514    36864    2  freebsd-swap  (18M)
    57378  7960576    3  freebsd-ufs  (3.8G)

Really hard time getting -w SWAPSIZE to work for me.
It will not take K as size (1600K)((as seen in code Kilobyte too small))
It fails at M as size (16m or 16M)
But G works....
poudriere image -t usb -s 4G -b -w 0.02G -j rockpi4 -p rockpi4_ports -h rockpi4-usb -n rockpi4 -f rockpi4-pkglist

Could this be a shell problem? What up? They do call it ALPHA since 2015+.
 
Houston we have ignition. I had to learn mkimg to fixxit.

Code:
/poudriere/data/images # gpart show md0
=>     34  7925726  md0  GPT  (3.8G)
       34    32734       - free -  (16M)
    32768   102400    1  efi  (50M)
   135168  3829760    2  freebsd-ufs  (1.8G)
  3964928  3829760    3  freebsd-ufs  (1.8G)
  7794688    65536    4  freebsd-ufs  (32M)
  7860224    65536    5  freebsd-ufs  (32M)


The key lays in /usr/local/share/poudriere/image_firmware.sh. Around Line 137
Code:
       espfilename=$(mktemp /tmp/efiboot.XXXXXX)
        make_esp_file ${espfilename} ${ESP_SIZE} ${WRKDIR}/world/boot/loader.efi
        mkimg -s gpt -C ${IMAGESIZE} -b ${mnt}/boot/pmbr \
                -p efi:=${espfilename} \
                -p freebsd-boot:=${mnt}/boot/gptboot \
                -p freebsd-ufs/${IMAGENAME}1:=${WRKDIR}/raw.img \
                -p freebsd-ufs/${IMAGENAME}2:=${WRKDIR}/raw.img \
                -p freebsd-ufs/cfg:=${WRKDIR}/cfg.img \
                ${SWAPFIRST} \
                -p freebsd-ufs/data:=${WRKDIR}/data.img \
                ${SWAPLAST} \
                -o "${OUTPUTDIR}/${FINALIMAGE}"
        rm -rf ${espfilename}
This section is the assembler. Takes all the images and combines them into final.

Ironically it uses mkimg and also has an offset option. partition offset to be exact.

I chose to modify for "EFI-only" and killed off gptboot/pmbr.
The key here is the partition offset.

Code:
espfilename=$(mktemp /tmp/efiboot.XXXXXX)
make_esp_file ${espfilename} ${ESP_SIZE} ${WRKDIR}/world/boot/loader.efi
mkimg -s gpt -C ${IMAGESIZE} \
        -p efi/efiboot0:=${espfilename}:16777216 \
        -p freebsd-ufs/${IMAGENAME}1:=${WRKDIR}/raw.img \
        -p freebsd-ufs/${IMAGENAME}2:=${WRKDIR}/raw.img \
        -p freebsd-ufs/cfg:=${WRKDIR}/cfg.img \
        ${SWAPFIRST} \
        -p freebsd-ufs/data:=${WRKDIR}/data.img \
        ${SWAPLAST} \
        -o "${OUTPUTDIR}/${FINALIMAGE}"
rm -rf ${espfilename}

I was having trouble with it running out of space(due to offset) so I modified this formula in build.

Code:
# Prune off a bit to fit the extra partitions and loaders
        OS_SIZE=$(( OS_SIZE - 1 - ESP_SIZE / 1 ))

This last part is hackish. I reduced it to /1 from /2 and it works. Basically cancelling itself out.

I am still having problems with offset (m,M) size. So I used no suffix to denote bytes of offset. 16777216
Also unsure if I needed relative or absolute. :+16777216
 
I made a variable to snazz it up.

Code:
# ESP_SIZE set the EFI system partition size in MB
ESP_SIZE=50

# Free Space before ESP for bootloader. Size in bytes. u-boot uses 16777216
BOOTLOADER_OFFSET=16777216

Code:
               -p efi/efiboot0:=${espfilename}:${BOOTLOADER_OFFSET} \

It works but does fail when set to zero. That would make it a nice feature. Maybe just comment out variable.

mkimg: writing metadata: Invalid argument
 
Back
Top