I need help updating some C code. If any information is missing, ask for it.
I have a V4L2 driver that works with petalinux 2019 and does not compile any more on petalinux 2022 and I think the reason is due to changes in the V4L2 header.
Here is the old C code I have (file xilinx-vfake.c):
| AR drivers/gpu/drm/built-in.a
| AR drivers/gpu/built-in.a
| CC drivers/media/platform/xilinx/xilinx-vpss-csc.o
| CC drivers/media/platform/xilinx/xilinx-vpss-scaler.o
| CC drivers/media/platform/xilinx/xilinx-vtc.o
| CC drivers/media/platform/xilinx/xilinx-vfake.o
| os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/drivers/media/platform/xilinx/xilinx-vfake.c: In function 'xvfake_enum_frame_size':
| os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/drivers/media/platform/xilinx/xilinx-vfake.c:44:48: error: passing argument 2 of 'v4l2_subdev_get_try_format' from incompatible pointer type [-Werror=incompatible-pointer-types]
| 44 | format = v4l2_subdev_get_try_format(subdev, cfg, fse->pad);
| | ^~~
| | |
| | struct v4l2_subdev_pad_config *
| In file included from os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/drivers/media/platform/xilinx/xilinx-vfake.c:9:
| os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/include/media/v4l2-subdev.h:999:54: note: expected 'struct v4l2_subdev_state *' but argument is of type 'struct v4l2_subdev_pad_config *'
| 999 | struct v4l2_subdev_state *state,
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
| os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/drivers/media/platform/xilinx/xilinx-vfake.c:42:26: warning: unused variable 'xvfake' [-Wunused-variable]
| 42 | struct xvfake_device *xvfake = to_xvfake(subdev);
| | ^~~~~~
| os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/drivers/media/platform/xilinx/xilinx-vfake.c: In function '__xvfake_get_pad_format':
| os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/drivers/media/platform/xilinx/xilinx-vfake.c:65:66: error: passing argument 2 of 'v4l2_subdev_get_try_format' from incompatible pointer type [-Werror=incompatible-pointer-types]
| 65 | return v4l2_subdev_get_try_format(&xvfake->xvip.subdev, cfg,
| | ^~~
| | |
| | struct v4l2_subdev_pad_config *
| In file included from os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/drivers/media/platform/xilinx/xilinx-vfake.c:9:
| os/petalinux/build/tmp/work-shared/zynqmp-generic/kernel-source/include/media/v4l2-subdev.h:999:54: note: expected 'struct v4l2_subdev_state *' but argument is of type 'struct v4l2_subdev_pad_config *'
| 999 |
Assistant
Based on the compilation messages you've provided, it appears that the signature of the v4l2_subdev_get_try_format function has changed between the Petalinux 2019 and Petalinux 2022 versions. The function now expects a struct v4l2_subdev_state * as its second argument, instead of a struct v4l2_subdev_pad_config *.
To resolve these errors, you'll need to modify your driver code to pass the correct type of argument to the v4l2_subdev_get_try_format function. This will likely involve more changes to your code than just fixing the function calls, as you may need to handle the pad configuration differently with the new API.
Without access to the exact changes in the V4L2 API between the two versions of Petalinux, I can only suggest a general approach to updating your driver. Here's a starting point to address the error:
Replace struct v4l2_subdev_pad_config *cfg with struct v4l2_subdev_state *state in function signatures and calls.
Update the function calls to v4l2_subdev_get_try_format to use the new state argument instead of the old cfg argument.
Review any other V4L2 API changes that may impact your code and update accordingly.
For example, here's how you might begin updating the xvfake_enum_frame_size function:
C
static int xvfake_enum_frame_size(struct v4l2_subdev *subdev,
struct v4l2_subdev_state *state, // Updated argument type
struct v4l2_subdev_frame_size_enum *fse)
{
struct v4l2_mbus_framefmt *format;
// Here you'll need to obtain the correct state structure for the pad configuration.
// This may involve using the v4l2_subdev_state structure and its associated functions.
// Since I don't have the updated V4L2 API documentation, I can't provide the exact code.
// However, it might look something like this (you will need to confirm the correct usage):
format = v4l2_subdev_get_try_format(subdev, state, fse->pad);
if (fse->index || fse->code != format->code)
{
return -EINVAL;
}
fse->min_width = XVIP_MIN_WIDTH;
fse->max_width = XVIP_MAX_WIDTH;
fse->min_height = XVIP_MIN_HEIGHT;
fse->max_height = XVIP_MAX_HEIGHT;
return 0;
}
Please note that the above code is a starting point and will require further modifications based on the updated V4L2 API. You'll need to refer to the updated V4L2 API documentation or the kernel source code to determine the correct usage of the updated functions and structures.
If you do not have access to the updated documentation, you could review the kernel source code for other drivers that have been updated for the new API, or consult the Linux kernel mailing list or forums where kernel developers discuss such changes.