Image encryption for Xilinx ZCU-104 - image

I'm trying to encrypt an images for ZCU-104. I follow this guide :
generate RSA keys:
bootgen -p zcu9eg -arch zynqmp -w on -log error -image ./stage1.bif -generate_keys pem
generate SHA3 digest:
bootgen -p zcu9eg -arch zynqmp -w on -log error -image ./stage2.bif
-efuseppkbits ./ppk0_digest.txt
generate keys for all components:
bootgen -p zcu9eg -arch zynqmp -w on -log error -image ./stage3.bif
pass PUF Registration (guide, card output) and create helperdata.txt, black_key.txt, black_iv.txt
generate final BOOT.BIN:
bootgen -p zcu9eg -arch zynqmp -image ./stage4.bif -w -o BOOT.BIN
-encryption_dump
And here I receive an error:
****** Xilinx Bootgen v2020.2
**** Build date : May 27 2021-14:58:44
** Copyright 1986-2020 Xilinx, Inc. All Rights Reserved.
[ERROR] : Invalid no. of data bytes for PUF Helper Data.
Expected length for PUF Helper Data is 1544 bytes
and question is how to fix this error?
Vitis version 2022.1, Petalinux version 2022.1. Final bif-file (stage4.bif):
the_ROM_image:
{
[pskfile] psk0.pem
[sskfile] ssk0.pem
[auth_params] spk_id=0; ppk_select=0
[keysrc_encryption] bh_blk_key
[bh_key_iv] black_iv.txt
[bh_keyfile] black_key.txt
[puf_file] helperdata.txt
[fsbl_config] bh_auth_enable,opt_key,puf4kmode,shutter=0x0100005E,pufhd_bh
[bootloader, destination_cpu=a53-0,authentication=rsa,exception_level=el-3, encryption=aes, aeskeyfile=zynqmp_fsbl.nky, blocks=1728(*)] zynqmp_fsbl.elf
[destination_cpu=pmu,authentication=rsa, encryption=aes, aeskeyfile=pmufw.nky, blocks=1728(*)] pmufw.elf
[destination_device=pl,authentication=rsa, encryption=aes, aeskeyfile=system.nky, blocks=1728(*)] system.bit
[destination_cpu=a53-0, exception_level=el-3, trustzone,authentication=rsa] bl31.elf
[destination_cpu=a53-0, exception_level=el-2,authentication=rsa] u-boot.elf
[load=0x1000000, destination_cpu=a53-0,authentication=rsa] image.ub
}
Thank you

Related

Retrieve const string value from .elf binary via variable name using command line utility?

Consider the following main.c:
#include <stdio.h>
const char greeting[] = "hello world";
int main() {
printf("%s!\n", greeting);
return 0;
}
I compiled this in Ubuntu with:
gcc -g main.c -o main.exe
I would like to retrieve the value of the variable named greeting; considering it is const, it won't change, so it should be possible to retrieve the value "hello world" from the executable.
Basically, I can see the variable name in the binary using:
$ readelf -p .rodata main.exe | grep hello
[ 8] hello world
... and I can see the value using:
$ readelf -s main.exe | grep greeting
59: 0000000000002008 12 OBJECT GLOBAL DEFAULT 18 greeting
I could try parsing the output of readelf -s and readelf -p to get what I want (retrieve the value of the variable named greeting), but I'm pretty sure I'll mess it up.
So is there some combination of switches of bintools utilities (or any command line program, really), which would perform the equivalent of the following pseudocode:
$ [tool] --get-value-of-variable-name greeting --program=main.exe
"hello world"
or even:
$ [tool] --verbose --get-value-of-variable-name greeting --program=main.exe
The constant value of the variable "greeting" in `main.exe` is:
is there some combination of switches of bintools utilities (or any command line program, really), which would perform the equivalent of the following pseudocode:
Sure:
you need to find the section in which the symbol resides, and the address within that section, and the length of data, and
you need to find where in the file the section itself starts, and
you need to dump length bytes from the right offset in the file.
Getting this all together (my file has slightly different data from yours):
readelf -Ws main.exe | grep greeting
29: 0000000000002008 12 OBJECT GLOBAL DEFAULT 17 greeting
readelf -WS main.exe | grep '\[17\]'
[17] .rodata PROGBITS 0000000000002000 002000 000019 00 A 0 0 8
This tells me that I need to dump 12 bytes (actually 11, since I don't want the terminating \0), starting of offset 0x2000 + (0x2008 (symbol address) - 0x2000 (section address)).
dd if=main.exe bs=1 skip=$((0x2008)) count=11 2>/dev/null
hello world
Now, parsing this data out from readelf output is more trouble than it's worth -- it's much easier to write a simple C++ program to produce the desired output. Using ELFIO should make this very easy.

kernel not able to run /init in initramfs in linux android 10 kernel version 4.9

I have created a custom initramfs using the below command in my custom initramfs directory:
find . | cpio --quiet -H newc -o | gzip -9 -n > ../diaginitrd.img
Then I built a custom bootimage with the above cpio using the command
mkbootimg --kernel --ramdisk
Defconfig variables are as below:
CONFIG_BLK_DEV_INITRD=y
CONFIG_RD_LZMA=y
CONFIG_RD_BZIP2=y
I have not provided CONFIG_INITRAMFS_SOURCE variable in defconfig.
Kernel command line given is as:
Kernel command line: console=ttyMSM0,115200n8 androidboot.console=ttyMSM0 androidboot.configfs=true loop.max_part=7 androidboot.usbcontroller=a600000.dwc3 root=/dev/dm-0 rdinit=/init user_debug=31
On build when i unpack my bootimage i can see my initramfs .
On unpacking the initramfs i can see the content of my initamfs.
When i boot the my device with this bootimage i get below logs:
[ 17.850396] sde: sde1 sde2 sde3 sde4 sde5 sde6 sde7 sde8 sde9 sde10 sde11 sde12 sde13 sde14 sde15 sde16 sde17 sde18 sde19 sde20 sde21 sde22 sde23 sde24 sde25 sde26 sde27 sde28 sde29 sde30 sde31 sde32 sde33 sde34 sde35 sde36 sde37 sde38 sde39 sde40 sde41 sde42 sde43 sde44 sde45 sde46 sde47 sde48 sde49 sde50 sde51 sde52 sde53 sde54 sde55 sde56
[ 17.853364] sd 0:0:0:7: [sdh] Write Protect is off
[ 17.854114] sdf: sdf1 sdf2 sdf3 sdf4 sdf5
[ 17.854573] sd 0:0:0:7: [sdh] Optimal transfer size 8192 bytes
[ 17.861410] sdg: sdg1 sdg2 sdg3 sdg4 sdg5 sdg6 sdg7 sdg8
[ 17.870417] sdh: sdh1 sdh2 sdh3 sdh4 sdh5 sdh6 sdh7 sdh8 sdh9 sdh10 sdh11 sdh12 sdh13 sdh14 sdh15 sdh16 sdh17 sdh18 sdh19 sdh20
[ 17.967128] sda: sda1 sda2 sda3 sda4 sda5 sda6 sda7 sda8 sda9 sda10
[ 17.995848] Freeing unused kernel memory: 7616K
[ 18.002632] Initramfs ---> Failed to execute /init (error -2)
[ 18.009114] Kernel panic - not syncing: Requested init /init failed (error -2).
[ 18.016482] CPU: 6 PID: 1 Comm: swapper/0 Not tainted 4.9.206+ #10
[ 18.022707] Hardware name: Qualcomm Technologies, Inc. sda845 v2.1 MTP (DT)
[ 18.029718] Call trace:
[ 18.032195] [<0000000011338cd0>] dump_backtrace+0x0/0x260
[ 18.037635] [<0000000085c2bec8>] show_stack+0x20/0x28
[ 18.042724] [<00000000d2899c10>] dump_stack+0xbc/0xf8
[ 18.047815] [<00000000bd9287e7>] panic+0x204/0x3f8
[ 18.052652] [<00000000b85fea6d>] kernel_init+0xa4/0x10c
I am not sure why kernel is not able to read my /init file
Note: my /init is a shell script of type
init: POSIX shell script, ASCII text executable.
All the binaries in initramfs are statically linked.
I found the answer:
It was issue of sh and all other binaries.
They were not cross compiled for my system architecture.
Now after cross-compiling the script can work.
Thanks "Ian Abbot" for pointing out the issue

RUST on windows : getting LINK : fatal error LNK1181 error

I am a complete beginner (following this course actually) regarding Rust language and i was wondering if it was possible to create an app for Windows involving a mqtt client.
I created my project using cargo new testmqtt --bin,
my toml file is
[package]
name = "testmqtt"
version = "0.1.0"
authors = ["Pierre"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
mosquitto-client = "0.1.5"
Main.rs file is exactly the first one found here.
extern crate mosquitto_client as mosq;
use mosq::Mosquitto;
fn main() {
let m = Mosquitto::new("test");
m.will_set("test/will",b"finished!",0,false).expect("can't set will");
m.connect("localhost",1883).expect("can't connect");
let bonzo = m.subscribe("bonzo/#",0).expect("can't subscribe to bonzo");
let frodo = m.subscribe("frodo/#",0).expect("can't subscribe to frodo");
// not interested in any retained messages!
let mut mc = m.callbacks(());
mc.on_message(|_,msg| {
if ! msg.retained() {
if bonzo.matches(&msg) {
println!("bonzo {:?}",msg);
} else
if frodo.matches(&msg) {
println!("frodo {:?}",msg);
m.disconnect().unwrap();
}
}
});
m.loop_forever(200).expect("broken loop");
}
When doing cargo run, i do have an error saying more or less that i have to include mosquitto.lib file.
Compiling testmqtt v0.1.0 (C:\Users\Pierre\rust\testmqtt)
Finished dev [unoptimized + debuginfo] target(s) in 3.43s
Running `target\debug\testmqtt.exe`
Hello, world!
PS C:\Users\Pierre\rust\testmqtt> cargo run
Updating crates.io index
Compiling mosquitto-client v0.1.5
Compiling testmqtt v0.1.0 (C:\Users\Pierre\rust\testmqtt)
error: linking with `link.exe` failed: exit code: 1181
|
= note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.18yxopwcqksqllf0.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.26hriqf9eoqoz70e.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.287dmq688xsz3isv.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.2e77zj76zbvh065j.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.2huuzosvc51r1ocl.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.2o9r9r2t2clr39wq.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.2wggiqwux76jad1h.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.3mqzooten3ugyse9.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.3vqvdeaqidai2p26.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.4fnmrub2ky4biwf5.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.4tdiuzs0kqadbi75.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.4u40iyf9g9kmiphf.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.51m4wneyq731nq60.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.5d67na1jjhizscb4.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.ap2kea3xxb47i5p.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.h5xgbt8abre0rtw.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.vlg3p2hoy45m5m6.rcgu.o" "/OUT:C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.exe" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.49ivjbnnhficmjo4.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps" "/LIBPATH:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\libmosquitto_client-23967bfdaa3a5433.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-8864852919b3dde3.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-60bab00b06422126.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-e90b3ab99b608a07.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-d9b7b1604d471c6c.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-a439eac7fda93b7a.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-058c975bf38e4686.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-711d56157cf28645.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-d802c196c150a787.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-7147008fc56d32b8.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-57b2ee5c835455f8.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-6391a360e3eeafba.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-6c8df881cdc2afb2.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-f998976453a15b70.rlib" "mosquitto.lib" "c.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
= note: Non-UTF-8 output: LINK : fatal error LNK1181: impossible d\'ouvrir le fichier en entr\xe9e \'mosquitto.lib\'\r\n
error: aborting due to previous error
error: Could not compile `testmqtt`.
To learn more, run the command again with --verbose.
Here is the verbose ouput
To learn more, run the command again with --verbose.
PS C:\Users\Pierre\rust\testmqtt> cargo run --verbose
Fresh mosquitto-client v0.1.5
Compiling testmqtt v0.1.0 (C:\Users\Pierre\rust\testmqtt)
Running `rustc --edition=2018 --crate-name testmqtt src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=e2a79a549b8dacef -C extra-filename=-e2a79a549b8dacef --out-dir C:\Users\Pierre\rust\testmqtt\target\debug\deps -C incremental=C:\Users\Pierre\rust\testmqtt\target\debug\incremental -L dependency=C:\Users\Pierre\rust\testmqtt\target\debug\deps --extern mosquitto_client=C:\Users\Pierre\rust\testmqtt\target\debug\deps\libmosquitto_client-23967bfdaa3a5433.rlib`error: linking with `link.exe` failed: exit code: 1181
|
= note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.18yxopwcqksqllf0.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.26hriqf9eoqoz70e.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.287dmq688xsz3isv.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.2e77zj76zbvh065j.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.2huuzosvc51r1ocl.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.2o9r9r2t2clr39wq.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.2wggiqwux76jad1h.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.3mqzooten3ugyse9.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.3vqvdeaqidai2p26.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.4fnmrub2ky4biwf5.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.4tdiuzs0kqadbi75.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.4u40iyf9g9kmiphf.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.51m4wneyq731nq60.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.5d67na1jjhizscb4.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.ap2kea3xxb47i5p.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.h5xgbt8abre0rtw.rcgu.o" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.vlg3p2hoy45m5m6.rcgu.o" "/OUT:C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.exe" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\testmqtt-e2a79a549b8dacef.49ivjbnnhficmjo4.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps" "/LIBPATH:C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Pierre\\rust\\testmqtt\\target\\debug\\deps\\libmosquitto_client-23967bfdaa3a5433.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-8864852919b3dde3.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-60bab00b06422126.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-e90b3ab99b608a07.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-d9b7b1604d471c6c.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-a439eac7fda93b7a.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-058c975bf38e4686.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-711d56157cf28645.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-d802c196c150a787.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-7147008fc56d32b8.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-57b2ee5c835455f8.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-6391a360e3eeafba.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-6c8df881cdc2afb2.rlib" "C:\\Users\\Pierre\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-f998976453a15b70.rlib" "mosquitto.lib" "c.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
= note: Non-UTF-8 output: LINK : fatal error LNK1181: impossible d\'ouvrir le fichier en entr\xe9e \'mosquitto.lib\'\r\n
error: aborting due to previous error
error: Could not compile `testmqtt`.
Caused by:
process didn't exit successfully: `rustc --edition=2018 --crate-name testmqtt src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=e2a79a549b8dacef -C extra-filename=-e2a79a549b8dacef --out-dir C:\Users\Pierre\rust\testmqtt\target\debug\deps -C incremental=C:\Users\Pierre\rust\testmqtt\target\debug\incremental -L dependency=C:\Users\Pierre\rust\testmqtt\target\debug\deps --extern mosquitto_client=C:\Users\Pierre\rust\testmqtt\target\debug\deps\libmosquitto_client-23967bfdaa3a5433.rlib` (exit code: 1)
It is possible to do that, isn't ?
Regards,
Pierre

STM32 + GCC v8 + Qt Creator + Qbs : crash in __libc_init_array

After upgrading my host PC to a newer Linux version, I can't run my project anymore. I just want to program a copy of a working electronic board : hardware and code have been validated before.
More accurately, the code crashes in the startup script at _libc_init_array and jump either to BusFault_Handler() or HardFault_Handler().
I have read a lot on the forum, and it seems is related to linking to the wrong libc flavor (Thumb vs. ARM).
Tools :
code generation : STM32CubeMX
compiler : GNU GCC version 8.2.1 (8-2018-q4-major)
IDE : Qt Creator
build system : Qbs (Qt's tool)
The MCU is a STM32L476RG, Cortex-M4, ARM v7e-m, with FPU. In GNU GCC installation folder, share/doc/gcc-arm-none-eabi/readme.txt tells me what flags I need :
|------------|--------------------------------------------|--------------|
| Cortex-M4 | -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp | thumb |
| (Soft FP) | -mfpu=fpv4-sp-d16 | /v7e-m+fp |
| |--------------------------------------------| /softfp |
| | -mthumb -march=armv7e-m -mfloat-abi=softfp | |
| | -mfpu=fpv4-sp-d16 | |
|------------|--------------------------------------------|--------------|
| Cortex-M4 | -mthumb -mcpu=cortex-m4 -mfloat-abi=hard | thumb |
| (Hard FP) | -mfpu=fpv4-sp-d16 | /v7e-m+fp |
| |--------------------------------------------| /hard |
| | -mthumb -march=armv7e-m -mfloat-abi=hard | |
| | -mfpu=fpv4-sp-d16 | |
|------------|--------------------------------------------|--------------|
Only -mfloat-abi=softfp works, not -mfloat-abi=hard, but GCC documentation suggests the result is the same ; only calling conventions differ.
Here is my Qbs file :
import qbs
CppApplication {
consoleApplication: true
property string family: "STM32L4xx"
property string linkerScript: "STM32L476RGTx_FLASH.ld"
cpp.positionIndependentCode: false // make sure option -fPIC is not passed to GCC
cpp.defines: [
"USE_HAL_DRIVER",
"STM32L476xx",
"__weak=__attribute__((weak))",
"__packed=__attribute__((__packed__))"
]
cpp.commonCompilerFlags: [
"-fno-common",
"-specs=nosys.specs",
"-specs=nano.specs",
"-march=armv7e-m",
"-mcpu=cortex-m4",
"-mthumb-interwork", // support ARM and Thumb instruction sets
"-mthumb",
"-mfloat-abi=softfp",
"-mfpu=fpv4-sp-d16",
"-mtune=cortex-m4", // tune performance of code for this processor
// "-std=c99",
"-ffunction-sections",
"-fdata-sections",
// "-Os",
"-O0",
"-g3",
"-Wall",
"-c", // don't run the linker
// "-v" // print a lot of details (too much ?)
]
cpp.linkerFlags: [
"-T"+path+"/"+linkerScript,
"--gc-sections", // fixes "undefined reference to _exit" error
"-Map="+buildDirectory+"/memory.map", // file created at the end of the link step
"-static",
"--verbose", // displays library search
// "-lgcc",
// "-lg",
// "-lm"
]
cpp.includePaths: [
"Inc",
"Drivers/CMSIS/Include",
"Drivers/CMSIS/Device/ST/"+family+"/Include",
"Drivers/STM32L4xx_HAL_Driver/Inc",
"Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc",
"Middlewares/ST/STM32_USB_Device_Library/Core/Inc/"
]
files: [
"Inc/*.h",
linkerScript,
"Src/*.c",
"Drivers/CMSIS/Device/ST/"+family+"/Include/*.h",
"Drivers/CMSIS/Device/ST/"+family+"/Source/Templates/gcc/*.s",
"Drivers/CMSIS/Device/ST/"+family+"/Source/Templates/*.c",
"Drivers/CMSIS/Include/*.h",
"Drivers/"+family+"_HAL_Driver/Inc/*.h",
"Drivers/"+family+"_HAL_Driver/Src/*.c",
"Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/*.c",
"Middlewares/ST/STM32_USB_Device_Library/Core/Src/*.c"
]
Properties {
condition: qbs.buildVariant === "debug"
cpp.defines: outer.concat(["DEBUG=1"])
}
Group { // Properties for the produced executable
fileTagsFilter: product.type
qbs.install: true
}
}
The linker --verbose option lets it print the full path of the libraries it links to. And it always resolves to arm-none-eabi/lib/libc.a. But I would have expected arm-none-eabi/lib/thumb/v7e-m+fp/softfp/libc.a instead.
I also tried the linker option -nostdlib in conjunction with the -L flag , but it has no effect. It compiles even when I omit -L, but according to GCC man page, it shouldn't.
So, I am pretty stuck here. That 5 minute work is turning into days...
The problem was that the newer version of Qbs I got (v1.12.1) is smart enough to prepend "-Wl," to all options under cpp.linkerFlags... The solution is to set those flags needed to compile AND link in a cpp.driverFlags section.
Should it be helpful to anyone, here is my working (to date ;-) ) Qbs file.
import qbs
CppApplication {
consoleApplication: true
property string family: "STM32L4xx"
property string linkerScript: "STM32L476RGTx_FLASH.ld"
cpp.positionIndependentCode: false // make sure option -fPIC is not passed to GCC
// Make sure to call the linker through GCC driver :
cpp.linkerMode: "manual" // default : "automatic"
cpp.linkerName: "gcc" // this string is appended to "<full_path_to_toolchain>/arm-none-eabi-"
// Define some symbols (GCC -D flag)
cpp.defines: [
"USE_HAL_DRIVER",
"STM32L476xx",
"__weak=__attribute__((weak))",
"__packed=__attribute__((__packed__))"
]
// Options for compilation AND linking.
cpp.driverFlags: [
// CPU
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-specs=nano.specs", // use smaller libc
]
// Compiler flags for all langages (C, C++).
cpp.commonCompilerFlags: [
// Optimizations
//"-Os",
//"-O0",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
// For debug
"-g",
"-gdwarf-2",
"-c", // don't run the linker
//"-v" // print a whole lot of details
]
// Linker flag only i.e. understood by LD !!!
// Qbs will prepend all these flags with "-Wl," so that GCC transfers them to LD.
// Other options required for linking should be set in the driverFlags section.
cpp.linkerFlags: [
"-T"+path+"/"+linkerScript,
"-static",
"--verbose", // displays library search
"-lc",
"-lm",
"-lnosys",
"-Map="+buildDirectory+"/memory.map", // file created at the end of the link step
"--cref", // map file formatting
"--gc-sections", // enables garbage collection for unused sections
]
// Include directories.
cpp.includePaths: [
"Inc",
"Drivers/CMSIS/Include",
"Drivers/CMSIS/Device/ST/"+family+"/Include",
"Drivers/STM32L4xx_HAL_Driver/Inc",
"Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc",
"Middlewares/ST/STM32_USB_Device_Library/Core/Inc/"
]
// Source files.
files: [
"Inc/*.h",
linkerScript,
"Src/*.c",
"Drivers/CMSIS/Device/ST/"+family+"/Include/*.h",
"startup/*.s",
"Drivers/CMSIS/Device/ST/"+family+"/Source/Templates/*.c",
"Drivers/CMSIS/Include/*.h",
"Drivers/"+family+"_HAL_Driver/Inc/*.h",
"Drivers/"+family+"_HAL_Driver/Src/*.c",
"Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/*.c",
"Middlewares/ST/STM32_USB_Device_Library/Core/Src/*.c"
]
Properties {
condition: qbs.buildVariant === "debug"
cpp.defines: outer.concat(["DEBUG=1"])
}
Group { // Properties for the produced executable
fileTagsFilter: product.type
qbs.install: true
}
}

kprobe_events fetch-args works for x86 but not arm64

I wanted to get do_sys_open filename argument as string. For this i added kprobe following kprobetrace.txt. A simple probe which gives filename as hex works for both x86/arm64.
x86: echo 'p:myprobe do_sys_open filename_string=%si' > kprobe_events
arm64: echo 'p:myprobe do_sys_open filename_string=%x1' > kprobe_events
However changing probe to get string for file name works on x86 but not arm64(ie cannot get string representation filename_string=(fault))
x86:
echo 'p:myprobe do_sys_open filename_string=+0(%si):string' > kprobe_events
output:
adb-30551 [001] d... 4570187.407426: myprobe: (do_sys_open+0x0/0x270) filename_string="/dev/bus/usb/001/001"
arm64:
echo 'p:myprobe do_sys_open filename_string=+0(%x1):string' > kprobe_events
output:
netd-4621 [001] d... 8491.094187: myprobe: (do_sys_open+0x0/0x24c) filename_string=(fault)
To check if i was using arm ABI correctly i tried setting probe using perf.
The probe created by perf as seen from /sys/kernel/debug/tracing/kprobe_events was similar
./perf4.14 probe 'do_sys_open filename:string'
/d/tracing # cat kprobe_events
p:kprobes/myprobe do_sys_open filename_string=+0(%x1):string
But perf probe was also failing (ie filename_string="") in this case.
./perf4.14 record -e probe:do_sys_open -aR sleep 3
/data/local/tmp # ./perf4.14 script
perf4.14 4587 [007] 7490.809036: probe:do_sys_open: (ffffff8337060148) filename_string=""
sleep 4588 [003] 7490.817937: probe:do_sys_open: (ffffff8337060148) filename_string=""
What would be the correct way to set kprobe_events for arm to fetch args as string?
Am i using the ABI incorrectly?
On kernel version >= 4.20, you can use $argN to fetch the Nth function argument. From kernel 4.20 kprobetrace.rst:
FETCHARGS : Arguments. Each probe can have up to 128 args.
.....
.....
$argN : Fetch the Nth function argument. (N >= 1) (\*1)
Since the filename is second argument of do_sys_open(), you should give $arg2 in the kprobe event, like this:
echo 'p:myprobe do_sys_open filename_string=+0($arg2):string' > kprobe_events
This should work on both x86 and arm64.

Resources