首页 > 其他分享 >编译u-boot

编译u-boot

时间:2023-11-06 10:59:27浏览次数:37  
标签:do restore boot 192.168 编译 brctl qemu

编译u-boot

源码仓库:https://github.com/u-boot/u-boot

可以在源码的 configs 目录下面的看到支持的类型

image

选择合适的架构,比如说,我现在需要用 qemu 来跑一个 aarch64 的内核

适合 qemu 的配置有这些

image

我们选择 qemu 和 arm64 那就是 qemu_arm64_defconfig,回到 u-boot 源码根目录,执行 make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- qemu_arm64_defconfig​,生成对应的预设设置,根据自己的需求更改 ARCH 和 CROSS_COMPILE 为对应的架构和交叉编译工具链

​​image

如果需要自定义某些参数的话可以手动编辑 .config 或者 执行 make menuconfig​ 打开可视配置界面

image

配置好了之后直接 make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- -j4​ 等着编译完就生成了目标 elf 文件

image

用 qemu 启动

qemu-system-aarch64 -machine virt -cpu cortex-a57 -kernel u-boot -serial stdio -append "console=ttyAMA0"

image

配置好 qemu 的网络就可以通过ftp把内核上传到u-boot启动

可以参考我 qemu 的 nat 配置,因为 qemu 默认不是 nat,没法通过 ip 和宿主机通讯

记得配置成自己需要的的 ip,放到 /etc/qemu-ifup,加可执行权限 chmod +x /etc/qemu-ifup

#!/bin/sh
#
# Copyright IBM, Corp. 2010  
#
# Authors:
#  Anthony Liguori <[email protected]>
#
# This work is licensed under the terms of the GNU GPL, version 2.  See
# the COPYING file in the top-level directory.

# Set to the name of your bridge
BRIDGE=br0

# Network information
NETWORK=192.168.53.0
NETMASK=255.255.255.0
GATEWAY=192.168.53.1
DHCPRANGE=192.168.53.2,192.168.53.254

# Optionally parameters to enable PXE support
TFTPROOT=
BOOTP=

do_brctl() {
    brctl "$@"
}

do_ifconfig() {
    ifconfig "$@"
}

do_dd() {
    dd "$@"
}

do_iptables_restore() {
    iptables-restore "$@"
}

do_dnsmasq() {
    dnsmasq "$@"
}

check_bridge() {
    if do_brctl show | grep "^$1" > /dev/null 2> /dev/null; then
        return 1
    else
        return 0
    fi
}

create_bridge() {
    do_brctl addbr "$1"
    do_brctl stp "$1" off
    do_brctl setfd "$1" 0
    do_ifconfig "$1" "$GATEWAY" netmask "$NETMASK" up
}

enable_ip_forward() {
    echo 1 | do_dd of=/proc/sys/net/ipv4/ip_forward > /dev/null
}

add_filter_rules() {
do_iptables_restore <<EOF
# Generated by iptables-save v1.3.6 on Fri Aug 24 15:20:25 2007
*nat
:PREROUTING ACCEPT [61:9671]
:POSTROUTING ACCEPT [121:7499]
:OUTPUT ACCEPT [132:8691]
-A POSTROUTING -s $NETWORK/$NETMASK -j MASQUERADE 
COMMIT
# Completed on Fri Aug 24 15:20:25 2007
# Generated by iptables-save v1.3.6 on Fri Aug 24 15:20:25 2007
*filter
:INPUT ACCEPT [1453:976046]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1605:194911]
-A INPUT -i $BRIDGE -p tcp -m tcp --dport 67 -j ACCEPT 
-A INPUT -i $BRIDGE -p udp -m udp --dport 67 -j ACCEPT 
-A INPUT -i $BRIDGE -p tcp -m tcp --dport 53 -j ACCEPT 
-A INPUT -i $BRIDGE -p udp -m udp --dport 53 -j ACCEPT 
-A FORWARD -i $1 -o $1 -j ACCEPT 
-A FORWARD -s $NETWORK/$NETMASK -i $BRIDGE -j ACCEPT 
-A FORWARD -d $NETWORK/$NETMASK -o $BRIDGE -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A FORWARD -o $BRIDGE -j REJECT --reject-with icmp-port-unreachable 
-A FORWARD -i $BRIDGE -j REJECT --reject-with icmp-port-unreachable 
COMMIT
# Completed on Fri Aug 24 15:20:25 2007
EOF
}

start_dnsmasq() {
    do_dnsmasq \
        --strict-order \
        --except-interface=lo \
        --interface=$BRIDGE \
        --listen-address=$GATEWAY \
        --bind-interfaces \
        --dhcp-range=$DHCPRANGE \
        --conf-file="" \
        --pid-file=/var/run/qemu-dnsmasq-$BRIDGE.pid \
        --dhcp-leasefile=/var/run/qemu-dnsmasq-$BRIDGE.leases \
        --dhcp-no-override \
        ${TFTPROOT:+"--enable-tftp"} \
        ${TFTPROOT:+"--tftp-root=$TFTPROOT"} \
        ${BOOTP:+"--dhcp-boot=$BOOTP"}
}

setup_bridge_nat() {
    if check_bridge "$1" ; then
        create_bridge "$1"
        enable_ip_forward
        add_filter_rules "$1"
        start_dnsmasq "$1"
    fi
}

setup_bridge_vlan() {
    if check_bridge "$1" ; then
        create_bridge "$1"
        start_dnsmasq "$1"
    fi
}

setup_bridge_nat "$BRIDGE"

if test "$1" ; then
    do_ifconfig "$1" 0.0.0.0 up
    do_brctl addif "$BRIDGE" "$1"
fi

放到 /etc/qemu-ifdown,加可执行权限 chmod +x /etc/qemu-ifdown

#!/bin/sh
#
# Copyright IBM, Corp. 2010  
#
# Authors:
#  Anthony Liguori <[email protected]>
#
# This work is licensed under the terms of the GNU GPL, version 2.  See
# the COPYING file in the top-level directory.

# Set to the name of your bridge
BRIDGE=br0

# Network information
NETWORK=192.168.53.0
NETMASK=255.255.255.0
GATEWAY=192.168.53.1
DHCPRANGE=192.168.53.2,192.168.53.254

# Optionally parameters to enable PXE support
TFTPROOT=
BOOTP=

do_brctl() {
    brctl "$@"
}

do_ifconfig() {
    ifconfig "$@"
}

do_dd() {
    dd "$@"
}

do_iptables_restore() {
    iptables-restore "$@"
}

do_dnsmasq() {
    dnsmasq "$@"
}

check_bridge() {
    if do_brctl show | grep "^$1" > /dev/null 2> /dev/null; then
        return 1
    else
        return 0
    fi
}

create_bridge() {
    do_brctl addbr "$1"
    do_brctl stp "$1" off
    do_brctl setfd "$1" 0
    do_ifconfig "$1" "$GATEWAY" netmask "$NETMASK" up
}

enable_ip_forward() {
    echo 1 | do_dd of=/proc/sys/net/ipv4/ip_forward > /dev/null
}

add_filter_rules() {
do_iptables_restore <<EOF
# Generated by iptables-save v1.3.6 on Fri Aug 24 15:20:25 2007
*nat
:PREROUTING ACCEPT [61:9671]
:POSTROUTING ACCEPT [121:7499]
:OUTPUT ACCEPT [132:8691]
-A POSTROUTING -s $NETWORK/$NETMASK -j MASQUERADE 
COMMIT
# Completed on Fri Aug 24 15:20:25 2007
# Generated by iptables-save v1.3.6 on Fri Aug 24 15:20:25 2007
*filter
:INPUT ACCEPT [1453:976046]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1605:194911]
-A INPUT -i $BRIDGE -p tcp -m tcp --dport 67 -j ACCEPT 
-A INPUT -i $BRIDGE -p udp -m udp --dport 67 -j ACCEPT 
-A INPUT -i $BRIDGE -p tcp -m tcp --dport 53 -j ACCEPT 
-A INPUT -i $BRIDGE -p udp -m udp --dport 53 -j ACCEPT 
-A FORWARD -i $1 -o $1 -j ACCEPT 
-A FORWARD -s $NETWORK/$NETMASK -i $BRIDGE -j ACCEPT 
-A FORWARD -d $NETWORK/$NETMASK -o $BRIDGE -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A FORWARD -o $BRIDGE -j REJECT --reject-with icmp-port-unreachable 
-A FORWARD -i $BRIDGE -j REJECT --reject-with icmp-port-unreachable 
COMMIT
# Completed on Fri Aug 24 15:20:25 2007
EOF
}

start_dnsmasq() {
    do_dnsmasq \
        --strict-order \
        --except-interface=lo \
        --interface=$BRIDGE \
        --listen-address=$GATEWAY \
        --bind-interfaces \
        --dhcp-range=$DHCPRANGE \
        --conf-file="" \
        --pid-file=/var/run/qemu-dnsmasq-$BRIDGE.pid \
        --dhcp-leasefile=/var/run/qemu-dnsmasq-$BRIDGE.leases \
        --dhcp-no-override \
        ${TFTPROOT:+"--enable-tftp"} \
        ${TFTPROOT:+"--tftp-root=$TFTPROOT"} \
        ${BOOTP:+"--dhcp-boot=$BOOTP"}
}

setup_bridge_nat() {
    if check_bridge "$1" ; then
        create_bridge "$1"
        enable_ip_forward
        add_filter_rules "$1"
        start_dnsmasq "$1"
    fi
}

setup_bridge_vlan() {
    if check_bridge "$1" ; then
        create_bridge "$1"
        start_dnsmasq "$1"
    fi
}

setup_bridge_nat "$BRIDGE"

if test "$1" ; then
    do_ifconfig "$1" 0.0.0.0 up
    do_brctl addif "$BRIDGE" "$1"
fi

可以看 https://wiki.qemu.org/Documentation/Networking/NAT

标签:do,restore,boot,192.168,编译,brctl,qemu
From: https://www.cnblogs.com/scriptk1d/p/compile-uboot-1kkkd.html

相关文章

  • gcc 为什么在arm 开发板上 就是编译的arch64 , 在虚拟机中编译的就是 x86
     在开发板上,编译命令如下,并且程序也是可以运行的。  看看原因。    所以在板子上编译的是aarch64架构的。......
  • Redis和Spring Boot:如何协作提高您的应用程序性能
    ......
  • ZPN项目 3:使用 Intel ICX 编译多线程动态运行时pyd的失败记录
    使用Pybind11,可以生成供python调用接口的C++动态链接库,该库包含一个符合python启动签名的函数,并以pyd为后缀。编译生成该库,与生成一般C++库基本一致。特殊地,当采用以下全部配置生成时,程序的调用将失败:使用icx-cl编译器(兼容MSVC编译器标识的icx编译器)使用多线程动态运行时标......
  • Spring Boot 3系列之-启动类详解
    SpringBoot是一个功能强大、灵活且易于使用的框架,它极大地简化了Spring应用程序的开发和部署流程,使得开发人员能够更专注于业务逻辑的实现。在我们的SpringBoot3系列之一(初始化项目)文章中,我们使用了Spring官方网站生成的SpringBoot项目作为示例。在该项目中,我们可以找到一个名......
  • 前端歌谣-第贰拾四课-预编译流程
    前言我是歌谣最好的种树是十年前其次是现在今天继续给大家带来的是预编译基础的讲解环境配置npminit-yyarnaddvite-D修改page.json配置端口{"name":"demo1","version":"1.0.0","description":"","main":"index.js",......
  • Linux脚本:批量启动docker容器、批量启动springboot、批量启动Vuejs
    批量启动springboot#!/bin/bash#检查容器是否已经启动check_container(){sudodockerps|grep"$1">/dev/nullif[$?-ne0];thenecho"$1containerisnotrunning.Starting$1..."sudodockerstart"$1"elseecho......
  • springboot第44集:Kafka集群和Lua脚本
    servers:Kafka服务器的地址。这是Kafka集群的地址,生产者将使用它来发送消息。retries:在消息发送失败时,生产者将尝试重新发送消息的次数。这个属性指定了重试次数。batchSize:指定了生产者在发送消息之前累积的消息大小(以字节为单位)。一次性发送多个消息可以提高性能。linger:指定了生......
  • 编译安装与systemd管理
    编译安装Apache服务压缩包下载地址 #登录nginx官网复制链接,下载压缩包 #切换到opt目录下 #粘贴刚复制的压缩包链接,并回到行首写上wget #查看下有无下载下来 #解压这个压缩包 #切换到刚解压的压缩包里 #安装依赖包 #安装完毕后递归创建/apps/nginx ......
  • android studio 编译Telegram源码经验总结(2023-11-05)
    前言Telegram是一款强大的端到端加密IM,专注于安全性和速度,支持Android/IOS/Windows/macOS等平台,功能丰富,运行流畅,免费开源,代码具有学习和研究意义。一、androidtelegram源码下载地址:github:https://github.com/DrKLO/Telegram.git二、编译环境的选择:Windows版本:1064位;Andro......
  • springboot入门
    两年没写了。。连右下的小人都没了。得开始新一阶段的学习了。先从学习springboot及其前置内容开始学习。然后简单复习一下vue框架。idea在创建maven的springboot工程时自动下了个依赖,尽量选择版本低一点的。。适配java8不容易出问题。一旦出问题了多重建项目就会重新下springboo......