zynq开发学习记录:u-boot源码编译

1.u-boot移植

u-boot源码包准备

开发者可以从xilinx的github源码库中下载各个版本的u-boot,这里选择版本为u-boot-xlnx-xilinx-v2017.4.zip,将源码包拷贝至虚拟机环境下/home/work目录,右键提取文件到当前目录(samba方式或直接拷贝)

2.u-boot预编译

  • cd /home/work/u-boot-xlnx-xilinx-v2017.4/
  • apt-get install build-essential git-core libncurses5-dev flex bison texinfo zip unzip zlib1g-dev gettext gperf libsdl-dev libssl-dev  安装必要的工具
  • apt-get install u-boot-tools 安装u-boot必要工具
  • apt-get install device-tree-compiler 安装设备树编译工具
  • make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- zynq_zed_config
  • make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi-

编译过程中 ./lib/rsa/rsa-sign.c会编译出错,原因是u-boot中rsa使用的libssl-dev的api版本与最新安装的libssl-dev部分api不兼容,根据bing搜索到的信息,根据提示修改该文件

> ---
>  lib/rsa/rsa-sign.c | 33 +++++++++++++++++++++++++++------
>  1 file changed, 27 insertions(+), 6 deletions(-)
>
> diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
> index 8c6637e328..965fb00f95 100644
> --- a/lib/rsa/rsa-sign.c
> +++ b/lib/rsa/rsa-sign.c
> @@ -20,6 +20,19 @@
>  #define HAVE_ERR_REMOVE_THREAD_STATE
>  #endif
>
> +#if OPENSSL_VERSION_NUMBER < 0x10100000L
> +void RSA_get0_key(const RSA *r,
> +                 const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
> +{
> +   if (n != NULL)
> +       *n = r->n;
> +   if (e != NULL)
> +       *e = r->e;
> +   if (d != NULL)
> +       *d = r->d;
> +}
> +#endif
> +
>  static int rsa_err(const char *msg)
>  {
>         unsigned long sslErr = ERR_get_error();
> @@ -409,7 +422,11 @@ static int rsa_sign_with_key(RSA *rsa, struct checksum_algo *checksum_algo,
>                 ret = rsa_err("Could not obtain signature");
>                 goto err_sign;
>         }
> -       EVP_MD_CTX_cleanup(context);
> +       #if OPENSSL_VERSION_NUMBER < 0x10100000L
> +               EVP_MD_CTX_cleanup(context);
> +       #else
> +               EVP_MD_CTX_reset(context);
> +       #endif
>         EVP_MD_CTX_destroy(context);
>         EVP_PKEY_free(key);
>
> @@ -479,6 +496,7 @@ static int rsa_get_exponent(RSA *key, uint64_t *e)
>  {
>         int ret;
>         BIGNUM *bn_te;
> +       const BIGNUM *key_e;
>         uint64_t te;
>
>         ret = -EINVAL;
> @@ -487,17 +505,18 @@ static int rsa_get_exponent(RSA *key, uint64_t *e)
>         if (!e)
>                 goto cleanup;
>
> -       if (BN_num_bits(key->e) > 64)
> +       RSA_get0_key(key, NULL, &key_e, NULL);
> +       if (BN_num_bits(key_e) > 64)
>                 goto cleanup;
>
> -       *e = BN_get_word(key->e);
> +       *e = BN_get_word(key_e);
>
> -       if (BN_num_bits(key->e) < 33) {
> +       if (BN_num_bits(key_e) < 33) {
>                 ret = 0;
>                 goto cleanup;
>         }
>
> -       bn_te = BN_dup(key->e);
> +       bn_te = BN_dup(key_e);
>         if (!bn_te)
>                 goto cleanup;
>
> @@ -527,6 +546,7 @@ int rsa_get_params(RSA *key, uint64_t *exponent, uint32_t *n0_invp,
>  {
>         BIGNUM *big1, *big2, *big32, *big2_32;
>         BIGNUM *n, *r, *r_squared, *tmp;
> +       const BIGNUM *key_n;
>         BN_CTX *bn_ctx = BN_CTX_new();
>         int ret = 0;
>
> @@ -548,7 +568,8 @@ int rsa_get_params(RSA *key, uint64_t *exponent, uint32_t *n0_invp,
>         if (0 != rsa_get_exponent(key, exponent))
>                 ret = -1;
>
> -       if (!BN_copy(n, key->n) || !BN_set_word(big1, 1L) ||
> +       RSA_get0_key(key, NULL, &key_n, NULL);
> +       if (!BN_copy(n, key_n) || !BN_set_word(big1, 1L) ||
>             !BN_set_word(big2, 2L) || !BN_set_word(big32, 32L))
>                 ret = -1;
>
> --
> 2.11.1
>
> _______________________________________________
> U-Boot mailing list
> [email protected]
> http://lists.denx.de/mailman/listinfo/u-boot

修改完成后可以正常编译通过

3.u-boot SD卡功能裁剪

当前硬件环境下,单板不含有emmc或SDHC硬件,需要将u-boot相应的功能进行裁剪。

  • cd /home/work/u-boot-xlnx-xilinx-v2017.4/configs/
  • gedit zynq_zed_defconfig 文件
  • #注释CONFIG_CMD_MMC=y
  • #注释CONFIG_DFU_MMC=y
  • #注释CONFIG_DM_MMC=y
  • #注释CONFIG_ZYNQ_SDHCI=y
  • #注释CONFIG_MMC_SDHCI=y
  • 保存退出
  • cd ../arch/arm/dts/
  • gedit zynq-zed.dts
  • 注释设备树zynq SD卡部分
/*mmc0 = &sdhci0*/;

/*&sdhci0 {

       u-boot,dm-pre-reloc;

       status = "okay";

};*/
  • cd ../../..
  • 重新编译

4.u-boot下载运行

  • 将u-boot文件重命名为u-boot.elf,并复制到vivado sdk工程的硬件文件夹下,例如project_1.sdk\design_1_wrapper_hw_platform_0
  • 打开sdk,并运行时xsdb,(vivado2016以后的版本为xsct)
  • cd xxxxxx/project_1.sdk/design_1_wrapper_hw_platform_0(注意路径间隔符,补充自己的路径)
  • source ps7_init.tcl
  • ps7_init
  • dow u-boot.elf
  • con
  • 在调试串口终端可以看到u-boot输出,运行效果样例(由于uboot版本、单板硬件配置不同,打印信息略有差别)如下

zynq开发学习记录:u-boot源码编译_第1张图片

5. u-boot QSPI flash识别

  • cd /home/work/u-boot-xlnx-xilinx-v2017.4/configs
  • gedit zynq_zed_defconfig
  • n25qxxx在u-boot中宏定义开关为CONFIG_SPI_FLASH_STMICRO,将宏定义添加到QSPI相关的宏定义当中
  • cd ../..
  • 重新编译
  • 下载运行

6.u-boot phy识别

  • cd /home/work/u-boot-xlnx-xilinx-v2017.4/configs
  • gedit zynq_zed_defconfig
  • 修改CONFIG_DEFAULT_DEVICE_TREE="zynq-zed"指定设备树文件名称
  • cd /home/work/u-boot-xlnx-xilinx-v2017.4/arch/arm/dts/
  • gedit zynq-zed.dts
  • 修改下列内容

      

 aliases {

              ethernet0 = &gem1;

              serial0 = &uart1;

              spi0 = &qspi;

              /*mmc0 = &sdhci0;*/

       };/*默认ethernet 指定为gem1*/

&gem1 {

       status = "okay";

       phy-mode = "rgmii-id";

       phy-handle = <ðernet_phy>;

       ethernet_phy: ethernet-phy@3 {

              reg = <3>;

              device_type = "ethernet-phy";

       };

};/*将phy地址更改为3*/
  • cd ../../
  • 重新编译,下载

你可能感兴趣的:(zynq)