注:简单记录一下,如果实验不成功,我也没有对应的方法;
使用的工具为 xshell,编码设置为 UTF-8
对应 menuconfig 路径
# kernel 版本 5.4.70
# 一般都默认支持,其它的我也不懂
File systems --->
-*- Native language support --->
<*> NLS UTF-8
# which sh
/bin/sh
# ls -al /bin/sh
lrwxrwxrwx 1 root root 7 Jan 1 00:00 /bin/sh -> busybox
# which sh
/bin/sh
# ls -al /bin/sh
lrwxrwxrwx 1 root root 9 Jan 1 1970 /bin/sh -> /bin/bash
# which bash
/bin/bash
# ls -al /bin/bash
-rwxrwxrwx 1 root root 826532 Oct 17 2019 /bin/bash
参考博客:https://blog.csdn.net/weixin_42842270/article/details/107839478
http://t.zoukankan.com/ChenChangXiong-p-13578667.html
使用的交叉编译器版本为:gcc-arm-11.2-2022.02-x86_64-arm-none-linux-gnueabihf
交叉编译器下载网址:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/downloads
使用的 busybox 版本为 Busybox_1.30.0;可以自行选择对应的版本;
busybox 下载地址:https://busybox.net/downloads/
export ARCH=arm
export CROSS_COMPILE=arm-none-linux-gnueabihf-
export PATH=$PATH:/opt/work/sdk/gcc-arm-11.2-2022.02-x86_64-arm-none-linux-gnueabihf/bin
busybox提供了几种配置:
defconfig(缺省配置)
allyesconfig(最大配置)
allnoconfig(最小配置)
一般选择缺省配置即可,这一步结束后,将生成.config
Settings --->
--- Build Options
[*] Build static binary (no shared libs) # 把busybox编译成静态链接的可执行文件,不用依赖其他库运行
--- Installation Options ("make install" behavior)
(./_install) Destination path for 'make install' # 默认的安装目录为当前的 _install 目录,不用改就行
--- Library Tuning
[*] Support Unicode
[*] Check $LC_ALL, $LC_CTYPE and $LANG environment variables
(63) Character code to substitute unprintable characters with # 替换不可打印的字符
(195101) Range of supported Unicode characters # 支持的 Unicode 字符范围,改为 195101(即 2FA1D)
diff --git a/libbb/printable_string.c b/libbb/printable_string.c
index a814fd0..816db74 100644
--- a/libbb/printable_string.c
+++ b/libbb/printable_string.c
@@ -28,8 +28,10 @@ const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str)
}
if (c < ' ')
break;
+#if 0
if (c >= 0x7f)
break;
+#endif
s++;
}
@@ -42,8 +44,13 @@ const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str)
unsigned char c = *d;
@@ -42,8 +44,13 @@ const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str)
unsigned char c = *d;
if (c == '\0')
break;
+#if 0
if (c < ' ' || c >= 0x7f)
*d = '?';
+#else
+ if (c < ' ')
+ *d = '?';
+#endif
d++;
}
if (stats) {
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 89d4217..cf46cf9 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -1019,7 +1019,11 @@ static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char
while ((int)--width >= 0);
break;
}
+#if 0
*d++ = (c >= ' ' && c < 0x7f) ? c : '?';
+#else
+ *d++ = (c >= ' ') ? c : '?';
+#endif
src++;
}
*d = '\0';
@@ -1027,8 +1031,13 @@ static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char
d = dst = xstrndup(src, width);
while (*d) {
unsigned char c = *d;
+#if 0
if (c < ' ' || c >= 0x7f)
*d = '?';
+#else
+ if (c < ' ')
+ *d = '?';
+#endif
d++;
}
}
diff --git a/coreutils/date.c b/coreutils/date.c
index 9cbc730..0d581f5 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -279,6 +279,9 @@ int date_main(int argc UNUSED_PARAM, char **argv)
time(&ts.tv_sec);
#endif
}
+#if !ENABLE_FEATURE_DATE_NANO
+ ts.tv_nsec = 0;
+#endif
localtime_r(&ts.tv_sec, &tm_time);
/* If date string is given, update tm_time, and maybe set date */
@@ -301,9 +304,11 @@ int date_main(int argc UNUSED_PARAM, char **argv)
if (date_str[0] != '@')
tm_time.tm_isdst = -1;
ts.tv_sec = validate_tm_time(date_str, &tm_time);
+ ts.tv_nsec = 0;
/* if setting time, set it */
- if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
+ //if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
+ if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
bb_perror_msg("can't set date");
}
}
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
index 87cf59b..b5916aa 100644
--- a/libbb/missing_syscalls.c
+++ b/libbb/missing_syscalls.c
@@ -15,6 +15,7 @@ pid_t getsid(pid_t pid)
return syscall(__NR_getsid, pid);
}
+#if 0
int stime(const time_t *t)
{
struct timeval tv;
@@ -22,6 +23,7 @@ int stime(const time_t *t)
tv.tv_usec = 0;
return settimeofday(&tv, NULL);
}
+#endif
int sethostname(const char *name, size_t len)
{
diff --git a/util-linux/rdate.c b/util-linux/rdate.c
index 70f829e..de78377 100644
--- a/util-linux/rdate.c
+++ b/util-linux/rdate.c
@@ -95,9 +95,14 @@ int rdate_main(int argc UNUSED_PARAM, char **argv)
if (!(flags & 2)) { /* no -p (-s may be present) */
if (time(NULL) == remote_time)
bb_error_msg("current time matches remote time");
- else
- if (stime(&remote_time) < 0)
+ else {
+// if (stime(&remote_time) < 0)
+ struct timespec ts;
+ ts.tv_sec = remote_time;
+ ts.tv_nsec = 0;
+ if (clock_settime(CLOCK_REALTIME, &ts) < 0)
bb_perror_msg_and_die("can't set time of day");
+ }
}
if (flags != 1) /* not lone -s */
vmuser:Busybox_1.30.0$ls -al _install/bin/busybox
-rwxr-xr-x 1 vmuser vmuser 1357136 Jul 22 10:39 _install/bin/busybox
# chmod 777 busybox
# ls
busybox
# which ls
/bin/ls
# rm /bin/ls
# cp busybox /bin/ls
# ls
busybox
# touch 哈哈.txt
# ls
busybox 哈哈.txt
我的设备环境是基于 bash 的;
参考博客:https://blog.csdn.net/yekui006/article/details/124384558
https://blog.csdn.net/weixin_30040925/article/details/116615917
cd /usr && find -name i18n
如果没有,拷贝交叉编译器的 i18n 文件夹到 /usr/share 目录下;
我的交叉编译器 i18n 路径为:
vmuser:gcc-arm-11.2-2022.02-x86_64-arm-none-linux-gnueabihf$find -name i18n
./arm-none-linux-gnueabihf/libc/usr/share/i18n
./arm-none-linux-gnueabihf/libc/usr/share/i18n/locales/i18n
which locale
which localedef
如果没有,拷贝交叉编译器的 locale、localedef 到 /bin 目录下,并赋予权限;
我的交叉编译器 locale、localedef 路径为:
vmuser:gcc-arm-11.2-2022.02-x86_64-arm-none-linux-gnueabihf$find -name locale
./share/locale
./arm-none-linux-gnueabihf/include/c++/11.2.1/locale
./arm-none-linux-gnueabihf/libc/usr/share/locale
./arm-none-linux-gnueabihf/libc/usr/bin/locale
vmuser:gcc-arm-11.2-2022.02-x86_64-arm-none-linux-gnueabihf$find -name localedef
./arm-none-linux-gnueabihf/libc/usr/bin/localedef
mkdir -p /usr/lib/locale && localedef -f UTF-8 -i zh_CN zh_CN.UTF8
删掉添加的文件,使用命令
localedef --delete-from-archive zh_CN.UTF8