buildroot_我如何在Buildroot中修复杯子打印

buildroot

image

介绍 (Intro)

Like I said earlier in previos articles, Buildroot is a great system for embedded Linux development. But sometimes strange things can happen.

就像我之前在previos文章中所说的那样,Buildroot是用于嵌入式Linux开发的出色系统。 但有时可能会发生奇怪的事情。

Once upon a workday, I got the following task: add printing system in firmware (Kraftway terminal Linux next generation). Ok, so I had to add cups + cups filter and to build firmware. I set a postscript-printer and got an error "Filter failed". Trivial tasks turned into serious work.

在一个工作日,我完成了以下任务:在固件中添加打印系统(下一代Kraftway终端Linux)。 好的,所以我必须添加杯子+杯子过滤器并构建固件。 我设置了一个后置打印机,并收到一个错误“过滤器失败”。 琐碎的任务变成了严肃的工作。

In this article, I wrote my own way of solving this problem. It may be useful for other developers and IT-specialist and, also, for a deeper understanding of the Buildroot.

在本文中,我写了解决该问题的方法。 它可能对其他开发人员和IT专家很有用,对于深入了解Buildroot也可能有用。

If you are a Buildroot beginner, I recommend reading my previous articles.

如果您是Buildroot的初学者,建议您阅读以前的文章

2020年5月1日更新 (Update 1 may 2020)

Revisioned versions of this patches applied to master.

此修补程序的修订版适用于母版。

了解Linux中的打印系统 (Understanding of the printing system in Linux)

First of all, CUPS is not an ALL-IN-ONE printing solution. Below, I wrote a simple printing schema:

首先,CUPS不是万能的打印解决方案。 下面,我编写了一个简单的打印模式:

  • application sends user file (pdf,txt,jpeg, other) to CUPS

    应用程序将用户文件(pdf,txt,jpeg等)发送到CUPS
  • CUPS transforms user file to internal PDF (via QPDF)

    CUPS将用户文件转换为内部PDF(通过QPDF)
  • CUPS selects needed filters and sends PDF to them

    CUPS选择所需的过滤器并将PDF发送给它们
  • filters transform PDF to printer format:

    过滤器将PDF转换为打印机格式:

    • ghostscript uses freetype for font rendering

      ghostscript使用freetype进行字体渲染
    • gilters use image libs(libjpeg,libpng) for image rendering

      烫手使用图像库(libjpeg,libpng)进行图像渲染
  • filters send printer-ready data to backend

    过滤器将打印机就绪的数据发送到后端
  • backend(lpd,smb,usb,etc) sends data to printer

    后端(lpd,smb,usb等)将数据发送到打印机

Ghostscript may be replaced with another render (like Poppler), but I use this schema. Filters depend on the printer manufacturer.The full printing system schema is more complex. But this one is simple enough to understand the article.

Ghostscript可以替换为另一个渲染器(例如Poppler),但是我使用这种模式。 过滤器取决于打印机制造商。完整的打印系统架构更为复杂。 但这很简单,足以理解本文。

步骤1。 网页界面 (Step one. Web interface)

"Ok", — said I, rolling up my sleeves.

“好”,我说,卷起袖子。

Buildroot has a 'target finalize' stage that cleans unnecessary files such as mans, docs, and others. Our target is bigger and more complex, so I'll show only the first 10 lines:

Buildroot有一个“目标确定”阶段,该阶段可以清除不必要的文件,例如mans,docs等。 我们的目标更大更复杂,因此我仅显示前10行:

alexey@comp:~/test/article/buildroot$ grep -n '.PHONY: target-finalize' -A 10 Makefile
743:.PHONY: target-finalize
744-target-finalize: $(PACKAGES) $(TARGET_DIR) host-finalize
745-    @$(call MESSAGE,"Finalizing target directory")
746-    $(call per-package-rsync,$(sort $(PACKAGES)),target,$(TARGET_DIR))
747-    $(foreach hook,$(TARGET_FINALIZE_HOOKS),$($(hook))$(sep))
748-    rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/share/aclocal \
749-        $(TARGET_DIR)/usr/lib/pkgconfig $(TARGET_DIR)/usr/share/pkgconfig \
750-        $(TARGET_DIR)/usr/lib/cmake $(TARGET_DIR)/usr/share/cmake
751-    find $(TARGET_DIR)/usr/{lib,share}/ -name '*.cmake' -print0 | xargs -0 rm -f
752-    find $(TARGET_DIR)/lib/ $(TARGET_DIR)/usr/lib/ $(TARGET_DIR)/usr/libexec/ \
753-        \( -name '*.a' -o -name '*.la' \) -print0 | xargs -0 rm -f

CUPS has a special directory, which contains a web interface file. By default, the location of CUPS documents directory resides in /usr/share/doc, but this path is cleaned by Buildroot on the target-finalize stage, on image-build. I will use cups.css as a detector of the CUPS doc-dir path. This file is part of the CUPS web interface.

CUPS有一个特殊的目录,其中包含一个Web界面文件。 缺省情况下,CUPS文档目录的位置位于/ usr / share / doc中,但是Buildroot在image-build的target-finalize阶段会清除此路径。 我将使用cups.css作为CUPS doc-dir路径的检测器。 该文件是CUPS Web界面的一部分。

Let's build the full system:

让我们构建完整的系统:

alexey@comp:~/test/article/buildroot$ find output/ -iname cups.css
output/host/x86_64-buildroot-linux-gnu/sysroot/usr/share/doc/cups/cups.css
output/build/cups-2.3.1/doc/cups.css

As you can see, no style.css is present in ${TARGET_DIR} because buildroot remove them:

如您所见,$ {TARGET_DIR}中没有style.css,因为buildroot删除了它们:

And some lines later:

还有一些行:

765: rm -rf $(TARGET_DIR)/usr/doc $(TARGET_DIR)/usr/share/doc
765:rm -rf $ {TARGET_DIR)/ usr / doc $ {TARGET_DIR)/ usr / share / doc

Let's rebuild cups without image create (make cups-rebuild command):

让我们重建不创建图像的杯子(make cups-rebuild命令):

alexey@comp:~/test/article/buildroot$ find output/ -iname cups.css
output/target/usr/share/doc/cups/cups.css
output/host/x86_64-buildroot-linux-gnu/sysroot/usr/share/doc/cups/cups.css
output/build/cups-2.3.1/doc/cups.css

I wrote a short patch that moves this directory to /usr/share. This patch was applied to the Buildroot master(since 2020.02 version).

我写了一个简短的补丁程序 ,将该目录移至/ usr / share。 此修补程序已应用于Buildroot主版本(从2020.02版本开始)。

第二步。 QPDF —Undertow战士 (Step two. QPDF — shadow warrior)

QPDF is used in CUPS for internal file converting, and it's a required dependence for cups. Using trace and cups error-log, I’ve founded a strange message:

CUPS中使用QPDF进行内部文件转换,这是杯子的必需依赖项。 使用跟踪和杯子错误日志,我发现了一条奇怪的消息:

access ("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
访问(“ /etc/ld.so.preload”,R_OK)= -1 ENOENT(无此类文件或目录)

I tested how it works and found a problem:

我测试了它的工作原理并发现了一个问题:

$ file  /usr/share/cups/data/secret.pdf
/usr/share/cups/data/secret.pdf: PDF document, version 1.2

$ qpdf  /usr/share/cups/data/secret.pdf -
open (): No such file or directory

I tested this command on my desktop with Linux Mint and got a normal result:

我使用Linux Mint在桌面上测试了此命令,并得到了正常结果:

alexey@comp:~/Downloads$ file /usr/share/cups/data/secret.pdf
/usr/share/cups/data/secret.pdf: PDF document, version 1.2
alexey@comp:~/Downloads$ qpdf /usr/share/cups/data/secret.pdf - |head
%PDF-1.2
%����
1 0 obj
<< /Pages 3 0 R /Type /Catalog >>
endobj
2 0 obj
<< /CreationDate (D:20140612184736+02'00') /ModDate (D:20140612184736+02'00') /Producer (GPL Ghostscript 9.14) >>
endobj
3 0 obj
<< /Count 1 /Kids [ 4 0 R ] /Type /Pages >>

So looks like the problem is in QPDF build. I've studied the package file (package/QPDF/QPDF.mk) and found strange option '--without-random'

因此,看起来问题出在QPDF版本中。 我研究了打包文件(package / QPDF / QPDF.mk),发现了奇怪的选项'--with-and-random'

alexey@comp:~/test/article/buildroot$ head -n 15 package/QPDF/QPDF.mk
################################################################################
#
# QPDF
#
################################################################################

QPDF_VERSION = 9.1.1
QPDF_SITE = http://downloads.sourceforge.net/project/qpdf/qpdf/$(QPDF_VERSION)
QPDF_INSTALL_STAGING = YES
QPDF_LICENSE = Apache-2.0 or Artistic-2.0
QPDF_LICENSE_FILES = LICENSE.txt Artistic-2.0
QPDF_DEPENDENCIES = host-pkgconf zlib jpeg

QPDF_CONF_OPTS = --without-random

Next, I checked the available conf option:

接下来,我检查了可用的conf选项:

alexey@comp:~/test/article/buildroot$ ./output/build/qpdf-9.1.1/configure --help |grep random
  --enable-insecure-random
                          whether to use stdlib's random number generator
  --enable-os-secure-random
                          whether to try to use OS-provided secure random
  --with-random=FILE      Use FILE as random number seed [auto-detected]

While I didn't find these options, I found another one "--with-random=". After that, I wrote a simple patch, rebuilt QPDF and got proper qpd work. This patch replaces "with-random" option with "--with-random=/dev/urandom" So, minus one problem on my way.

虽然没有找到这些选项,但我找到了另一个“ --with-random =”。 之后, 我编写了一个简单的补丁程序 ,重新构建了QPDF并进行了适当的qpd工作。 该补丁将“ with-random”选项替换为“ --with-random = / dev / urandom”。因此,消除了我遇到的一个问题。

第三步 杯子过滤器和Ghostscript (Step three. Cups-filters and Ghostscript)

CUPS-filters are needed to transform CUPS internal representation to printer-ready format. They depend on the printer model. But CUPS-FILTER (early known as foomatic) is a good collection of different printer filters, especially for a generic-like printer (generic-pdf, generic-postscript, and other).

需要CUPS过滤器才能将CUPS内部表示转换为打印机就绪格式。 它们取决于打印机型号。 但是CUPS-FILTER(以前称为foomatic)可以很好地收集不同的打印机过滤器,尤其是对于通用打印机(generic-pdf,generic-postscript等)。

These are the important strings in the cups-filters readme:

这些是cups-filters自述文件中的重要字符串:

For compiling and using this package CUPS, libqpdf (8.3.0 or newer), libjpeg, libpng, libtiff, freetype, font-tconfig, liblcms (liblcms2 recommended), libavahi-common, libavahi-client, libdbus, and glib are needed. It is highly recommended, especially if non-PDF printers are used, to have at least one of Ghostscript, Poppler, or MuPDF.
为了编译和使用此软件包,需要CUPS,libqpdf(8.3.0或更高版本),libjpeg,libpng,libtiff,freetype,font-tconfig,liblcms(建议使用liblcms2),libavahi-common,libavahi-client,libdbus和glib。 强烈建议(至少在使用非PDF打印机的情况下)使用Ghostscript,Poppler或MuPDF中的至少一种。

OK, I chose Ghostscript:

好的,我选择了Ghostscript:

Ghostscript has better color management and is generally optimized more for printing.
Ghostscript具有更好的色彩管理,并且通常针对打印进行了更多优化。

Now, let's look at the cups-filters package file (package/cups-filters/cups-filters.mk):

现在,让我们看一下cups-filters软件包文件(package / cups-filters / cups-filters.mk):

head -n 21 package/cups-filters/cups-filters.mk
################################################################################
#
# cups-filters
#
################################################################################

CUPS_FILTERS_VERSION = 1.26.0
CUPS_FILTERS_SITE = http://openprinting.org/download/cups-filters
CUPS_FILTERS_LICENSE = GPL-2.0, GPL-2.0+, GPL-3.0, GPL-3.0+, LGPL-2, LGPL-2.1+, MIT, BSD-4-Clause
CUPS_FILTERS_LICENSE_FILES = COPYING

CUPS_FILTERS_DEPENDENCIES = cups libglib2 lcms2 qpdf fontconfig freetype jpeg

CUPS_FILTERS_CONF_OPTS = --disable-imagefilters \
    --disable-mutool \
    --disable-foomatic \
    --disable-braille \
    --with-cups-config=$(STAGING_DIR)/usr/bin/cups-config \
    --with-sysroot=$(STAGING_DIR) \
    --with-pdftops=pdftops \
    --with-jpeg

First, I add selected Ghostscript support by adding "--with-pdftops"; select depends on Ghostscript: if enabled — add the dependency for the current build:

首先,我通过添加“ --with-pdftops”来添加选定的Ghostscript支持; 选择取决于Ghostscript:如果启用-添加当前构建的依赖项:

ifeq ($(BR2_PACKAGE_GHOSTSCRIPT),y)
CUPS_FILTERS_CONF_OPTS += --with-pdftops=gs
CUPS_FILTERS_DEPENDENCIES += ghostscript
else
CUPS_FILTERS_CONF_OPTS += --with-pdftops=pdftops
endif

Also, I added image printing (such as jpeg) support by removing " --disable-imagefilters" from config options. After that, cups-filters began to use Ghostscript as the default render.

另外,我通过从配置选项中删除“ --disable-imagefilters”,添加了图像打印(例如jpeg)支持。 之后,cups-filters开始使用Ghostscript作为默认渲染。

This patch is submitted, but I don't have any response, and it's not applied to buildroot.

该补丁已提交 ,但我没有任何回应,它也不适用于buildroot。

第四步。 Ghostscript + CUPS =爱 (Step four. Ghostscript + CUPS = love)

In reality, this step parallels with step 4. And it's the hardest work in this task.

实际上,此步骤与步骤4并行。这是此任务中最艰巨的工作。

alexey@comp:~/test/article/buildroot$ grep cups  package/ghostscript/ghostscript.mk
    --disable-cups \

Ghostscript is built without cups-support! I thought it's a mistake, but it's true! I added cups support:

Ghostscript的构建无需杯子支持! 我以为是错误的,但这是真的! 我添加了杯子支持:

GHOSTSCRIPT_DEPENDENCIES += cups

GHOSTSCRIPT_DEPENDENCIES + =杯子

GHOSTSCRIPT_PRE_CONFIGURE_HOOKS += GHOSTSCRIPT_CUPS_CONFIG_FIX

GHOSTSCRIPT_PRE_CONFIGURE_HOOKS + = GHOSTSCRIPT_CUPS_CONFIG_FIX

GHOSTSCRIPT_CONF_OPTS += --enable-cups

GHOSTSCRIPT_CONF_OPTS + =-启用杯子

else

其他

GHOSTSCRIPT_CONF_OPTS += --disable-cups

GHOSTSCRIPT_CONF_OPTS + =-禁用杯

endif

万一

Easy, but it doesn't help:

容易,但这无济于事:

gs --help| grep -i cups
/usr/share/cups/fonts : /usr/share/ghostscript/fonts :

And I didn’t see the cup device support. But on my Mint:

而且我没有看到杯子设备的支持。 但是在我的薄荷糖上:

alexey@comp:~/test/article/buildroot$ gs --help |grep -i cups
   chp2200 cif cljet5 cljet5c cljet5pr coslw2p coslwxl cups declj250 deskjet
   /usr/share/cups/fonts : /usr/share/ghostscript/fonts :

I read Ghostscript build config and found that configure does not find cups. I opened Ghostscript configure.ac file and found something interesting:

我阅读了Ghostscript构建配置,发现配置找不到杯子。 我打开了Ghostscript configure.ac文件,发现了一些有趣的东西:

# this is an unpleasant hack
# but if we are cross compiling, and there isn't a matching
# pkconfig for the --host setting, then don't use the 'local'
# pkconfig at all
if test x"$cross_compiling" = x"yes"; then
  AC_PATH_PROG(BUILD_PKGCONFIG, pkg-config)
  if test x"$BUILD_PKGCONFIG" = x"$PKGCONFIG" ; then
    PKGCONFIG=
  fi
fi

It seems that the author of the Ghostscript check used cross-compile. Buildroot uses cross-compile, but it uses its own PATH and other environments to prevent using build-machine utils inside of toolchain. And this hack does not work properly. Also, an equivalent hack is used for cups-config and strip_xe:

Ghostscript检查的作者似乎使用了交叉编译。 Buildroot使用交叉编译,但是它使用自己的PATH和其他环境来防止在工具链内部使用构建计算机工具。 并且此hack无法正常工作。 同样,cups-config和strip_xe也使用了等效的hack:

AC_PATH_TOOL(CUPSCONFIG,cups-config)
        if test x"$cross\_compiling" = x"yes"; then
                AC_PATH_PROG(BUILD_CUPSCONFIG, cups-config)
                if test x"$BUILD_CUPSCONFIG" = x"$CUPSCONFIG" ; then
                        CUPSCONFIG=
                fi
              fi

I wrote a patch to remove this hack, and pkg-config started to work fine. [Full patch is submitted (http://lists.busybox.net/pipermail/buildroot/2020-May/281749.html), but I have no response, and it's not applied. Also, copy cups-config to $(HOST_DIR)/usr/bin/ because pkg-config search in this dir.

我写了一个补丁删除了这个黑客,然后pkg-config开始正常工作。 [已提交完整补丁( http://lists.busybox.net/pipermail/buildroot/2020-May/281749.html ),但我没有任何回应,因此未应用。 另外,将cups-config复制到$(HOST_DIR)/ usr / bin /,因为pkg-config在该目录中搜索。

Proper pkg-config's work resolves the problem with Freetype. Freetype is the default font render for Ghostscript. Without it, cups won't print normal text page — only blank space instead of text and images.

正确的pkg-config可以解决Freetype的问题。 Freetype是Ghostscript的默认字体渲染。 如果没有它,杯子将无法打印正常的文本页面,只能打印空白区域,而不是文本和图像。

而不是结论 (Instead of conclusion)

Of course, I lost a lot of time before I found all these problems and fixed them. Yes, I understand that Buildroot, QPDF, cups, Ghostscript are opensource software, and I want to say "Thank you" to their developers and maintainers.

当然,在发现所有这些问题并将其修复之前,我浪费了很多时间。 是的,我知道Buildroot,QPDF,cups,Ghostscript是开源软件,我想对他们的开发人员和维护人员说“谢谢”。

I hope that the Buildroot-community will apply all of my patches. If not, everyone can read this article and get patches from the Buildroot mailing lists.

我希望Buildroot社区可以应用我的所有补丁。 如果没有,那么每个人都可以阅读本文并从Buildroot邮件列表中获取补丁。

翻译自: https://habr.com/en/post/498764/

buildroot

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值