RK3288 android7.1.2 kernel 更改uboot 环境变量完整详细步骤 make env(解决遇到的大问题)(进阶篇四)

准备工作:

1.搭建adbwireless 环境

参考:https://blog.csdn.net/Chhjnavy/article/details/97643584

           https://blog.csdn.net/Chhjnavy/article/details/98845930

目标板:rk3288 android

编译环境:android7.1.2

编译路径:源码根目录u-boot/ 以及 /u-boot/tools/env

2.产生fw_printenv 执行文件并下载到目标版中

1)u-boot/目录下make env  可能会出错如下:

解决办法:添加交叉编译工具: make CROSS_COMPILE=arm-linux-gnueabihf- env

编译通过后,产生fw_printenv 以及fw_env.config 文件。

2)根据目标版属性修改fw_env.config 文件

fw_env.config 文件如下:

# Configuration file for fw_(printenv/setenv) utility.
# Up to two entries are valid, in this case the redundant
# environment sector is assumed present.
# Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash.
# Futhermore, if the Flash sector size is ommitted, this value is assumed to
# be the same as the Environment size, which is valid for NOR and SPI-dataflash

# NOR example
# MTD device name	Device offset	Env. size	Flash sector size	Number of sectors
#/dev/mtd1		0x0000		0x4000		0x4000
#/dev/mtd2		0x0000		0x4000		0x4000

# MTD SPI-dataflash example
# MTD device name	Device offset	Env. size	Flash sector size	Number of sectors
#/dev/mtd5		0x4200		0x4200
#/dev/mtd6		0x4200		0x4200

# NAND example
#/dev/mtd0		0x4000		0x4000		0x20000			2

# Block device example
/dev/block/mmcblk0		0xc0000		0x20000

通过目标版终端查询:使用的是 /dev/block/mmcblk0  ,因此在fw_env.config 文件中将开启Block device 

该文件对应的设备一定要修改对,否则会出现:Cannot access MTD device /dev/mtd1: No such file or directory

3)通过adbwireless 将文件 fw_printenv 下载到目标板目录 /system/bin 中

adb push /system/bin fw_printenv

     通过adbwireless 将文件 fw_env.config  下载到目标板目录 /etc 中

adb push /etc fw_env.config

如果出现:无权限或者只读类似的问题请使用以前命令修正

adb root
mount -o rw,remount -t auto /
chmod 777 system
chmod 777 etc
chmod 777 fw_printenv
chmod 777 fe_env.config

在目录/system/bin/建立软连接:ln -s  /system/bin/fw_printenv /system/bin/fw_setenv

3.重启开机会发现目标板根目录创建的lib(存放在fw_printenv依赖库) 目录消失(以rk3288 为例解决此问题)

为什么消失,这里不做介绍,应该和根文件系统有关,请自查资料。

1)目标板可以在很多目录下创建文件重启开机都不会消失,除了根目录下创建的。因此j将fw_printenv 依赖的库放入system/lib 下,修改源码包,在文件init.rc 中添加创建符号链接:

源码根目录:out/target/product/rk3288/root/init.rc

    symlink /system/lib /lib

2)改写保存,make snod 将修改的重新编译到.img ,烧录SD 卡,重启目标板,发现根目录下已存在lib 目录,且每次开机都存在。

3)再次更改system/lib 下fw_printenv 依赖库  ld-linux-armhf.so.3 和 libc.so.6 的权限:

chmod 777  ld-linux-armhf.so.3

chmod 777  libc.so.6

 4)再次更改system/bin下fw_printenv 和 fw_setenv 的权限:

chmod 777 fw_printenv
chmod 777 fw_setenv

5)执行./fw_printenv  打印出环境变量参数

4.在根目录下执行 ./fw_setenv  有可能出现以下问题

1)/system/bin/sh: ./fw_printenv: No such file or directory

解决方法:在编译环境目录 u-boot/tools/env  执行:readelf -l fw_printenv  发现需要依赖文件 ld-linux-armhf.so.3

在 ubuntu 根目录下搜索:find / -name ld-linux*  发现 /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3  

原来 ld-linux-armhf.so.3  是指向 ld-2.15.so ,将 ld-2.15.so 拷贝出来重命名为 ld-linux-armhf.so.3 将其下载到目标目录/lib 下

如果没有lib  则:mkdir  lib   创建一个。

adb push ld-linux-armhf.so.3 /lib

2)/system/bin/sh: ./fw_printenv: Permission denied

解决方法:目标板/lib 下:chomd 777  ld-linux-armhf.so.3

3)在1)2)的基础上依然发现错误:./fw_printenv: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

解决方法:在 ubuntu 根目录下搜索:find / -name libc.so.6  发现 /usr/arm-linux-gnueabihf/lib/libc.so.6

原来 libc.so.6  是指向 libc-2.15.so ,将 libc-2.15.so 拷贝出来重命名为 libc.so.6  将其下载到目标目录/lib 下

adb push libc.so.6 /lib

并在目标板/lib 下:chomd 777  libc.so.6

4)在1)2)3)的基础上依然发现错误:Error opening lock file /var/lock/fw_printenv.lock

解决方法:在目录u-boot/env/fw_env_main.c 下将lock 部分屏蔽掉,重新make CROSS_COMPILE=arm-linux-gnueabihf- env 产生新的fw_printenv ,code 如下:

/*
 * (C) Copyright 2000-2008
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

/*
 * Command line user interface to firmware (=U-Boot) environment.
 *
 * Implements:
 *	fw_printenv [ -a key ] [[ -n name ] | [ name ... ]]
 *              - prints the value of a single environment variable
 *                "name", the ``name=value'' pairs of one or more
 *                environment variables "name", or the whole
 *                environment if no names are specified.
 *	fw_setenv [ -a key ] name [ value ... ]
 *		- If a name without any values is given, the variable
 *		  with this name is deleted from the environment;
 *		  otherwise, all "value" arguments are concatenated,
 *		  separated by single blank characters, and the
 *		  resulting string is assigned to the environment
 *		  variable "name"
 *
 * If '-a key' is specified, the env block is encrypted with AES 128 CBC.
 * The 'key' argument is in the format of 32 hexadecimal numbers (16 bytes
 * of AES key), eg. '-a aabbccddeeff00112233445566778899'.
 */

#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/file.h>
#include <unistd.h>
#include "fw_env.h"

#define	CMD_PRINTENV	"fw_printenv"
#define CMD_SETENV	"fw_setenv"

static struct option long_options[] = {
	{"script", required_argument, NULL, 's'},
	{"help", no_argument, NULL, 'h'},
	{NULL, 0, NULL, 0}
};

void usage(void)
{

	fprintf(stderr, "fw_printenv/fw_setenv, "
		"a command line interface to U-Boot environment\n\n"
		"usage:\tfw_printenv [-a key] [-n] [variable name]\n"
		"\tfw_setenv [-a key] [variable name] [variable value]\n"
		"\tfw_setenv -s [ file ]\n"
		"\tfw_setenv -s - < [ file ]\n\n"
		"The file passed as argument contains only pairs "
		"name / value\n"
		"Example:\n"
		"# Any line starting with # is treated as comment\n"
		"\n"
		"\t      netdev         eth0\n"
		"\t      kernel_addr    400000\n"
		"\t      var1\n"
		"\t      var2          The quick brown fox jumps over the "
		"lazy dog\n"
		"\n"
		"A variable without value will be dropped. It is possible\n"
		"to put any number of spaces between the fields, but any\n"
		"space inside the value is treated as part of the value "
		"itself.\n\n"
	);
}

int main(int argc, char *argv[])
{
	char *p;
	char *cmdname = *argv;
	char *script_file = NULL;
	int c;
//	const char *lockname = "/var/lock/" CMD_PRINTENV ".lock";
//	int lockfd = -1;
	int retval = EXIT_SUCCESS;
/*	lockfd = open(lockname, O_WRONLY | O_CREAT | O_TRUNC, 0666);
	if (-1 == lockfd) {
		fprintf(stderr, "Error opening lock file %s\n", lockname);
		return EXIT_FAILURE;
	}

	if (-1 == flock(lockfd, LOCK_EX)) {
		fprintf(stderr, "Error locking file %s\n", lockname);
		close(lockfd);
		return EXIT_FAILURE;
	}
*/
	if ((p = strrchr (cmdname, '/')) != NULL) {
		cmdname = p + 1;
	}

	while ((c = getopt_long (argc, argv, "a:ns:h",
		long_options, NULL)) != EOF) {
		switch (c) {
		case 'a':
			/* AES key, handled later */
			break;
		case 'n':
			/* handled in fw_printenv */
			break;
		case 's':
			script_file = optarg;
			break;
		case 'h':
			usage();
			goto exit;
		default: /* '?' */
			fprintf(stderr, "Try `%s --help' for more information."
				"\n", cmdname);
			retval = EXIT_FAILURE;
			goto exit;
		}
	}

	if (strcmp(cmdname, CMD_PRINTENV) == 0) {
		if (fw_printenv(argc, argv) != 0)
			retval = EXIT_FAILURE;
	} else if (strcmp(cmdname, CMD_SETENV) == 0) {
		if (!script_file) {
			if (fw_setenv(argc, argv) != 0)
				retval = EXIT_FAILURE;
		} else {
			if (fw_parse_script(script_file) != 0)
				retval = EXIT_FAILURE;
		}
	} else {
		fprintf(stderr,
			"Identity crisis - may be called as `" CMD_PRINTENV
			"' or as `" CMD_SETENV "' but not as `%s'\n",
			cmdname);
		retval = EXIT_FAILURE;
	}

exit:
	//flock(lockfd, LOCK_UN);
	//close(lockfd);
	return retval;
}

再次执行:

./fw_printenv  即可打印环境变量信息

./fw_setenv bootdelay 9 即更改环境变量

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 7.1.2(也被称为Nougat)是Android操作系统的一个版本,它的源代码是公开可用的。源码包含了构建和运行Android操作系统所需的所有代码文件和资源。 Android操作系统是一个基于Linux内核的开源平台,用于移动设备和嵌入式系统。它提供了一个统一的操作系统环境,使开发者能够轻松地构建和定制自己的Android设备。 Android 7.1.2源码提供了一套开发工具和框架,使开发者能够创建功能丰富、稳定和安全的应用程序。该版本中引入了一些新的功能和改,例如通知栏的增强、多任务处理的改、Doze模式的优化等,以提供更好的用户体验。 通过查看源代码,开发者可以深入了解Android操作系统的内部工作原理,并理解其中的各个组件和模块是如何相互协作的。例如,开发者可以研究Android的用户界面框架、应用程序生命周期管理、通信和存储机制等。 修复和优化Android 7.1.2源码也是可能的,因为它是开源的。开发者可以根据自己的需求和想法对操作系统行修改,并参与到Android社区中,与其他开发者分享和贡献代码。 总之,Android 7.1.2源码为开发者提供了一个定制和构建Android应用的平台。通过深入了解源码,开发者能够创建出更加出色和创新的应用程序,同时也有机会参与到Android开源社区中,为整个生态系统的发展做出贡献。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值