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
標籤:其他
