Bpi-r64 quick start (boot from eMMC)

i also have not got debian working on emmc so far…it’s a similar problem i faced above

I think we need some vendor-info why it does not work

@frank-w have you gone thru the emmc preloader above and the embedded atf and conpared them from a bin/he. Perspective to whats available publicly?

im about to dolve in if no one else has?

Also - i got past the LK ISSUE - i partitioned and imaged the exact same way u mentioned in another post regard sata boot and then used your preloader above, THEN redid the partition table only and it loaded the kernel - getting closer!

Sata-boot is for r2…

And no,have not byte compared…only lokked for offsets and compared with my infos (from vendor-script) but afair atf is different in the openwrt image here

Which partition-table do you use? Kernel loads? Uboot should be first,but i expect it does…

Please tell me your complete steps

@Frank I got it done - works perfectly. I’ll upload a complete & clean image inside of 48hrs.

They use a hybrid gpt partition table that accounts fot the LK and subsequent “TRUST” boot loaders.

You actually had the magic part all along. Here’s what to do

  1. Boot the r64 with any of the 3 linux sd imgs provided
  2. Write the complete emmc_singleimage.bin (top of the page open wrt) to the beginning of the disk. dd if=emmc_singleimage.bin of=/dev/mmcblk bs=512
  3. then (another one of your snippets)
parted -s /dev/mmcblk0 unit MiB mkpart primary fat32 -- 100MiB 356MiB
parted -s /dev/mmcblk0 unit MiB mkpart primary ext2 -- 356MiB 7295MiB
partprobe /dev/mmcblk0
mkfs.vfat /dev/mmcblk0p6 -I -n BPI-BOOT
mkfs.ext4 -O ^has_journal -E stride=2,stripe-width=1024 -b 4096 /dev/mmcblk0p7 -L BPI-ROOT
sync
  1. Then edit your /etc/fstab
/dev/mmcblk1p1 /boot vfat defaults,errors=remount-ro 0 0
/dev/mmcblk1p2 / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
tmpfs /tmp tmpfs defaults,nosuid 0 0
/dev/mmcblk0p6 /mnt/boot vfat defaults,errors=remount-ro,noauto 0 0
/dev/mmcblk0p7 /mnt/root ext4 defaults,noauto 0 1
  1. Manually mount and copy from the partitions on your SD card (these are your steps and i am thankful)
#unpack bootstrapped debian or copy full rootfs from sdcard

rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/boot/*"} / /mnt/root/

#copy kernel (p1) and modules (p2)

mkdir -p /mnt/emmc/boot/bananapi/bpi-r2/linux cp /boot/bananapi/bpi-r64/linux/uImage /mnt/emmc/boot/bananapi/bpi-r64/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/mmcblk1/mmcblk0/' /boot/bananapi/bpi-r64/linux/uEnv.txt > /mnt/boot/bananapi/bpi-r64/linux/uEnv.txt

as for the u-boot, atf, etc - follow the same directions as you mentioned at the top of this thread.

IMPORTANT MTK seems to pair their preloaders to the GPT table sigs which is directly linked to the access path for the LK, the stage two loader. The only reason i knew where to dig was that I’ve had to bring up several raw boards in a previous venture - and I was lucky enough to be given really great direction from qualcomm and others.

The reason it’s so tricky is in every image we’ve been provided, once it’s mounted, it has hides the parent GPT and only exposes the hybrid MBR table - but you don’t need an MBR table at all as described above

happy hunting and I’ll (or u if you beat me too it) will upload an image within a couple of days

I seriously could not have done it anywhere near this quickly without your help and incredibly detailed posts!

here is the final GPT table

root@bpi-iot-ros-ai:~# gdisk /dev/mmcblk0
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/mmcblk0: 15269888 sectors, 7.3 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9C040E2D-2415-47A1-9193-CB5BD2C34E82
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 15269854
Partitions will be aligned on 512-sector boundaries
Total free space is 490429 sectors (239.5 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            1024            1535   256.0 KiB   8300  tee1
   2            1536            2559   512.0 KiB   8300  lk
   3            2560            3583   512.0 KiB   8300  nvram
   4            3584            4095   256.0 KiB   8300  rf
   5            4096           45055   20.0 MiB    8300  boot
   6          204800          729087   256.0 MiB   0700  BPI-BOOT
   7          729088        14940159   6.8 GiB     8300  BPI-ROOT

-Jon

1 Like

We need mbr+gpt both for emmc? This differs from sdcard where only a mbr exists.maybe thats the cause i can’t get the partitiontable via sfdisk/sgdisk? But you can display it so it should be exportable too

Can you try get it working without the singleimage? So we know whats really needed…

@Frank it’s not the “singleimage” that matters at all. It’s the signature pairing between the LK (partition 2 above, the GPT table signature (the usually hidden one) and the preloader) - those three things are married - and for whatever reaso they were only used to create a LEDE image - i’m completely removed them from their existing containers and reimplemented the process - above are the individual steps - BUT

by lunch tomorrow i’ll have our internal image to flash directly which will require no additional effort (we image via pxe boot - thank you again for the netboot work)

And you don’t need any MBR at all. I will try and get an image up tomorrow for you guys - just getting my folks into production on a new device so time is sparse.

The way i’ve broken it apart - the images are all standalone now - i’ll @ u when i upload them

jon

1 Like

Is the gpt accessible from outside (e.g. losetup the img and run partprobe on loop-dev)?

On my gdrive i have already some parts collected like uboot-binaries (currently only rtl8367-switch),atf and a bootstrapped buster

https://drive.google.com/drive/u/0/mobile/folders/1WLWAR1FC-rF4n2SgFecBlU1ym_XKqAR_/15Y5Y3NAOwg_IMmN3k6hdb7pAQj9oTVTl/1SRUhYQqs5Jg_lKqgMfUlwSX4dG5T6qPZ?sort=13&direction=a

Maybe you can use it to create a clean system. Maybe you need to set rootpw via chroot before you can login

I hope i get a new r64 board soon to test my repos with mt7531- driver

Have now added also uboot-binaries for mt7531 and emmc…rtl8367+sd is working…the others i can’t test at the moment.

you can also send me the first x MB containing gpt+mbr, bootheaders +atf and uboot. then i can try to boot it on my board till uboot

@moore why did you use 2 cards? Isn’t that card able to simultaneously provide 2,4 and 5GHz as AP? Why you did not use this card from ASIARF? https://www.asiarf.com/shop/wifi-wlan/wifi_mini_pcie/wifi-mini-pcie-module-mtk-mt7615-4x4-11ac-5g-ws3294-manufacturer/? Do you know the difference between those two cards(ASIARF WS3294 and M27615-GAE)?

Two cards solution can have AC2600 (4x4ac + 4x4n) concurrent solution, but one card is dual-band only (work at 4x4ac or 4x4n only). In addition, this card is not standard mpcie size, so it’ll cause another pcie slot cannot plug other cards, thanks.

@moore thnx for clarification. Do you know, does other non standard mpcie size wifi card support concurrent wifi solution? And what about this card, do you know anything about it? https://www.aliexpress.com/item/32842242314.html?spm=a2g0o.cart.0.0.6e813c00kSgUC1&mp=1

As far as I know, only Mediatek MT7615D support dual band concurrent feature.i.e., 5Ghz 4x4ac or 2.4Ghz 4x4n => 5Ghz 2x2ac + 2.4Ghz 2x4n, but there is no standard mpcie size MT7615D card and mt76 mac80211 wifi driver cannot support dual-band concurrent mode at this moment.

@moore thnx for clarification, btw, this is a clear statement from asiaRF:

WS3294 each RF connector is with 2.4GHz and 5GHz traces out. MT7615-GAE is with only 2.4GHz out. MT7615-AAE is with only 5.GHz out.

Can you please discuss this in another (new) thread? This is about booting from emmc and not wifi-hardware :wink:

@jglanz i tried your way

first i see your working on mmcblk0 (it’s sd-card in my stretch-image, is it diffent in official-images?)

second after i flash the singleimage i see the special-partitions in gdisk:

root@bpi-r64:~# gdisk /dev/mmcblk1
GPT fdisk (gdisk) version 1.0.1

The protective MBR's 0xEE partition is oversized! Auto-repairing.

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/mmcblk1: 15269888 sectors, 7.3 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9C040E2D-2415-47A1-9193-CB5BD2C34E82
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 14609966
Partitions will be aligned on 512-sector boundaries
Total free space is 14565901 sectors (6.9 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            1024            1535   256.0 KiB   8300  tee1
   2            1536            2559   512.0 KiB   8300  lk
   3            2560            3583   512.0 KiB   8300  nvram
   4            3584            4095   256.0 KiB   8300  rf
   5            4096           45055   20.0 MiB    8300  boot

but i can’t add new partition with parted (btw. the commands are for R2)

root@bpi-r64:~# parted -s /dev/mmcblk1 unit MiB mkpart primary fat32 -- 100MiB 356MiB
Error: Both the primary and backup GPT tables are corrupt.  Try making a fresh table, and using Parted's rescue feature to recover partitions.

googled a bit around…as p(rint) looks ok, i tried v(eryfy), it shows this:

Command (? for help): v

Problem: The secondary header's self-pointer indicates that it doesn't reside
at the end of the disk. If you've added a disk to a RAID array, use the 'e'
option on the experts' menu to adjust the secondary header's and partition
table's locations.

Problem: GPT claims the disk is larger than it is! (Claimed last usable
sector is 14609966, but backup header is at
1 and disk size is 15269888 sectors.
The 'e' option on the experts' menu will probably fix this problem

Identified 2 problems!

then used w(rite) to write the partitiontable again and fix problems

Command (? for help): w
Warning! Secondary header is placed too early on the disk! Do you want to
correct this problem? (Y/N): y
Have moved second header and partition table to correct location.

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/mmcblk1.
[ 1348.931288]  mmcblk1: p1 p2 p3 p4 p5
The operation has completed successfully.

now i was able to create the partitions on emmc

root@bpi-r64:~# parted -s /dev/mmcblk1 unit MiB mkpart primary fat32 -- 100MiB 356MiB                                                                                                    
root@bpi-r64:~# parted -s /dev/mmcblk1 unit MiB mkpart primary ext2 -- 356MiB 7295MiB                                                                                                    
root@bpi-r64:~# 

till this point i see emmc-uboot, which i now try to reflash with my emmc/rtl8367-variant…works so far :wink: can i clean the openwrt-part anyhow? or can i export the partitiontable and ATF?

i expect that i can dd the first ~1.1MB (uboot is located at 768k and ~300kb in size) or 768k without uboot…atf is before this point (512kb), also the first 4 partitions (tee1,lk,nvram,rf). the 20MB boot-partiton overlaps uboot…maybe thats the cause i can’t mount it

have uploaded both to my gdrive…

https://drive.google.com/open?id=1SRUhYQqs5Jg_lKqgMfUlwSX4dG5T6qPZ

basicly r64_emmc_bootsect*.bin needs to be written to emmc (/dev/mmcblkX) and after reread partitiontable you need to create fs on BPI-BOOT (vfat) and BPI-ROOT

root@bpi-r64:~# partprobe /dev/mmcblk1
root@bpi-r64:~# apt install dosfstools
root@bpi-r64:~# mkfs.vfat /dev/mmcblk1p6 -I -n BPI-BOOT
root@bpi-r64:~# mkfs.ext4 -O ^has_journal -E stride=2,stripe-width=1024 -b 4096 /dev/mmcblk1p7 -L BPI-ROOT

i try to get kernel booted on my machine before create a basic image (without the openwrt-stuff which imho still lays somewhere on my emmc)…

can you tell me whats on the 20MB boot-partition? is this the openwrt-data? which filesystem is it? gdisk says it’s 8300=linux filesystem, but i cannot mount it without mount options

@frank-w the latest boards have mmcblk0 as the eMMC

I’m still prepping an image - you are on the correct track - I actually started using the preloader named forsdcard-0k

I’m pretty close - when I get it locked i’ll update everything - AND YES - u just need the openwrt partition table if you use the preloader u mentioned

@frank-w one more note - mmcblk0boot is where you write the preloader to on the new boards - ONE MORE update - sorry super busy and scatter brained today - you basically want to copy all of the vfat partition + 100MB from the SD - that will include, tee, lk, etc (I used the sector count method you explained in another post)

it’s depend on kernel…i use my own kernel where i swapped mmc to be same as official debian image and r2

preloader has to be written to boot0. with tee/lk,…you mean that i should copy the first 100MB? then i have also the openwrt-stuff still in…

what about boot-partition (is this needed)? if i copy all till there (first2M) i should have all stuff i need, right?

Hello! Could you explain how to not only build kernel BIN-file but also make IMG-file containing all necessary components as u-boot, preload, root.squashfs etc.? So this IMG-file could be written to the SD/MMC.

This topic is for emmc-boot…