环境
- PC Win11平台
- Ubuntu18.04(官方网盘下载)
- 2K0300蜂鸟板
系统编译
系统编译,主要参考《广东龙芯2K0300蜂鸟板快速使用指南-v1.0.240725》的第三、第四、第五章进行
1 编译uboot
更新
loongson@loongson-virtual-machine:~/workspace/u-boot$ git
pull
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 7), reused 0 (delta 0), pack-reused 0
展开对象中: 100% (8/8), 完成.
来自
https://gitee.com/open-loongarch/u-boot
1d58dfa0..79bfe1cf master -> origin/master
更新 1d58dfa0..79bfe1cf
Fast-forward
configs/loongson_2k300_mini_dp_defconfig | 2
+-
configs/loongson_2k300_pai_defconfig | 2 +-
include/configs/loongson_common.h | 4 +++-
3 files changed, 5
insertions(+), 3 deletions(-)
交叉编译
loongson@loongson-virtual-machine:~/workspace/u-boot$ source
set_env.sh
====>setup env for LoongArch...
编译
loongson@loongson-virtual-machine:~/workspace/u-boot$ make
loongson_2k300_mini_dp_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
YACC scripts/kconfig/zconf.tab.c
LEX scripts/kconfig/zconf.lex.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
configuration written to .config
loongson@loongson-virtual-machine:~/workspace/u-boot$ make
scripts/kconfig/conf
--syncconfig Kconfig
UPD include/config.h
………………………
OBJCOPY spl/u-boot-spl-nodtb.bin
mkdir -p spl/dts/
FDTGREP
spl/dts/dt-spl.dtb
COPY spl/u-boot-spl.dtb
CAT spl/u-boot-spl-dtb.bin
COPY spl/u-boot-spl.bin
SYM spl/u-boot-spl.sym
MKIMAGE u-boot.img
COPY u-boot.dtb
MKIMAGE
u-boot-dtb.img
CAT u-boot-with-spl.bin
CFGCHK u-boot.cfg
OFCHK .config
2 编译kernel
更新
loongson@loongson-virtual-machine:~/workspace/linux-5.10$
git pull
remote: Enumerating objects: 367, done.
remote: Counting objects: 100% (367/367), done.
remote: Compressing objects: 100% (266/266), done.
remote: Total 354 (delta 84), reused 354 (delta 84),
pack-reused 0
接收对象中: 100% (354/354), 1.78 MiB |
728.00 KiB/s, 完成.
处理 delta 中:
100% (84/84), 完成 11 个本地对象.
来自
https:
8df076d8d..79c459850 master -> origin/master
更新 8df076d8d..79c459850
Fast-forward
.../loongarch/boot/dts/loongson/loongson2k300.dtsi
| 1 +
arch/loongarch/configs/loongson_2k300_defconfig |
2 +
drivers/staging/Kconfig | 2 +
drivers/staging/Makefile | 1 +
drivers/staging/rtl8188fu/.gitignore | 8 +
drivers/staging/rtl8188fu/Kconfig | 10 +
drivers/staging/rtl8188fu/LICENSE | 339 +
drivers/staging/rtl8188fu/Makefile | 463 +
……………………….
create mode 100644
drivers/staging/rtl8188fu/os_dep/linux/rtw_proc.h
create mode 100644
drivers/staging/rtl8188fu/os_dep/linux/usb_intf.c
create mode 100644
drivers/staging/rtl8188fu/os_dep/linux/usb_ops_linux.c
create mode 100644
drivers/staging/rtl8188fu/os_dep/linux/wifi_regd.c
create mode 100644
drivers/staging/rtl8188fu/os_dep/linux/xmit_linux.c
create mode 100644
drivers/staging/rtl8188fu/os_dep/osdep_service.c
交叉编译
loongson@loongson-virtual-machine:~/workspace/linux-5.10$
source set_env.sh
====>setup env for LoongArch...
编译
loongson@loongson-virtual-machine:~/workspace/linux-5.10$
make loongson_2k300_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/confdata.o
HOSTCC scripts/kconfig/expr.o
LEX scripts/kconfig/lexer.lex.c
YACC scripts/kconfig/parser.tab.[ch]
HOSTCC scripts/kconfig/lexer.lex.o
HOSTCC scripts/kconfig/parser.tab.o
HOSTCC scripts/kconfig/preprocess.o
HOSTCC scripts/kconfig/symbol.o
HOSTCC scripts/kconfig/util.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
loongson@loongson-virtual-machine:~/workspace/linux-5.10$ make
uImage
HOSTCC arch/loongarch/tools/elf-entry
HOSTCC arch/loongarch/boot/tools/relocs_32.o
HOSTCC arch/loongarch/boot/tools/relocs_64.o
HOSTCC arch/loongarch/boot/tools/relocs_main.o
………
LD vmlinux
SORTTAB vmlinux
SYSMAP System.map
OBJCOPY
arch/loongarch/boot/vmlinux.bin
GZIP arch/loongarch/boot/vmlinux.bin.gz
UIMAGE arch/loongarch/boot/uImage.gz
Image Name: Linux-5.10.0.lsgd-g79c459850596
Created: Sat Aug
10 14:44:20 2024
Image Type:
LoongArch Linux Kernel Image (gzip compressed)
Data Size: 8829913
Bytes = 8622.96 KiB = 8.42 MiB
Load Address: 00200000
Entry Point: 00e263f0
Image
arch/loongarch/boot/uImage is ready
3 编译buildroot
更新
loongson@loongson-virtual-machine:~/workspace/buildroot$ git
pull
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
展开对象中: 100% (3/3), 完成.
来自
https://gitee.com/open-loongarch/buildroot
bd3c07dc..f2002b9e master -> origin/master
更新 bd3c07dc..f2002b9e
Fast-forward
buildroot-2021.02/.gitignore => .gitignore
| 0
1 file changed, 0
insertions(+), 0 deletions(-)
rename
buildroot-2021.02/.gitignore => .gitignore (100%)
交叉编译
配置在工程文件中,可以使用make menuconfig修改,这里使用默认值,不做修改
编译
loongson@loongson-virtual-machine:~/workspace/buildroot$
make loongson2k300_mini_dp_defconfig
mkdir -p /home/loongson/workspace/buildroot/output/build/buildroot-config/lxdialog
PKG_CONFIG_PATH="" make
CC="/usr/bin/gcc" HOSTCC="/usr/bin/gcc" \\
obj=/home/loongson/workspace/buildroot/output/build/buildroot-config -C
support/kconfig -f Makefile.br conf
make[1]: 进入目录“/home/loongson/workspace/buildroot/support/kconfig”
/usr/bin/gcc -DCURSES_LOC=""
-DLOCALE
-I/home/loongson/workspace/buildroot/output/build/buildroot-config
-DCONFIG_=\\"\\" -MM *.c >
/home/loongson/workspace/buildroot/output/build/buildroot-config/.depend
2>/dev/null || :
/usr/bin/gcc -DCURSES_LOC=""
-DLOCALE
-I/home/loongson/workspace/buildroot/output/build/buildroot-config
-DCONFIG_=\\"\\" -c conf.c -o
/home/loongson/workspace/buildroot/output/build/buildroot-config/conf.o
/usr/bin/gcc -DCURSES_LOC=""
-DLOCALE
-I/home/loongson/workspace/buildroot/output/build/buildroot-config
-DCONFIG_=\\"\\" -I. -c
/home/loongson/workspace/buildroot/output/build/buildroot-config/zconf.tab.c -o
/home/loongson/workspace/buildroot/output/build/buildroot-config/zconf.tab.o
/usr/bin/gcc -DCURSES_LOC=""
-DLOCALE
-I/home/loongson/workspace/buildroot/output/build/buildroot-config
-DCONFIG_=\\"\\"
/home/loongson/workspace/buildroot/output/build/buildroot-config/conf.o
/home/loongson/workspace/buildroot/output/build/buildroot-config/zconf.tab.o -o
/home/loongson/workspace/buildroot/output/build/buildroot-config/conf
rm
/home/loongson/workspace/buildroot/output/build/buildroot-config/zconf.tab.c
make[1]: 离开目录“/home/loongson/workspace/buildroot/support/kconfig”
#
# configuration written to
/home/loongson/workspace/buildroot/.config
#
loongson@loongson-virtual-machine:~/workspace/buildroot$
make
/usr/bin/make -j1
O=/home/loongson/workspace/buildroot/output HOSTCC="/usr/bin/gcc"
HOSTCXX="/usr/bin/g++" syncconfig
make[1]: 进入目录“/home/loongson/workspace/buildroot”
make[1]: 离开目录“/home/loongson/workspace/buildroot”
> > > host-skeleton
> > > Extracting
> > > host-skeleton
> > > Patching
> > > host-skeleton
> > > Configuring
> > > host-skeleton
> > > Building
> > > host-skeleton
> > > Installing to host directory
pkgconf-1.6.3.tar.xz: OK (sha256:
61f0b31b0d5ea0e862b454a80c170f57bad47879c0c42bd8de89200ff62ea210)
> > > host-pkgconf 1.6.3 Extracting
……
/target/etc/systemd/system/sysinit.target.wants/systemd-pstore.service
→ /usr/lib/systemd/system/systemd-pstore.service.
Created symlink
/home/loongson/workspace/buildroot/output/build/buildroot-fs/tar/target/etc/systemd/system/multi-user.target.wants/sshd.service
→ /usr/lib/systemd/system/sshd.service.
Created symlink /home/loongson/workspace/buildroot/output/build/buildroot-fs/tar/target/etc/systemd/system/multi-user.target.wants/collectd.service
→ /usr/lib/systemd/system/collectd.service.
Created symlink
/home/loongson/workspace/buildroot/output/build/buildroot-fs/tar/target/etc/systemd/system/multi-user.target.wants/nfs-server.service
→ /usr/lib/systemd/system/nfs-server.service.
PATH="/home/loongson/workspace/buildroot/output/host/bin:/home/loongson/workspace/buildroot/output/host/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
pigz -9 -c -n /home/loongson/workspace/buildroot/output/images/rootfs.tar >
/home/loongson/workspace/buildroot/output/images/rootfs.tar.gz
ln -snf
/home/loongson/workspace/buildroot/output/host/loongarch64-buildroot-linux-gnu/sysroot
/home/loongson/workspace/buildroot/output/staging
最后查看生成的镜像
loongson@loongson-virtual-machine:~/workspace/buildroot$ ls output/images/ -al
总用量 1302608
drwxr-xr-x 2 loongson loongson 4096 8月 10 16:07 .
drwxr-xr-x 6 loongson loongson 4096 8月 10 16:07 ..
-rw-r
-rw-r
lrwxrwxrwx 1 loongson loongson 14 8月 10 16:07 rootfs.ext4.gz -> rootfs.ext2.gz
lrwxrwxrwx 1 loongson loongson 14 8月 10 16:07 rootfs.img -> rootfs.ext2.gz
-rw-r
-rw-r
镜像替换
镜像准备
升级uboot
镜像升级,主要参考《广东龙芯2k0300蜂鸟板快速使用指南-v1.0.240725》的1.7.1节进行
- 1 将镜像放到U盘根目录下的update目录
- 2 U盘插入板子,重启,按m进入uboot控制菜单
- 3 再选择通过usb升级
- 4 显示升级成功
对比升级前与升级后
替换内核
uname -a
镜像升级,主要参考《广东龙芯2k0300蜂鸟板快速使用指南-v1.0.240725》的1.7.1节进行,其实本质是将uImage放到根文件系统的boot目录下
- 1 将镜像放到U盘根目录下的update目录
- 2 U盘插入板子,重启,按m进入uboot控制菜单
- 3 再选择通过usb升级
- 4 显示升级成功
对比升级前与升级后
替换根文件系统
镜像升级,主要参考《广东龙芯2k0300蜂鸟板快速使用指南-v1.0.240725》的1.4.1节进行
- 1 将镜像放到U盘根目录下的update目录
- 2 U盘插入板子,重启,按m进入uboot控制菜单
- 3 再选择通过usb升级![QQ_1723371162676.png]
- 4 显示升级成功![QQ_1723371443719.png]
对比升级前与升级后
附录
uboot升级失败
打印如下
Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit
[1] Update u-boot to spi flash (by usb)
[2] Update u-boot to spi flash (by mmc)
[3] Update u-boot to spi flash (by tftp)
[4] Return
Press UP/DOWN to move, ENTER to select
resetting USB...
Bus ehci@0x16080000: USB EHCI 1.00
Bus ohci@0x16088000: USB OHCI 1.0
Bus otg@0x16040000: dwc2_usb otg@0x16040000: Core Release: 2.93a
USB DWC2
scanning bus ehci@0x16080000 for devices... 2 USB Device(s) found
scanning bus ohci@0x16088000 for devices... 1 USB Device(s) found
scanning bus otg@0x16040000 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found
Device 0: Vendor: Generic Rev: 8.07 Prod: Flash Disk
Type: Removable Hard Disk
Capacity: 60000.0 MB = 58.5 GB (122880000 x 512)
update u-boot.............
try to get u-boot-with-spl.bin ......
### cur test cmd : fatload usb 0:0 ${loadaddr} /update/u-boot-with-spl.bin
Can't set block device
### cur test cmd : ext4load usb 0:0 ${loadaddr} /update/u-boot-with-spl.bin
Can't set block device
try to get u-boot.bin ......
### cur test cmd : fatload usb 0:0 ${loadaddr} /update/u-boot.bin
Can't set block device
### cur test cmd : ext4load usb 0:0 ${loadaddr} /update/u-boot.bin
Can't set block device
upgrade uboot failed, not found u-boot image!
loongson_update - upgrade uboot kernel rootfs dtb over usb\\tftp\\mmc\\dhcp.
Usage:
loongson_update
查看U盘格式,应改为fat32
uboot启动系统失败
uboot升级重启后,报如下错
SF: Detected gd25q80 with page size 256 Bytes, erase size 4 KiB, total 1 MiB
device 0 offset 0xf0000, size 0xe000
SF: 57344 bytes @ 0xf0000 Read: OK
Couldn't find partition mmc 0:1
Can't set block device
Wrong Image Format for bootm command
ERROR: can't get kernel image!
Bootcmd="setenv bootargs ${bootargs} root=/dev/mmcblk0p${syspart} mtdparts=${mtdparts} fbcon=rotate:${rotate} panel=${panel};sf probe;sf read ${fdt_addr} 0xF0000 ${fdt_size};ext4load mmc 0:${syspart} ${loadaddr} /boot/uImage;bootm"
Boot Kernel failed. Kernel not found or bad.
简单测试
=> ext4load mmc 0:${syspart} ${loadaddr} /boot/uImage
** No partition table - mmc 0 **
Couldn't find partition mmc 0:1
Can't set block device
=> ext4load mmc 0 ${loadaddr} /boot/uImage
8830259 bytes read in 192 ms (43.9 MiB/s)
修改
=> setenv bootcmd 'setenv bootargs ${bootargs} root=/dev/mmcblk0 mtdparts=${mtdparts} fbcon=rotate:${rotate} panel=${panel};sf probe;sf read ${fdt_addr} 0xF0000 ${fdt_size};ext4load mmc 0 ${loadaddr} /boot/uImage;bootm'
=> saveenv
Saving Environment to SPIFlash... Erasing SPI flash...Writing to SPI flash...done
OK
参考
源代码
广东龙芯2K0300蜂鸟板快速使用指南-v1.0.240725
广东龙芯2K0300蜂鸟板用户手册V0.99