Solved u-boot flash with dd

I have built u-boot for several platforms and when I flashed u-boot to the disk it never acted up.

But on RockPro64 I have a problem building my own image. The default FreeBSD 13.1 image works fine.
U-boot README package instructions:
Code:
To install this bootloader on an sdcard just do:
dd if=/usr/local/share/u-boot/u-boot-rockpro64/idbloader.img of=/path/to/sdcarddevice seek=64 bs=512 conv=sync
dd if=/usr/local/share/u-boot/u-boot-rockpro64/u-boot.itb of=/path/to/sdcarddevice seek=16384 bs=512 conv=sync

It seems the disk get corrupted when I write this to an existing microsd disk with an existing disk scheme.

If I write u-boot first then create scheme and partition the disk needs fscking.
Code:
CYLINDER GROUP 95: INTEGRITY CHECK FAILED
UNEXPECTED SOFT UPDATE INCONSISTENCY

REBUILD CYLINDER GROUP? yes

CYLINDER GROUP 96: INTEGRITY CHECK FAILED
UNEXPECTED SOFT UPDATE INCONSISTENCY

REBUILD CYLINDER GROUP? yes

CYLINDER GROUP 97: INTEGRITY CHECK FAILED
UNEXPECTED SOFT UPDATE INCONSISTENCY

REBUILD CYLINDER GROUP? yes

^C
root@rockpro64:~ #
***** FILE SYSTEM MARKED DIRTY *****

This may be a result of me using a tiny 256MB microsd card? I figured u-boot and EFI would be fine.

I don't understand the flashing regime.

So 'seek=' is where to begin writing on the disk with dd? That is in bytes?
What is the bs=512 doing here? Setting the sector size?

When should I be flashing u-boot? Before creating my disk scheme or after?

On my i-MX6 u-boot I never had a problem but the flasher looks different.
Code:
dd if=u-boot.imx of=/dev/whatever bs=1k oseek=1 conv=sync
Why are they using oseek instead?
 

Why are they using oseek instead?
Read the dd() manual page.
"seek" and "oseek" are the same options.

dd if=u-boot.imx of=/dev/whatever bs=1k oseek=1 conv=sync
This one writes content of u-boot.imx after the first 1k (1024 byte) block of output device.

dd if=/usr/local/share/u-boot/u-boot-rockpro64/idbloader.img of=/path/to/sdcarddevice seek=64 bs=512 conv=sync
dd if=/usr/local/share/u-boot/u-boot-rockpro64/u-boot.itb of=/path/to/sdcarddevice seek=16384 bs=512 conv=sync
First line writes content of idbloader.img after 64 sectors (512-byte blocks) of output device.
Second line u-boot.itb after 16384 sectors (512-byte blocks) of output device.

It seems the disk get corrupted when I write this to an existing microsd disk with an existing disk scheme.
Two dd's writes on destination disk and do not consider any existing partitions.
Check your manual, maybe you have skipped some step like MBR creation or writting with dd 1st sector of a target device.

So 'seek=' is where to begin writing on the disk with dd? That is in bytes?
What is the bs=512 doing here? Setting the sector size?
bs is a blocksize, bs=512 sets block size equal to size of physical sector on most legacy disks.
If you want to calculate offset in bytes then just multiple "bs*seek".

If you want to understand how dd works - you can use a file instead of a real output device.
You can write with dd() some data to a file, and examine a result via hd() utility or via mcview() in hex-mode(F4-key).
Use a simple text files filled by some character as a playground.
Code:
dd if=/dev/zero of=zero-file bs=1k count=100
dd if=/dev/random of=random bs=512 count=1
dd if=random of=zero-file oseek=1 bs=512 conv=sync,notrunc
hd zero-file | less
hd random | less
 
I don't understand the flashing regime.

So 'seek=' is where to begin writing on the disk with dd? That is in bytes?
What is the bs=512 doing here? Setting the sector size?

When should I be flashing u-boot? Before creating my disk scheme or after?

On my i-MX6 u-boot I never had a problem but the flasher looks different.
Code:
dd if=u-boot.imx of=/dev/whatever bs=1k oseek=1 conv=sync
Why are they using oseek instead?
dd() man page
Code:
     bs=n     Set both input and output    block size to n    bytes
     seek=n   Seek n blocks from the beginning of the output before copying.
     oseek=n  Seek on the output file n    blocks.     This is synonymous with
          seek=n.

u-boot offsets are HW platform specific.
For RK3399 you need to leave first 16 MB to u-boot, ie your first partition should start after 16 MB
 
OK by studying the FreeBSD 13-1-RELEASE image for RockPro64 I see the 16MB offset.
So I need to start my EFI partition with the 16MB offset. Then UFS will fall in line.
So can I use my dd byte number for the offset?
gpart add -b 16384 -s 512 -t efi da0
Is default GPT Partition table location fine? Just adjust the first partition?

Code:
# gpart show md0
=>     40  6291376  md0  GPT  (3.0G)
       40    32728       - free -  (16M)
    32768   102400    1  efi  (50M)
   135168  6156160    2  freebsd-ufs  (2.9G)
  6291328       88       - free -  (44K)
Maybe this is what I need?
gpart add -b 32768 -s 50M -t efi da0
 
Question. Does the GPT Partition table(primary) reside in the first 40 bytes that appears unallocated above?
I am trying to figure out this stuff.
 
That did the trick. I have working u-boot with an EFI partition on a 256MB SLC microSD.
Thank You.
Now onto nvme as root device.
 
Back
Top