en:bpi-r3:uboot
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
en:bpi-r3:uboot [2022/07/31 13:38] – [booting kernel] frank | en:bpi-r3:uboot [2023/04/07 13:45] – [writing emmc] frank | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== U-Boot ====== | ||
+ | [[https:// | ||
+ | |||
+ | Mtk uboot: https:// | ||
+ | |||
+ | Mtk atf: https:// | ||
+ | |||
+ | My uboot: https:// | ||
+ | ===== building ===== | ||
+ | |||
+ | Uboot needs to build into atf bl33. | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | So basicly do these in both branches (first uboot then atf) | ||
+ | |||
+ | ./build.sh importconfig | ||
+ | ./build.sh | ||
+ | |||
+ | Then flash build/ | ||
+ | |||
+ | sudo dd if=build/ | ||
+ | sudo dd if=build/ | ||
+ | |||
+ | ATF branch contains gpt file (gpt_sdmmc_100m6g.img) for flashing first and script to create basic image with bootchain | ||
+ | |||
+ | ./build.sh createimg | ||
+ | ===== booting kernel ===== | ||
+ | |||
+ | |||
+ | setenv kaddr 0x46000000 | ||
+ | ls mmc 0:5 | ||
+ | fatload mmc 0:5 ${kaddr} bpi-r3-5.19.0-rc1-r3.itb | ||
+ | #setenv bootargs " | ||
+ | bootm ${kaddr} | ||
+ | | ||
+ | board seems to hang in 5.19-rc1 when console=ttyS0 is passed | ||
+ | |||
+ | with my environment it is easy to boot kernel from usb | ||
+ | |||
+ | BPI-R3> usb start | ||
+ | BPI-R3> setenv device usb #was mmc before | ||
+ | BPI-R3> setenv partition 0:1 #was 0:5 before for mmc | ||
+ | BPI-R3> setenv fit bpi-r3-sfp.itb #change filename if needed | ||
+ | BPI-R3> run newboot #will load bpi-r3.itb | ||
+ | |||
+ | load fip with alternate dtb (like from my current 5.19-r3 branch, second config contains emmc dtb) | ||
+ | |||
+ | BPI-R3> fatload usb 0:1 $loadaddr bpi-r3.itb | ||
+ | 17032308 bytes read in 1427 ms (11.4 MiB/s) | ||
+ | BPI-R3> bootm ${loadaddr}# | ||
+ | |||
+ | load external initrd (run before "run newboot" | ||
+ | |||
+ | BPI-R3> setenv rdaddr 0x48000000 | ||
+ | BPI-R3> setenv root "/ | ||
+ | BPI-R3> setenv bootopts " | ||
+ | BPI-R3> fatload usb 0:1 ${rdaddr} rootfs.cpio.zst | ||
+ | |||
+ | |||
+ | latest uboot with usb, initrd and bootconf | ||
+ | |||
+ | BPI-R3> run useusb | ||
+ | BPI-R3> setenv initrd rootfs.cpio.zst | ||
+ | BPI-R3> setenv fit bpi-r3-sfp-no-rd.itb | ||
+ | BPI-R3> setenv bootconf "# | ||
+ | BPI-R3> run newboot | ||
+ | |||
+ | #using spi dt-overlay | ||
+ | BPI-R3> setenv bootconf "# | ||
+ | |||
+ | setenv buildargs ' | ||
+ | ===== bootmedium selection ===== | ||
+ | |||
+ | | | top || bottom | ||
+ | | |sw1/ | ||
+ | |spim-nor|low|low|low|x| | ||
+ | |spim-nand|high|low|high|x| | ||
+ | |emmc|low|high|x|low| | ||
+ | |sd|high|high|x|high| | ||
+ | |||
+ | To access emmc you need to go over spi-nand/ | ||
+ | |||
+ | Bootup with sdcard (put spi-nand bl2 + fip with emmc-and usb-support as files on card) and flash them like described [[# | ||
+ | ===== nand flash ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | < | ||
+ | BPI-R3> ls mmc 0:5 | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | 3 file(s), 0 dir(s) | ||
+ | |||
+ | BPI-R3> mtd list | ||
+ | List of MTD devices: | ||
+ | * spi-nand0 | ||
+ | - device: spi_nand@1 | ||
+ | - parent: spi@1100a000 | ||
+ | - driver: spi_nand | ||
+ | - path: / | ||
+ | - type: NAND flash | ||
+ | - block size: 0x20000 bytes | ||
+ | - min I/O: 0x800 bytes | ||
+ | - OOB size: 64 bytes | ||
+ | - OOB available: 24 bytes | ||
+ | - 0x000000000000-0x000008000000 : " | ||
+ | * nmbm0 | ||
+ | - type: Unknown | ||
+ | - block size: 0x20000 bytes | ||
+ | - min I/O: 0x800 bytes | ||
+ | - OOB size: 64 bytes | ||
+ | - OOB available: 24 bytes | ||
+ | - 0x000000000000-0x000007800000 : " | ||
+ | - 0x000000000000-0x000000100000 : " | ||
+ | - 0x000000100000-0x000000180000 : " | ||
+ | - 0x000000180000-0x000000380000 : " | ||
+ | - 0x000000380000-0x000000580000 : " | ||
+ | - 0x000000580000-0x000004580000 : " | ||
+ | |||
+ | BPI-R3> printenv loadaddr | ||
+ | loadaddr=0x46000000 | ||
+ | |||
+ | BPI-R3> mtd erase spi-nand0 | ||
+ | Erasing 0x00000000 ... 0x07ffffff (1024 eraseblock(s)) | ||
+ | BPI-R3> fatload mmc 0:5 $loadaddr bl2_nand.img | ||
+ | 217712 bytes read in 24 ms (8.7 MiB/s) | ||
+ | BPI-R3> mtd write spi-nand0 $loadaddr 0x0 0x100000 | ||
+ | Writing 1048576 byte(s) (512 page(s)) at offset 0x00000000 | ||
+ | |||
+ | BPI-R3> fatload mmc 0:5 $loadaddr fip_nand.bin | ||
+ | 579401 bytes read in 60 ms (9.2 MiB/s) | ||
+ | BPI-R3> mtd write spi-nand0 $loadaddr 0x380000 0x200000 | ||
+ | Writing 2097152 byte(s) (1024 page(s)) at offset 0x00380000 | ||
+ | </ | ||
+ | |||
+ | ===== nor flash ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | < | ||
+ | MT7986> sf probe | ||
+ | SF: Detected w25q256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB | ||
+ | MT7986> sf erase 0 0x180000 | ||
+ | SF: 1572864 bytes @ 0x0 Erased: OK | ||
+ | MT7986> fatload usb 0:1 ${loadaddr} 2023.04/ | ||
+ | 202160 bytes read in 21 ms (9.2 MiB/s) | ||
+ | MT7986> sf write ${loadaddr} 0 0x40000 | ||
+ | device 0 offset 0x0, size 0x40000 | ||
+ | SF: 262144 bytes @ 0x0 Written: OK | ||
+ | MT7986> fatload usb 0:1 ${loadaddr} 2023.04/ | ||
+ | 255509 bytes read in 25 ms (9.7 MiB/s) | ||
+ | MT7986> sf write ${loadaddr} 0x100000 0x80000 | ||
+ | device 0 offset 0x100000, size 0x80000 | ||
+ | SF: 524288 bytes @ 0x100000 Written: OK | ||
+ | </ | ||
+ | |||
+ | if you get this error on bootup | ||
+ | |||
+ | NOTICE: | ||
+ | No valid device tree binary found at 0000000041e92f20 | ||
+ | initcall sequence 0000000041e621a8 failed at call 0000000041e57800 (err=-2) | ||
+ | ### ERROR ### Please RESET the board ### | ||
+ | |||
+ | you need to compress bl31 | ||
+ | |||
+ | xz -f -e -k -9 -C crc32 u-boot.bin | ||
+ | |||
+ | and use the resulting u-boot.bin.xz as BL33 | ||
+ | |||
+ | ==== kernel/ | ||
+ | |||
+ | currently untested... | ||
+ | |||
+ | < | ||
+ | label = " | ||
+ | reg = < | ||
+ | |||
+ | label = " | ||
+ | reg = < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | MT7986> sf probe | ||
+ | SF: Detected w25q256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB | ||
+ | MT7986> sf erase 0x180000 0xa80000 | ||
+ | SF: 11010048 bytes @ 0x180000 Erased: OK | ||
+ | MT7986> fatload usb 0:1 ${loadaddr} rootfs_bpi-r3.cpio.zst | ||
+ | 9501203 bytes read in 798 ms (11.4 MiB/s) | ||
+ | MT7986> sf write ${loadaddr} 0x180000 ${filesize} | ||
+ | device 0 offset 0x180000, size 0x90fa13 | ||
+ | SF: 9501203 bytes @ 0x180000 Written: OK | ||
+ | MT7986> sf erase 0xc00000 0x1400000 | ||
+ | SF: 20971520 bytes @ 0xc00000 Erased: OK | ||
+ | MT7986> fatload usb 0:1 ${loadaddr} bpi-r3-6.1.itb | ||
+ | 8424540 bytes read in 708 ms (11.3 MiB/s) | ||
+ | MT7986> sf write ${loadaddr} 0xc00000 ${filesize} | ||
+ | device 0 offset 0xc00000, size 0x808c5c | ||
+ | SF: 8424540 bytes @ 0xc00000 Written: OK | ||
+ | </ | ||
+ | |||
+ | loading it: | ||
+ | |||
+ | < | ||
+ | MT7986> setenv useinitrd ' | ||
+ | MT7986> sf read ${rdaddr} 0x180000 0xa80000 | ||
+ | device 0 offset 0x180000, size 0xa80000 | ||
+ | SF: 11010048 bytes @ 0x180000 Read: OK | ||
+ | MT7986> sf read ${kaddr} 0xc00000 0x1400000 | ||
+ | device 0 offset 0xc00000, size 0x1400000 | ||
+ | SF: 20971520 bytes @ 0xc00000 Read: OK | ||
+ | MT7986> setenv bootnor 'run useinitrd; | ||
+ | MT7986> run bootnor | ||
+ | </ | ||
+ | ===== usb ===== | ||
+ | |||
+ | < | ||
+ | BPI-R3> usb start | ||
+ | starting USB... | ||
+ | Bus xhci@11200000: | ||
+ | xhci-mtk xhci@11200000: | ||
+ | xhci-mtk xhci@11200000: | ||
+ | Register 300010f NbrPorts 3 | ||
+ | Starting the controller | ||
+ | USB XHCI 1.10 | ||
+ | scanning bus xhci@11200000 for devices... 3 USB Device(s) found | ||
+ | | ||
+ | BPI-R3> ls usb 0:1 | ||
+ | efi/ | ||
+ | 1023582 | ||
+ | 1365903 | ||
+ | 2956137 | ||
+ | | ||
+ | 4767728 | ||
+ | |||
+ | 5 file(s), 1 dir(s) | ||
+ | |||
+ | BPI-R3> | ||
+ | </ | ||
+ | |||
+ | from testing usb-sockets near gpio-header (connected to an usb2-hub): | ||
+ | |||
+ | < | ||
+ | BPI-R3> usb tree | ||
+ | USB device tree: | ||
+ | 1 Hub (5 Gb/s, 0mA) | ||
+ | | U-Boot XHCI Host Controller | ||
+ | | | ||
+ | +-2 Hub (480 Mb/s, 100mA) | ||
+ | | USB 2.0 Hub | ||
+ | | | ||
+ | +-3 Mass Storage (480 Mb/s, 200mA) | ||
+ | | ||
+ | </ | ||
+ | ===== writing emmc ===== | ||
+ | |||
+ | get emmc/gpt information: | ||
+ | < | ||
+ | < | ||
+ | BPI-R3> mmc info | ||
+ | Device: mmc@11230000 | ||
+ | Manufacturer ID: 11 | ||
+ | OEM: 0 | ||
+ | Name: 008GB0 | ||
+ | Bus Speed: 52000000 | ||
+ | Mode: MMC High Speed (52MHz) | ||
+ | Rd Block Len: 512 | ||
+ | MMC version 5.1 | ||
+ | High Capacity: Yes | ||
+ | Capacity: 7.3 GiB | ||
+ | Bus Width: 8-bit | ||
+ | Erase Group Size: 512 KiB | ||
+ | HC WP Group Size: 4 MiB | ||
+ | User Capacity: 7.3 GiB WRREL | ||
+ | Boot Capacity: 4 MiB ENH | ||
+ | RPMB Capacity: 4 MiB ENH | ||
+ | Boot area 0 is not write protected | ||
+ | Boot area 1 is not write protected | ||
+ | |||
+ | BPI-R3> gpt read mmc 0 | ||
+ | Partition 1: | ||
+ | Start 0MiB, size 0MiB | ||
+ | Block size 512, name gpt | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID df7a38f6-9df4-11ec-a1e0-1c1b0d6d28f5 | ||
+ | |||
+ | Partition 2: | ||
+ | Start 4MiB, size 0MiB | ||
+ | Block size 512, name u-boot-env | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 19a4763a-6b19-4a4b-a0c4-8cc34f4c2ab9 | ||
+ | |||
+ | Partition 3: | ||
+ | Start 4MiB, size 2MiB | ||
+ | Block size 512, name factory | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 8142c1b2-1697-41d9-b1bf-a88d76c7213f | ||
+ | |||
+ | Partition 4: | ||
+ | Start 6MiB, size 2MiB | ||
+ | Block size 512, name fip | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 18de6587-4f17-4e08-a6c9-d9d3d424f4c5 | ||
+ | |||
+ | Partition 5: | ||
+ | Start 8MiB, size 32MiB | ||
+ | Block size 512, name kernel | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 971f7556-ef1a-44cd-8b28-0cf8100b9c7e | ||
+ | |||
+ | Partition 6: | ||
+ | Start 40MiB, size 256MiB | ||
+ | Block size 512, name rootfs | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 309a3e76-270b-41b2-b5d5-ed8154e7542b | ||
+ | |||
+ | success! | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | load gpt file and flash it | ||
+ | < | ||
+ | BPI-R3> usb start | ||
+ | starting USB... | ||
+ | Bus xhci@11200000: | ||
+ | xhci-mtk xhci@11200000: | ||
+ | xhci-mtk xhci@11200000: | ||
+ | Register 300010f NbrPorts 3 | ||
+ | Starting the controller | ||
+ | USB XHCI 1.10 | ||
+ | scanning bus xhci@11200000 for devices... 3 USB Device(s) found | ||
+ | | ||
+ | BPI-R3> ls usb 0:1 | ||
+ | efi/ | ||
+ | 1365903 | ||
+ | 2956137 | ||
+ | 4767728 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 17408 | ||
+ | | ||
+ | | ||
+ | |||
+ | 11 file(s), 1 dir(s) | ||
+ | |||
+ | BPI-R3> fatload usb 0:1 $loadaddr gpt_emmc_100m6g.img | ||
+ | 17408 bytes read in 4 ms (4.2 MiB/s) | ||
+ | BPI-R3> mmc erase 0x0 0x400;mmc write ${loadaddr} 0x0 0x400 | ||
+ | |||
+ | MMC erase: dev # 0, block # 0, count 1024 ... 1024 blocks erased: OK | ||
+ | |||
+ | MMC write: dev # 0, block # 0, count 1024 ... 1024 blocks written: OK | ||
+ | </ | ||
+ | verify gpt is changed (kernel is now 100MiB - 32 before, rootfs 6144MiB - 256 before): | ||
+ | < | ||
+ | < | ||
+ | BPI-R3> gpt read mmc 0 | ||
+ | Partition 1: | ||
+ | Start 0MiB, size 0MiB | ||
+ | Block size 512, name gpt | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 4a32da88-f334-11ec-94f0-112beaedcdcb | ||
+ | |||
+ | Partition 2: | ||
+ | Start 4MiB, size 0MiB | ||
+ | Block size 512, name u-boot-env | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 19a4763a-6b19-4a4b-a0c4-8cc34f4c2ab9 | ||
+ | |||
+ | Partition 3: | ||
+ | Start 4MiB, size 2MiB | ||
+ | Block size 512, name factory | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 8142c1b2-1697-41d9-b1bf-a88d76c7213f | ||
+ | |||
+ | Partition 4: | ||
+ | Start 6MiB, size 2MiB | ||
+ | Block size 512, name fip | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 18de6587-4f17-4e08-a6c9-d9d3d424f4c5 | ||
+ | |||
+ | Partition 5: | ||
+ | Start 8MiB, size 100MiB | ||
+ | Block size 512, name kernel | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 971f7556-ef1a-44cd-8b28-0cf8100b9c7e | ||
+ | |||
+ | Partition 6: | ||
+ | Start 108MiB, size 6144MiB | ||
+ | Block size 512, name rootfs | ||
+ | Type U-Boot, bootable 0 | ||
+ | UUID 309a3e76-270b-41b2-b5d5-ed8154e7542b | ||
+ | |||
+ | success! | ||
+ | BPI-R3> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | now flash bl2 to boot0 block and fip to fip partition | ||
+ | |||
+ | short way using my environment: | ||
+ | < | ||
+ | MT7986> setenv bl2file 2023.04/ | ||
+ | MT7986> setenv fipfile 2023.04/ | ||
+ | MT7986> run wremmc | ||
+ | bl2file=2023.04/ | ||
+ | 195976 bytes read in 20 ms (9.3 MiB/ | ||
+ | | ||
+ | MMC erase: dev # 0, block # 0, count 1024 ... 1024 blocks erased: OK | ||
+ | | ||
+ | MMC write: dev # 0, block # 0, count 1024 ... 1024 blocks written: OK | ||
+ | fipfile=2023.04/ | ||
+ | 645001 bytes read in 58 ms (10.6 MiB/ | ||
+ | | ||
+ | MMC erase: dev # 0, block # 13312, count 4096 ... 4096 blocks erased: OK | ||
+ | | ||
+ | MMC write: dev # 0, block # 13312, count 4096 ... 4096 blocks written: OK | ||
+ | </ | ||
+ | manual way: | ||
+ | < | ||
+ | < | ||
+ | BPI-R3> mmc dev 0 | ||
+ | switch to partitions #0, OK | ||
+ | mmc0(part 0) is current device | ||
+ | #switch to boot0 block | ||
+ | BPI-R3> mmc partconf 0 1 1 1 | ||
+ | BPI-R3> mmc erase 0x0 0x400 | ||
+ | BPI-R3> fatload usb 0:1 $loadaddr bl2_emmc_usb.img | ||
+ | 200072 bytes read in 19 ms (10 MiB/s) | ||
+ | BPI-R3> mmc write ${loadaddr} 0x0 0x400 | ||
+ | |||
+ | MMC write: dev # 0, block # 0, count 1024 ... 1024 blocks written: OK | ||
+ | #switch back to user-partition | ||
+ | BPI-R3> mmc partconf 0 1 1 0 | ||
+ | |||
+ | #fip partition starts at blockoffset 0x3400 (start-value from json 13312 in hex) | ||
+ | BPI-R3> mmc erase 0x3400 0x1000 | ||
+ | |||
+ | MMC erase: dev # 0, block # 13312, count 4096 ... 4096 blocks erased: OK | ||
+ | BPI-R3> fatload usb 0:1 $loadaddr fip_emmc_usb.bin | ||
+ | 634345 bytes read in 55 ms (11 MiB/s) | ||
+ | BPI-R3> mmc write ${loadaddr} 0x3400 0x1000 | ||
+ | |||
+ | MMC write: dev # 0, block # 13312, count 4096 ... 4096 blocks written: OK | ||
+ | BPI-R3> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | If boot from emmc does not work,maybe bootbus needs to be changed to 0: | ||
+ | |||
+ | mmc bootbus 0 0 0 0 | ||
+ | |||
+ | |||
+ | instead of writing the gpt image file you can bootup a linux with initrd | ||
+ | |||
+ | you get all files here: https:// | ||
+ | |||
+ | BPI-R3> run useusb | ||
+ | BPI-R3> setenv initrd rootfs.cpio.zst | ||
+ | BPI-R3> setenv fit bpi-r3.itb | ||
+ | BPI-R3> run newboot | ||
+ | |||
+ | and create gpt like i do it for [[https:// | ||
+ | |||
+ | < | ||
+ | sudo sgdisk -o ${LDEV} | ||
+ | #sudo sgdisk -a 1 -n 1:34:8191 -A 1:set:2 -t 1:8300 -c 1:" | ||
+ | sudo sgdisk -a 1 -n 1:0:33 -A 1:set:2 -t 1:8300 -c 1:" | ||
+ | sudo sgdisk -a 1 -n 2: | ||
+ | sudo sgdisk -a 1 -n 3: | ||
+ | sudo sgdisk -a 1 -n 4: | ||
+ | sudo sgdisk -a 1024 -n 5: | ||
+ | sudo sgdisk -a 1024 -n 6: | ||
+ | </ | ||
+ | ===== chainload uboot ===== | ||
+ | |||
+ | u-boot.bin (without mtk header and not fip) can be chainloaded from another | ||
+ | uboot for testing uboot-features without flashing | ||
+ | |||
+ | < | ||
+ | BPI-R3> fatload usb 0:1 $loadaddr uboot_emmc_usb.bin | ||
+ | 601344 bytes read in 52 ms (11 MiB/s) | ||
+ | BPI-R3> go $loadaddr | ||
+ | ## Starting application at 0x46000000 ... | ||
+ | |||
+ | U-Boot 2022.04-00557-g726479add2f1 (Jul 05 2022 - 18:14:31 +0200) | ||
+ | </ |
en/bpi-r3/uboot.txt · Last modified: 2024/04/07 09:39 by frank