User Tools

Site Tools

Translations of this page:
en

en:bpi-r2:storage

Storage

image by garywang

it looks like /dev/mmcblk1, /dev/mmcblk1boot0 and /dev/mmcblk1boot1 are independend devices (bootx not partitions inside /dev/mmcblk1)

SD-Card

1. download binary files:

2. Create image file (8GB):

dd if=/dev/zero bs=1M count=7296 | pv | dd of=bpir2.img

3. Load image as virtual drive:

losetup /dev/loop8 bpir2.img

4. Make partitions and format:

parted -s /dev/loop8 mklabel msdos
parted -s /dev/loop8 unit MiB mkpart primary fat32 -- 100MiB 356MiB
parted -s /dev/loop8 unit MiB mkpart primary ext2 -- 356MiB 7295MiB
partprobe /dev/loop8
mkfs.vfat /dev/loop8p1 -I -n BPI-BOOT
mkfs.ext4 -O ^has_journal -E stride=2,stripe-width=1024 -b 4096 /dev/loop8p2 -L BPI-ROOT
sync
parted -s /dev/loop8 print

5. extended boot-headers

  • SDMMC_BOOT-signature + address of 2nd header 0x00000200 (before partition-table):
gunzip -c BPI-R2-HEAD440-0k.img.gz | dd of=/dev/loop8 bs=1024 seek=0
  • BRLYT-signature + preloader-address (0x00000800):
gunzip -c BPI-R2-HEAD1-512b.img.gz | dd of=/dev/loop8 bs=512 seek=1

6. Write preloader and u-boot bootloader:

dd if=preloader_iotg7623Np1_sd_1600M.bin of=/dev/loop8 bs=1024 seek=2
dd if=u-boot.bin of=/dev/loop8 bs=1024 seek=320
sync

7. Copy rootfs + kernel

create bootstraped rootfs

Install Kernel:

Kernel

8. Remove loop device:

losetup -d /dev/loop8

MMC-Utils

with the mmc-utils you can test out of a running system, if the EMMC-partitioning is correct (should be 48 see change_partition-configuration_of_emmc).

./mmc extcsd read /dev/mmcblk1
....
Boot configuration bytes [PARTITION_CONFIG: 0x48]
....

i have added the mmc-utils also to my Kernel-Repo (with changed Makefile for Cross-Compile)

a forum user give me the tip here that partition config can be wrote with mmc-utils too

./mmc bootpart enable 1 1 /dev/mmcblk1
[18:02] root@bpi-r2:~# ./mmc extcsd read /dev/mmcblk1 | grep PARTITION_CONFIG
Boot configuration bytes [PARTITION_CONFIG: 0x00]
[18:02] root@bpi-r2:~# ./mmc bootpart enable 1 1 /dev/mmcblk1
[18:03] root@bpi-r2:~# ./mmc extcsd read /dev/mmcblk1 | grep PARTITION_CONFIG
Boot configuration bytes [PARTITION_CONFIG: 0x48]

install OS on EMMC

http://forum.banana-pi.org/t/bpi-r2-new-image-ubuntu-16-04-v1-2-1-bt-and-wifi-ap-mode-are-working-fine-2017-11-27/4291

  1. activate write mode /dev/mmcblk1boot0:
    echo 0 > /sys/block/mmcblk1boot0/force_ro
  2. write preloader from here to the emmc boot-device:
    • gunzip -c BPI-R2-EMMC-boot0-DDR1600-0k-0905.img.gz | sudo dd of=/dev/mmcblk1boot0 bs=1024 seek=0
    • with bpi-tools:
      bpi-bootsel BPI-R2-EMMC-boot0-DDR1600-0k-0905.img.gz /dev/mmcblk1boot0
  3. copy of OS-image to EMMC (device=/dev/mmcblk1):
    • gunzip deb_stretch_emmc.img.gz
      dd if=deb_stretch_emmc.img of=/dev/mmcblk1 bs=1M
    • unzip -p <XXX.img.zip> | pv | dd of=<device> bs=10M status=noxfer
    • alternate (with bpi-tools):
      bpi-copy  <XXX.img.zip> <device>
  4. poweroff, remove SD card and boot again

if sd-card-image does not fit emmc: shrinking image

manual copy of OS

  • if you want bootable sdcard,you need to copy first 2k from existing sd-image/card.
    • first 2kB without preloader/uboot first MB with preloader/uboot
      gunzip bpi-r2-sd-boot*.img.gz
      dd if=bpi-r2-sd-boot1m.img of=/dev/sdx
      sync
      #remove card after "sync" and reenter
      sudo mkfs -t vfat /dev/sdx1
      sudo mkfs -t ext4 /dev/sdx2
      #set filesystem-labels, partition must not be mounted!
      sudo mlabel -i /dev/sdx1 ::BPI-BOOT
      sudo tune2fs -L BPI-ROOT /dev/sdx2
  • install uboot (not needed if bpi-r2-sd-boot1m.img is flashed):
    dd if=BPI-R2-720P-2k.img of=/dev/mmcblk1 bs=1k seek=2 count=1022
  • export partitiontable from SD parttable.dat and write it to emmc (not needed if bpi-r2-sd-bootx.img is flashed):
    root@bpi-r2:~# sfdisk -d /dev/mmcblk0 > parttable.dat
    root@bpi-r2:~# sfdisk /dev/mmcblk1 < parttable.dat
  • check/resize
  • create filesystems (mkfs) for p1=vfat (apt-get install dosfstools) and p2=ext4 (here emmc)
    mkfs -t vfat /dev/mmcblk1p1
    mkfs -t ext4 /dev/mmcblk1p2
  • create+configure mount-points in existing system
    mkdir -p /mnt/emmc/boot
    mkdir -p /mnt/emmc/root
    nano /etc/fstab
    # <file system>         <dir>           <type>  <options>               <dump>  <pass>
    /dev/mmcblk0p2          /               ext4    errors=remount-ro       0       1
    /dev/mmcblk0p1          /boot           vfat    defaults                0       0
    /dev/mmcblk1p2          /mnt/emmc/root  ext4    errors=remount-ro,noauto  0       1
    /dev/mmcblk1p1          /mnt/emmc/boot  vfat    defaults,noauto           0       0
  • mount it:
    mount /mnt/emmc/root
    mount /mnt/emmc/boot
  • unpack bootstrapped debian or copy full rootfs from sdcard
    rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/boot/*"} / /mnt/emmc/root/
  • copy kernel (p1) and modules (p2)
    mkdir -p /mnt/emmc/boot/bananapi/bpi-r2/linux
    cp /boot/bananapi/bpi-r2/linux/uImage /mnt/emmc/boot/bananapi/bpi-r2/linux
    mkdir -p /mnt/emmc/root/lib/modules/
    cp -r /lib/modules/$(uname -r) /mnt/emmc/root/lib/modules/
  • configure uboot to load kernel from right partition
    sed 's/mmcblk0/mmcblk1/' /boot/bananapi/bpi-r2/linux/uEnv.txt > /mnt/emmc/boot/bananapi/bpi-r2/linux/uEnv.txt

Discussion

en/bpi-r2/storage.txt · Last modified: 2018/11/03 10:04 by frank