auto make System.map to C header file

#!/bin/bash

#                    auto make System.map to C header file
# 说明:
#     该脚本主要是将Linux内核生成的System.map文件中的符号、地址存入结构体中,
# 目前认为也许可以在内核驱动中直接调用对应的函数。以前在学习裸板开发中就有
# 使用Uboot中提供的printf来写程序的先例,那么这里应该也是可以的,不过这里没
# 有什么实用性,因为5W个函数,但这个结构体就要用掉进200kByte空间。
# 
#                                          2016-3-19 深圳 南山平山村 曾剑锋

if [ $# -ne 1 ]; then
    echo "USAGE:"
    echo "    systemMap.sh <your system.Map file>"
    exit -1
fi

cat > systemMap.h << EOF
#ifndef __SYSTEM_MAP_H__
#define __SYSTEM_MAP_H__

typedef struct System_header {
EOF

cat $1 | awk '{print "	 unsigned int "$3";"}' | sort | uniq | grep -v "[.&]" >> systemMap.h

cat >> systemMap.h << EOF
} System_header;

System_header system_header = {
EOF

cat $1 | awk '{print $3 " 	= " "0x"$1","}' | sort -n -k1 | uniq | grep -v "[.&]" | sed -e "s/^/\t./g" >> systemMap.h 

cat >> systemMap.h << EOF
};
#endif // __SYSTEM_MAP_H__
EOF

# cat systemMap.h
#     #ifndef __SYSTEM_MAP_H__
#     #define __SYSTEM_MAP_H__
#     
#     typedef struct System_header {
#          unsigned int a_aidl_bdis_tmr;
#          unsigned int aalg_list;
#          unsigned int ablkcipher_decrypt;
#          unsigned int ablkcipher_decrypt_done;
#          unsigned int ablkcipher_encrypt;
#          unsigned int ablkcipher_encrypt_done;
#          ......
#     } System_header;
#     
#     System_header system_header = {
#         .a_aidl_bdis_tmr     = 0xc0a62660,
#         .aalg_list     = 0xc09f2a28,
#         .ablkcipher_decrypt     = 0xc04c3568,
#         .ablkcipher_decrypt_done     = 0xc04c1480,
#         .ablkcipher_encrypt     = 0xc04c34d4,
#         .ablkcipher_encrypt_done     = 0xc04c14f0,
#         ......
#     };
#     #endif // __SYSTEM_MAP_H_
原文地址:https://www.cnblogs.com/zengjfgit/p/5295290.html