Automatically distill headers from other project

catch_inc.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
 
dir_cur=`pwd`
dir_inc=original_inc
dir_src=/path/to/other/project
 
withly()
{
	[ -e $2 ] && $*
}
 
withoutly()
{
	[ -e $2 ] || $*
}
 
withly rm inc.makefile1
withly rm Makefile
 
if [ x$1 == xclean ] ; then
	withly rm inc.makefile
	withly rm ${dir_inc} -Rf
	exit 0
fi
 
withoutly mkdir ${dir_inc}
withoutly touch inc.makefile
 
while [ 1 ] ; do
	cat inc.makefile | sort | uniq > inc.makefile1
	cp inc.makefile1 inc.makefile
	cat inc.makefile | sed ':t;N;s/\n//;b t' | sed 's/\//\\\//g' | sed 's/\ /\\\ /g' > inc.makefile1
	sed "s/@original_includes@/`cat inc.makefile1`/g" Makefile.pat > Makefile
	lost_header=`make 2>&1 | grep "#include" | awk '{if ($2 == "|" && $3 == "#include") print $4}' | awk -F\" '{print $2}'`
	if [ x${lost_header} == x ] ; then
		break
	fi
	found_header=`cd ${dir_src}; find . -name ${lost_header} | head -n 1`
	echo ${found_header}
	found_header=${found_header##./}
	( cd ${dir_src}; cp --path ${found_header} ${dir_cur}/${dir_inc}/ )
	found_header=`dirname ${found_header}`
	echo "-I${dir_inc}/${found_header} " | cat >> inc.makefile
done

For an example, pattern file Makefile.pat is as

1
2
3
4
...
CFLAGS=-g -Iinclude @original_includes@
LDFLAGS=-pthread -lm
...

from which the catch_inc.sh script can generate Makefile like

1
2
3
4
...
CFLAGS=-g -Iinclude -Ioriginal_inc/subdir/in/other/project/inc1 -Ioriginal_inc/subdir/in/other/project/common/inc2
LDFLAGS=-pthread -lm
...

refer to:
https://www.cnblogs.com/liqiu/p/4506508.html

Hardware memo

1
2
3
4
5
6
7
8
PWM	Pulse Width Modulation
SPI	Serial Peripheral Interface			MISO MOSI SCLK CS
UART	Universal Asynchronous Receiver/Transmitter	Rx Tx GND
USB	Universal Serial Bus				VBUS D- D+ GND
AMBA	Advanced Microcontroller Bus Architecture	AHB ASB APB
MIPI	Mobile Industry Processor Interface
LVDS	Low Voltage Differential Signaling
CFA	Color Filter Arrays

HiSi

1
2
3
4
5
6
7
8
9
NNIE	DPU
IVE	ISP
VI	Video Input
VO	Video Output
VPSS	Video Processing Sub System
AVS	Video Splicing
MMZ	Media Memory Zone
VB	Video Buffer
NR	Noise Reduction

refer to:
https://www.cnblogs.com/qinghaowusu/p/13610568.html

h264 memo

AVC		Advanced Video Coding, alias h264

SODB	String Of Data Bits
RBSP	Raw Byte Sequence Payload
		RBSP = SODB + (RBSP Trailing Bits for alignment)

EBSP	Encapsulated Byte Sequence Payload
		EBSP = RBSP inserted 0x03 to avoid being treated as startcode of a NALU
		Raw data
			... 0xXX, 0x00, 0x00, 0xXX, ...
		Encoded data
			... 0xXX, 0x00, 0x00, 0x03, 0xXX, ...
NALUHeader
		forbidden_zero_bit, 1bit
		nal_ref_idc, 2bits
		nal_unit_type, 5bits, equals NALUHeader & 0x1F

NALU	Network Abstraction Layer Unit
		NALU = NALUHeader + EBSP
		startcode
			0x00, 0x00, 0x01		Following NALU is a slice in one picture frame
			0x00, 0x00, 0x00, 0x01	Following NALU is a picture frame, SPS, PPS, etc
AU		Access Units
			A complete picture frame containing several NALUs

SPS		Sequence Parameter Set				nal_unit_type == 7
			From an SPS, we can get width and height of the picture

PPS		Picture Parameter Set					nal_unit_type == 8
IDR		Instantaneous Decoding Refresh			nal_unit_type == 5
SEI		Supplemental Enhancement Information	nal_unit_type == 6
			1 byte payloadType + 1 byte payloadSize
			payloadType
				0x00: buffering_period
				0x01: pic_timing
				0x02: pan_scan_rect
				0x03: filler_payload
				0x04: user_data_registered_itu_t_t35
				0x05: user_data_unregistered
					16 bytes: uuid_iso_iec_11578
					payloadSize - 16: user_data_payload_byte
				0x06: recovery_point
			rbsp trailing bits
AnnexB
		use startcode
AVCC
		use NALU length, reuse EBSP
RTP
		in AVCC, not AnnexB?

refer to:
https://www.cnblogs.com/ssyfj/p/14624498.html
https://blog.csdn.net/y601500359/article/details/80943990

Priority of operator

Upper operators are more preemptive than lower ones.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
left to right	[] () . -> rear++ rear--
right to left	front++ front-- sizeof & * +(positive) -(negitive) ~ !
right to left	(mandatory transform)
left to right	.* ->*
left to right	* / %
left to right	+ -
left to right	<< >>
left to right	< > <= >=
left to right	== !=
left to right	&
left to right	^
left to right	|
left to right	&&
left to right	||
right to left	?:
right to left	= *= /= %= += -= <<= >>= &= ^= |=
left to right	,

refer to:
https://blog.csdn.net/l2014010671/article/details/104636916

Download all debug symbols for Win10

Download app symbols,

1
2
3
4
set SYMURL=SRV*C:\MySymbols\*http://msdl.microsoft.com/download/symbols
#symchk /om c:\MySymbols\app_manifest.txt /ie explorer.exe
#symchk /im c:\MySymbols\app_manifest.txt /s %SYMURL%
symchk /r /ie explorer.exe /s %SYMURL%

Download kernel symbols,

1
symchk /r c:\windows\system32\ntoskrnl.exe /s %SYMURL%

Setup symbols path for WinDbg and IDA in console with Administrator privilege,

1
2
setx /m _NT_SYMBOL_PATH SRV*c:\\MySymbols*http://msdl.microsoft.com/download/symbols/
#.

ps. SymChk is in WinDbg tools.

refer to:
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/using-a-manifest-file-with-symchk
https://blog.csdn.net/ziwei960319/article/details/122212998
https://www.cnblogs.com/antigao/p/4584034.html

Source and destination

Colored item indicates destination.

param 1 param 2
Tell him(indirect object) the truth(direct object)
Replace rice with noodles
Prefer coffee to tea
substitute dest for src
substitute src with dest
grep word file
find directory -name "*key*"
cp src dest
ln src link
chown owner file
strcpy dest src
#define macro expression
typedef source type
mklink link src

Recover Fedora after EFI partition is deleted by shaking hand

Make a Fedora live USB stick, plug it in the pc and power up, when grub menu appears, type ctrl + e, using tab key find the real path when editing,

linux (hd2,gpt3)/boot/vmlinuz-5.16.12-200.fc35.x86_64 root=/dev/sda3 ro rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1
initrd (hd2,gpt3)/boot/initramfs-5.16.12-200.fc35.x86_64.img

press ctrl + x to boot.

If encounter

Cannot open access to console, the root account is locked.

It means the password of root is not set so far,

Reboot to Fedora live environment,

# /dev/sda3 is the root partition.
mkdir /tmp/sda3
mount /dev/sda3 /tmp/sda3
cd /tmp/sda3
mount -o bind /dev ./dev
mount -t proc proc ./proc
mount -t sysfs sys ./sys
chroot .
passwd root

Now we have set up root password, then retry previous step to boot in local Fedora.

sudo su

# For security, Fedora coder disables directly building loader files in EFI partition.
# we can not invoke like this: grub2-install /dev/sda

dnf reinstall grub2-efi-x64 shim-x64
dnf install grub2-efi-x64-modules

# for how to register startup item in EFI NVRAM, get it from
#grep efibootmgr /var/log/anaconda/storage.log

# we make /dev/sda1 as EFI partition.
# -c = create
# -d = disk
# -p = EFI partition number, start from 1
# -l = loader path
efibootmgr -c -w -L Fedora -d /dev/sda -p 1 -l \EFI\fedora\shimx64.efi

refer to:
https://bugzilla.redhat.com/show_bug.cgi?id=1917213

Burn iso to USB stick for Windows installation

  • Rufus, released only in Windows.

    https://rufus.ie/en/
    https://github.com/pbatard/rufus

  • WoeUSB, can run in Linux.

    1
    2
    3
    
    dnf install WoeUSB
    # /dev/sdd is the u-disk
    woeusb --device /path/to/cn_windows_10_enterprise_ltsc_2019_x64_dvd_9c09ff24.iso /dev/sdd

Install VMWare Player in Fedora

After

1
dnf install kernel-headers kernel-devel

we still failed building kernel modules for VMWare Player in fedora,

1
vm_basic_defs.h:54:12: fatal error: stddef.h: No such file or directory

A solution is

1
2
3
4
# e.g. current kernel version is 5.16.12-200.fc35.x86_64
cd /usr/src/kernel/5.16.12-200.fc35.x86_64/include
ln -s linux/stddef.h stddef.h
ln -s linux/stdarg.h stdarg.h

refer to:
https://stackoverflow.com/questions/54480765/how-can-i-solve-stdarg-h-no-such-file-or-directory-while-compiling-out-of-tree-l