主頁 > 移動端開發 > [Linux Audio Driver] 移植外部CODEC常見編譯報錯解決(持續更新)

[Linux Audio Driver] 移植外部CODEC常見編譯報錯解決(持續更新)

2021-02-05 14:35:16 移動端開發

0. 背景

最近一直在除錯codec芯片,好多代碼FAE給的和平臺不適配,比如結構體改了之類的,一些編譯問題老是忘記,就想著順手寫下總結,

在這里插入圖片描述

1. function definition is not allowed here

error: function definition is not allowed here

好家伙,它說函式不能夠在這里定義,網上看了一下,這個報錯的原因是在函式原型里面又定義了一個函式,
在這里插入圖片描述
回頭看下函式報錯的位置,這里for回圈的括號丟了一個,添上即可,

(其他還有類似報錯,但是 發生在報錯函式的前一個函式少一個括號-_-),

這玩意會帶來一系列報錯,改一個就改好好多報錯,

2. extraneous ‘)’ before ‘;’

627:109: error: extraneous ')' before ';'

這個報錯說有個括號很突兀,不曉得哪里來的,extraneous是外來的意思,

在這里插入圖片描述

然后看了下,發現多了一個括號,

3. no member named ‘codec’ in 'struct snd_soc_dai

在這里插入圖片描述
這個報錯是說,snd_soc_dai結構體里面缺少成員變數codec,

在這里插入圖片描述

好家伙,我發現這個snd_soc_codec結構體在android 11直接被干沒了, 之前在msm-3.18 、 android 7是有的,如下:

grep -nr "struct snd_soc_codec {"  ./kernel/msm-3.18/
  /* SoC Audio Codec device */
  struct snd_soc_codec {
      struct device *dev;
      const struct snd_soc_codec_driver *driver;
 
      struct mutex mutex;
      struct list_head list;
      struct list_head card_list;
      int (*volatile_register)(struct snd_soc_codec *, unsigned int);
      int (*readable_register)(struct snd_soc_codec *, unsigned int);
      int (*writable_register)(struct snd_soc_codec *, unsigned int);
 
      /* runtime */
      struct snd_ac97 *ac97;  /* for ad-hoc ac97 devices */
      unsigned int cache_bypass:1; /* Suppress access to the cache */
      unsigned int suspended:1; /* Codec is in suspend PM state */
      unsigned int ac97_registered:1; /* Codec has been AC97 registered */
      unsigned int ac97_created:1; /* Codec has been created by SoC */
      unsigned int cache_init:1; /* codec cache has been initialized */
      u32 cache_sync; /* Cache needs to be synced to hardware */
 
      /* codec IO */
      void *control_data; /* codec control (i2c/3wire) data */
      hw_write_t hw_write;
      void *reg_cache;
      struct mutex cache_rw_mutex;
 
      /* component */
      struct snd_soc_component component;
 
      /* dapm */
      struct snd_soc_dapm_context dapm;
 
  #ifdef CONFIG_DEBUG_FS
      struct dentry *debugfs_reg;
  #endif
  };

仔細看了下代碼,發現這個報錯的地方就是根據dai(傳進來的引數),找到codec,然后根據codec找到es7210結構體,目的是根據es7210->pcm_pop_work1的地址傳參給schedule_delayed_work這個延遲佇列,看了下pcm_pop_work1函式是處理POP音的,目前代碼還在移植階段,干脆簡單粗暴把這個幾個都注釋掉:
在這里插入圖片描述

在這里插入圖片描述

4. warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement] error

995:6: warning: ISO C90 forbids mixing declarations and code

在這里插入圖片描述
這個錯誤真的無力吐槽,也不知道哪個兄弟寫的代碼…這個要把int i放在前面,

5. implicit declaration of function ‘snd_soc_codec_get_drvdata’ [-Werror,-Wimplicit-function-declaration]

error: implicit declaration of function 'snd_soc_codec_get_drvdata' [-Werror,-Wimplicit-function-declaration]

在這里插入圖片描述

這里又用到了snd_soc_codec結構體,這里看起來繞不掉了,因為es7210_tdm_init_codec這個函式看起來比較重要,

于是想著看看平臺默認的codec驅動是咋搞的,看了下snd_soc_component結構體與snd_soc_codec類似,于是決定全面改寫代碼,把傳參struct snd_soc_codec *codec全部干掉,換成struct snd_soc_component *component,

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

6. implicit declaration of function 'snd_soc_unregister_codec

.c:2187:2: error: implicit declaration of function 'snd_soc_unregister_codec' 
[-Werror,-Wimplicit-function-declaration]

snd_soc_unregister_codec這個函式也木得,(后面直接用SI看了,不grep了),還是看了下平臺的codec芯片代碼,
發現應該是用snd_soc_unregister_component函式,

同樣,snd_soc_register_codec這個函式也木有了,我們替換成snd_soc_register_component,

7. use of undeclared identifier ‘GPIO_HIGH’

 error: use of undeclared identifier 'GPIO_HIGH'

這個都不用看,直接把宏定義放在代碼前面即可,

#define GPIO_LOW 0
#define GPIO_HIGH 1

8. no member named ‘power_enable_gpio’ in ‘struct es7210_priv’

error: no member named 'power_enable_gpio' in 'struct es7210_priv'
struct es7210_priv {
	struct regmap *regmap;
	struct device *dev;
	struct i2c_client *i2c;
	unsigned int sysclk;
	struct clk *mclk;
	struct snd_pcm_hw_constraint_list *sysclk_constraints;
	unsigned int tdm_mode;
	struct delayed_work pcm_pop_work;
	struct delayed_work pcm_pop_work1;
	//struct delayed_work es7243_init_work;
	struct voltage_supply vol_supply;
	int power_enable_gpio;
};

這個沒啥說的,成員變數power_enable_gpio沒有,那就加上,

9. use of undeclared identifier ‘np’

error: implicit declaration of function 'gpio_is_valid' 
[-Werror,-Wimplicit-function-declaration]
        if (!gpio_is_valid(es7210->power_enable_gpio)){

看下 of_get_named_gpio的函式原型:

static inline int of_get_named_gpio(struct device_node *np,
                                   const char *propname, int index)
{
	return of_get_named_gpio_flags(np, propname, index, NULL);
}

10. variable has incomplete type ‘struct snd_soc_codec_driver’

snd_soc_codec_driver這個結構體沒有,看看對比的codec驅動咋搞的,,

在這里插入圖片描述

把他換成snd_soc_component_driver,

11. implicit declaration of function ‘gpio_direction_output’ [-Werror,-Wimplicit-function-declaration]

error: implicit declaration of function 'gpio_free' 
[-Werror,-Wimplicit-function-declaration]gpio_free(es7210->power_enable_gpio);

在這里插入圖片描述

這個報錯前后看了下沒啥例外的,原因是沒有包含檔案頭,gpio.h,這個在代碼開頭添上即可:

#include <linux/gpio.h>

12. incompatible pointer types initializing ‘void (*)(struct snd_soc_component *)’ with an expression of type ‘int (struct snd_soc_component *)’ [-Werror,-Wincompatible-pointer-types]

error: incompatible pointer types initializing 'void (*)(struct snd_soc_component *)' 
with an expression of type 'int (struct snd_soc_component *)' [-Werror,-Wincompatible-pointer-types]
        .remove = es7210_remove,

在這里插入圖片描述

這個地方報錯得看下snd_soc_component_driver結構體,從報錯來看應該是定義的結構體成員變數型別不匹配,

在這里插入圖片描述
所以我們要調整下函式:es7210_remove

static int es7210_remove(struct snd_soc_component *component)
{
	return 0;
}

修改為:

static void es7210_remove(struct snd_soc_component *component)
{
	return ;
}

13. field designator ‘reg_word_size’ does not refer to any field in type ‘struct snd_soc_component_driver’

error: field designator 'reg_word_size' does not refer to any field in type 
'struct snd_soc_component_driver'
.reg_word_size = sizeof(u8),

/* component interface */

struct snd_soc_component_driver {
	const char *name;

	/* Default control and setup, added after probe() is run */
	const struct snd_kcontrol_new *controls;
	unsigned int num_controls;
	const struct snd_soc_dapm_widget *dapm_widgets;
	unsigned int num_dapm_widgets;
	const struct snd_soc_dapm_route *dapm_routes;
	unsigned int num_dapm_routes;

	int (*probe)(struct snd_soc_component *);
	void (*remove)(struct snd_soc_component *);
	int (*suspend)(struct snd_soc_component *);
	int (*resume)(struct snd_soc_component *);

	unsigned int (*read)(struct snd_soc_component *, unsigned int);
	int (*write)(struct snd_soc_component *, unsigned int, unsigned int);

	/* pcm creation and destruction */
	int (*pcm_new)(struct snd_soc_pcm_runtime *);
	void (*pcm_free)(struct snd_pcm *);

	/* component wide operations */
	int (*set_sysclk)(struct snd_soc_component *component,
			  int clk_id, int source, unsigned int freq, int dir);
	int (*set_pll)(struct snd_soc_component *component, int pll_id,
		       int source, unsigned int freq_in, unsigned int freq_out);
	int (*set_jack)(struct snd_soc_component *component,
			struct snd_soc_jack *jack,  void *data);

	/* DT */
	int (*of_xlate_dai_name)(struct snd_soc_component *component,
				 struct of_phandle_args *args,
				 const char **dai_name);
	int (*of_xlate_dai_id)(struct snd_soc_component *comment,
			       struct device_node *endpoint);
	void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type,
		int subseq);
	int (*stream_event)(struct snd_soc_component *, int event);
	int (*set_bias_level)(struct snd_soc_component *component,
			      enum snd_soc_bias_level level);

	/*
	 * For platform-caused delay reporting, where the thread blocks waiting
	 * for the delay amount to be determined.  Defining this will cause the
	 * ASoC core to skip calling the delay callbacks for all components in
	 * the runtime.
	 * Optional.
	 */
	snd_pcm_sframes_t (*delay_blk)(struct snd_pcm_substream *substream,
			struct snd_soc_dai *dai);

	const struct snd_pcm_ops *ops;
	const struct snd_compr_ops *compr_ops;

	/* probe ordering - for components with runtime dependencies */
	int probe_order;
	int remove_order;

	/* bits */
	unsigned int idle_bias_on:1;
	unsigned int suspend_bias_off:1;
	unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
	unsigned int endianness:1;
	unsigned int non_legacy_dai_naming:1;

	/* this component uses topology and ignore machine driver FEs */
	const char *ignore_machine;
	const char *topology_name_prefix;
	int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
				  struct snd_pcm_hw_params *params);
	bool use_dai_pcm_id;	/* use the DAI link PCM ID as PCM device number */
	int be_pcm_base;	/* base device ID for all BE PCMs */
};

看了下結構體的成員變數,這個里面沒有reg_word_size,那就給它加上,.reg_word_size = sizeof(u8),這個給它整個short就足夠了,

unsigned int (*read)(struct snd_soc_component *, unsigned int);
int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
+ short reg_word_size;
/* pcm creation and destruction */
int (*pcm_new)(struct snd_soc_pcm_runtime *);

14. ‘reg_cache_default’ does not refer to any field in type ‘struct snd_soc_component_driver’

.reg_cache_default = es7210_reg_defaults,

在這里插入圖片描述
這個也是結構體的成員變數里面沒有,它指向的是結構體陣列的地址,所以使用unsigned long int,

unsigned long int reg_cache_default;

結果還是型別不匹配-_-,這樣改了下就好了:

const struct reg_default *reg_cache_default;

15. field designator ‘reg_cache_size’ does not refer to any field in type ‘struct snd_soc_component_driver’

error: field designator 'reg_cache_size' does not refer to any field in 
type 'struct snd_soc_component_driver'
        .reg_cache_size = ARRAY_SIZE(es7210_reg_defaults),
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

從這個宏定義來看,我給它一個整型,

16.field designator ‘component_driver’ does not refer to any field in type 'struct snd_soc_component_driver

在這里插入圖片描述

它這個是結構體里面又嵌入了一個結構體,這個操作很簡單,因為默認的結構里里面是有:controls和num_controls
的:

在這里插入圖片描述

在這里插入圖片描述
所以修改如下:

在這里插入圖片描述

17.implicit declaration of function ‘of_get_named_gpio’ [-Werror,-Wimplicit-function-declaration]

implicit declaration of function 'of_get_named_gpio' [-Werror,-Wimplicit-function-declaration]
power_enable_gpio = of_get_named_gpio(np, "es7210,power-enable-gpio", 0);

這個函式原型:of_get_named_gpio,用SI看了下在:

kernel\msm-4.19\include\linux\of_gpio.h

所以加上檔案頭:

#include <linux/of_gpio.h>

18. unused function ‘es7210_multi_chips_write’

 warning: unused function 'es7210_multi_chips_write' [-Wunused-function]
 error, forbidden warning:

在這里插入圖片描述

代碼被呼叫的地方,默認全部被注釋了,所以直接把這個函式也注釋了即可,

在這里插入圖片描述
好家伙,我解了50-60個編譯報錯,終于編過去了,

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/256821.html

標籤:其他

上一篇:Android編譯系統的學習(二)

下一篇:Windows10下如何創建VHDX(VHD)格式的虛擬硬碟檔案

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more