使用最新 ALSA 驱动解决 Ubuntu Linux Intel 集成声卡问题

目前用户所抱怨的 Ubuntu 系列的声卡问题,基本上归结为几类:一,找不到声音设备;二,不发声;三,耳机和音箱同时发声;四、话筒没声。大部分这种问题都是由笔记本上 Intel 集成声卡驱动引起的,关于这个问题的具体描述和解决方案,可以查看下面两个页面:

BUG:
https://bugs.launchpad.net/ubuntu/+source/linux-source-2.6.22/+bug/131133

SOLUTION:
https://wiki.ubuntu.com/Gutsy_Intel_HD_Audio_Controller

其实大部分问题都可以通过自己动手编译安装最新 ALSA 驱动解决,解决方法上面两个链接中已经解释得很清楚了,我这里介绍一下我的思路:

第一,查看 ALSA 版本,如果最新,就不用重新安装了,仔细查看一下配置吧。

$ alsactl -v

如果打印出: alsactl version 1.0.20,那么 ALSA 已经是最新了。

第二,在 ALSA 官方网站 http://www.alsa-project.org 上,下载最新的 ALSA 驱动,怎么解压我就不说了吧。

$ wget ftp://ftp.alsa-project.org/pub/driver/alsa-driver-1.0.20.tar.bz2
$ wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.0.20.tar.bz2
$ wget ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.0.20.tar.bz2

第三,查看自己的内核版本和声卡解码芯片是否被支持。
查看支持的内核版本

$ less alsa-driver-1.0.15/SUPPORTED_KERNELS

查看自己声卡解码芯片(如果系统不能识别声卡,可能无法由下面两个查到,那么查看你电脑配置单吧)

$ tail -2 /proc/asound/oss/sndstat

$ head -1 /proc/asound/card0/codec#0

比如我的 DELL D630 就显示的是下面这个

Codec: SigmaTel STAC9205

在 alsa-driver-1.0.20/sound/Documentation/ALSA-Configuration.txt 中查找自己声卡解码芯片对应的 model 名字,比如我的 STAC9205 对应的就是:

STAC9205/9254
ref Reference board
dell-m42 Dell (unknown)
dell-m43 Dell Precision
dell-m44 Dell Inspiron

如果存在对应的 model,恭喜你可以继续安装了。

第四,准备好编译环境,安装 gcc, libc 等等工具,还需要下载 Linux header,这是编译 ALSA 驱动必须的。

$ sudo apt-get install build-essential linux-headers-2.x.xx-xx(你的内核版本)

第五,编译安装,一般的 ./configure, make, make install 流程。注意的是驱动编译时候需要 module 名字,就是第三步中找到的 modle 对应的 module 名字,去掉 snd-即可。比如我的 STAC9205 对应的 modle 是 dell-m44,对应的 module 是 snd-hda-intel,那么 configure 时候需要加上 --with-cards=hda-intel。编译安装时遇到问题请仔细阅读源码附带的 INSTALL。

$ cd alsa-driver-1.0.15
$ ./configure --with-cards=MODULE_NAME
$ make
$ sudo make install
$ cd ../alsa-lib-1.0.15
$ ./configure
$ make
$ sudo make install
$ cd ../alsa-utils-1.0.15
$ ./configure
$ make
$ sudo make install

第六,配置 ALSA。
如果以前系统中没有使用 ALSA 驱动,可能需要 alsaconf 来配置,还要将 ALSA 加入内核模块中,我没有经验;
如果系统原来已经有 ALSA 驱动,但是没有识别声卡或者声音驱动有问题。那么理论上只需要在两个地方做改动:

添加 /etc/modprobe.d/sound 文件,内容为:

alias snd-card-0 snd-MODULE_NAME
alias snd-slot-0 snd-MODULE_NAME

比如我的就是:

alias snd-card-0 snd-hda-intel
alias sound-slot-0 snd-hda-intel

在 /etc/modprobe.d/alsa-base 中最后一行添加:

options snd-MODULE_NAME model=MODEL_NAME

比如我的就是:

options snd-hda-intel model=dell-m44

第七,重新启动查看效果,可以使用 alsamixer 调节声音设置。

其它都好,话筒没声
如果您已经安装了 alsa 驱动,话筒没声的问题可以通过设置解决。命令行输入 alsamixer:
1. Digital 那列,设置为 Analog I。
2. 点击 tab 制表键,在第一个 Capture 上点空格,显示出来红色的 "Capture, LR"字样表示选中,并把音量设置为 0。
3. Digital 那列,将音量设置为 67,这样能减少杂音。

由于各种各样的问题,比如 ALSA 驱动重复安装,内核版本,内核模块添加不全等等,本文并不保证能完美解决声卡问题。本人不是声卡驱动专家,本文只是阐述我解决声卡问题的做法,如果您在本文指导下仍然不能解决声卡问题,请您到熟悉的论坛上寻求帮助。请尽量不要发邮件给我,谢谢。

编译一个软件要花多长时间?

不知道现在世界上有多少人正坐在电脑前,等待着编译结束。如果把所有的软件按照规模来排名的话,编译器至少应该在最大那一批的角落里,想想自己动手编译 GNU 工具链需要的时间吧!难怪有人抗议说 gcc 应该附带音乐以便编译时候打发时间 ^_^

但是还有比 gcc 更变态的,就比如 Open64(原为 SGIPro64,开源后叫 Open64,Intel 和中科院改的叫 ORC,Pathscale 改的叫 EkoPath,特拉华大学改的叫 KylinC),Open64 前端使用的是修改后的 gcc,然后对生成的 WHIRL 文件进行处理,生成 .s 文件再让 as 去汇编。在编译 Open64 时什么稀奇古怪的问题都可能出来,最主要的原因可能是 gcc, binutils 源代码版本不对应,或者只能使用某个版本的 gcc 去编译,某个版本的 ld 去连接。看看 Open64 中的源代码就可以发现,什么风格的代码都有,gcc 的代码可能是 K&R 的,也可能是 ANSI 的,有 C 风格的 C++,还有数不清的 csh,代码的混乱程度比 gcc 有过之而无不及,warning 一大堆,我每次都奇怪它是如何编译过去的。

我没有具体计算过 Open64 的编译时间,但是从感觉上来看,如果全部编译的话,Open64 至少需要一个小时(双核3.4G,2G内存)。平常我改编译器的源代码,最多的就是改 Dwarf 相关的调试信息输出。GNU make 会增量构建,改个 c/cxx 问题还不大,顶多重编一下模块,我最怕的就是改动哪个头文件。因为如果动了头文件,尤其是那种比较关键的头文件,就意味这下面一个小时就等编译结果吧。

一般情况下 make 的逻辑是:如果源文件被更新,只需要重编这个文件生成目标文件,然后用其重新构建可执行文件;如果头文件被更新,那么所有依赖此头文件的源文件都要被重新编译。这个依赖关系是写在 Makefile 中的,为了避免无谓的重编译,一定要在 Makefile 中确定正确的依赖关系。而这个依赖关系的依据是程序中头文件的包含关系和模块之间的联系,所以在写程序时一定要谨慎地选择包含头文件。多 include 一个头文件,错误地声明一个全局变量,都会造成程序的臃肿。

其实在这一点上 GNU 的东西做得就比较不错,头文件的包含,文件的依赖关系都很清楚,而且本身做为 Linux 下的程序员来说,了解依赖关系就是理解 Makefile 的第一步。相比而言 Windows 程序员就差很多,Win 程序员太依赖 IDE(集成开发环境) 了,没有 IDE 什么都干不了。经常有人问 Linux 下没有 VC,那怎么写程序?天那,比 VC 优秀的编译器有很多,而且没有图形界面不意味着写不出图形界面的程序,VC 编译程序也是调用命令行的。VC 的编译器叫做 CL, 连接器叫做 LINK,VC 也有 make,叫做 NMAKE。不相信的人可以尝试一下:如果你安装了 VC 并且选择了将 VC 可执行文件路径加入到环境变量里,那么就可以用 CL hello.cpp 来编译你的 hello world 程序,根本没有必要为了一个单文件的命令行程序创建一个工程。

Linux 并不拒绝 IDE,从 Eclipse 的流行可以看到这一点,但是不要让 IDE 把程序员变傻。如果不了解程序编译的整个过程和逻辑,那么写程序就成了一件盲目的事情。很多 VC 的程序员都不能区分什么是 assembly file, object file, executable file,什么是 preprocess,一个程序的源文件是怎么组织起来的,最终的二进制文件是怎样生成的。他们所知道的就是把一个文件往工程里一拉,乱七八糟的头文件一包含,就希望程序能编译过去。一旦遇到问题,马上抱怨怎么报那么多错误,就算很明显的错误也要到论坛上叽叽歪歪一番,怎么能期望得到一个可靠又高效的程序呢?

从 VC 自动生成的源程序来看,本身就有很多问题,就拿 VC 自动生成的类来说,鲜有 private 类型的成员变量和方法,大多数都是 public 或者 protect 了事,因为这样它不容易出错。但是这样一来 C++ 面向对象的特性又去哪儿了?MFC 里一堆一堆的宏,又如何了解真正的 API?

IDE 仅仅是一个加强版的文本编辑器,它提供的功能是高效写代码,但需要程序员自己保证写高效的代码!

细节很重要!

Hacking 《自己动手写操作系统》Chapter 4

——Writing x86 PC Bootloader With Free Software 2

本文内容已被整理为一本电子书,请到这里下载

强烈建议随《自己动手写操作系统》这本书读本篇文章,基础知识:x86 汇编指令,AT&T 汇编格式,FAT12 文件系统格式。

由于《自己动手写操作系统》第三章讲的是保护模式,示例代码全是 DOS 可执行代码,和直接的 Bootloader 没有太大关系,所以这次继续下来从第四章开始。

前两章中写的 Bootloader 其实严格意义上只算是一个 Boot sector(扇区),因为它只是简单地打印了一个字符。第四章的 Bootloader 实现了从软盘中读写一个文件并加载运行的功能。

总共有以下几个文件:boot.S loader.S solrex_x86_boot.ld solrex_x86_dos.ld Makefile

下面解释每个文件的作用:
boot.S:
它生成的 .bin 文件就是软盘镜像的第一个扇区。由上一篇文章提供的 boot.S 只有启动功能,生成的软盘镜像文件只能作为启动器而不能作为可读写软盘来使用,因为在那个镜像里面没有将软盘格式化。其实格式化说白了就是在软盘的第一个扇区添加一些头信息,这样系统就知道如何处理这张软盘,在 boot.S 中的 Floppy header 就是做这个工作的。而在软盘的前 3 个 byte 是一句跳转指令,这样在启动时候系统会跳过 floppy header,也解决了如何启动的问题。这样这张软盘既可以作为启动盘,又可以作为文件盘使用了。因为启动扇区只有 512 个字节,不可能依赖它作为启动功能,这样我们可以将另一个程序 LOADER.BIN 放入软盘,启动后,从软盘读取它进入内存并执行。

所以 boot.S 代码的主要内容是,首先将软盘主目录复制到内存中,并在其中搜索 LOADER.BIN,搜索到以后,将 LOADER.BIN 加载入内存并执行。

loader.S:
就是一个普通的打印程序,在屏幕第一行中间打印一个 'L'

solrex_x86_boot.ld:
boot.S 的连接脚本,将 boot.S 代码段连接到 0x7c00 的位置(x86 PC 操作系统启动的位置)。

solrex_x86_dos.ld:
loader.S 的连接脚本,将 loader.S 代码段连接到 0x1000 的位置,和普通 DOS 程序一样。

Makefile:
不说了,大家都知道。

这个 hacking 系列我准备继续写下去,示例代码可以从我的个人主页 http://solrex.org 打包下载,包括《自己动手写操作系统》的部分源代码,以 .asm 为后缀。对 Intel(MASM,NASM,TASM) 和 AT&T(GAS)汇编语言语法在 x86 平台的实现如何转换感兴趣的朋友,可以对比阅读 .asm 和 .S 文件。

[solrex@NJU-CAS Solrex]$ more boot.S loader.S solrex_x86_boot.ld solrex_x86_dos.ld Makefile
::::::::::::::
boot.S
::::::::::::::
.code16
.set BaseOfStack, 0x7c00 /* Stack base address, inner */
.set BaseOfLoader, 0x9000 /* Section loading address of LOADER.BIN */
.set OffsetOfLoader, 0x0100 /* Loading offset of LOADER.BIN */
.set RootDirSectors, 14 /* Root directory sector count */
.set SecNoOfRootDir, 19 /* 1st sector of root directory */
.set SecNoOfFAT1, 1 /* 1st sector of FAT1 */
.set DeltaSecNo, 17 /* BPB_(RsvdSecCnt+NumFATs*FATSz) -2 */
/* Start sector of file space =*/
.text
/* Floppy header of FAT12 */
jmp LABEL_START /* Start to boot. */
nop /* nop required */
BS_OEMName: .ascii "WB. YANG" /* OEM String, 8 bytes required */
BPB_BytsPerSec: .2byte 512 /* Bytes per sector */
BPB_SecPerCluse: .byte 1 /* Sector per cluse */
BPB_ResvdSecCnt: .2byte 1 /* Reserved sector count */
BPB_NumFATs: .byte 2 /* Number of FATs */
BPB_RootEntCnt: .2byte 224 /* Root entries count */
BPB_TotSec16: .2byte 2880 /* Total sector number */
BPB_Media: .byte 0xf0 /* Media descriptor */
BPB_FATSz16: .2byte 9 /* FAT size(sectors) */
BPB_SecPerTrk: .2byte 18 /* Sector per track */
BPB_NumHeads: .2byte 2 /* Number of magnetic heads */
BPB_HiddSec: .4byte 0 /* Number of hidden sectors */
BPB_TotSec32: .4byte 0 /* If TotSec16 equal 0, this works */
BS_DrvNum: .byte 0 /* Driver number of interrupt 13 */
BS_Reserved1: .byte 0 /* Reserved */
BS_BootSig: .byte 0x29 /* Boot signal */
BS_VolID: .4byte 0 /* Volume ID */
BS_VolLab: .ascii "Solrex 0.01" /* Volume label, 11 bytes required */
BS_FileSysType: .ascii "FAT12 " /* File system type, 8 bytes required */

/* Initial registers. */
LABEL_START:
mov %cs,%ax
mov %ax,%ds
mov %ax,%es
mov %ax,%ss
mov $BaseOfStack, %sp

/* Clear screen */
mov $0x0600,%ax /* %ah=6, %al=0 */
mov $0x0700,%bx /* Black white */
mov $0,%cx /* Top left: (0,0) */
mov $0x184f,%dx /* Bottom right: (80,50) */
int $0x10 /* BIOS int 10h, ah=6: Initialize screen */

/* Display "Booting**" */
mov $0,%dh
call DispStr /* Display string(index 0)*/

/* Reset floppy */
xor %ah,%ah
xor %dl,%dl /* %dl=0: floppy driver 0 */
int $0x13 /* BIOS int 13h, ah=0: Reset driver 0 */

/* Find LOADER.BIN in root directory of driver 0 */
movw $SecNoOfRootDir, (wSectorNo)

/* Read root dir sector to memory */
LABEL_SEARCH_IN_ROOT_DIR_BEGIN:
cmpw $0,(wRootDirSizeForLoop) /* If searching in root dir */
jz LABEL_NO_LOADERBIN /* can find LOADER.BIN ? */
decw (wRootDirSizeForLoop)
mov $BaseOfLoader,%ax
mov %ax,%es /* %es <- BaseOfLoader*/
mov $OffsetOfLoader,%bx /* %bx <- OffsetOfLoader */
mov (wSectorNo),%ax /* %ax <- sector number in root */
mov $1,%cl
call ReadSector
mov $LoaderFileName,%si /* %ds:%si -> LOADER BIN */
mov $OffsetOfLoader,%di /* BaseOfLoader<<4+100*/
cld
mov $0x10,%dx

/* Search for "LOADER BIN", FAT12 save file name in 12 bytes, 8 bytes for
file name, 3 bytes for suffix, last 1 bytes for '20'. If file name is
less than 8 bytes, filled with '20'. So "LOADER.BIN" is saved as:
"LOADER BIN"(4f4c 4441 5245 2020 4942 204e).
*/
LABEL_SEARCH_FOR_LOADERBIN:
cmp $0,%dx /* Read control */
jz LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR
dec %dx
mov $11,%cx

LABEL_CMP_FILENAME:
cmp $0,%cx
jz LABEL_FILENAME_FOUND /* If 11 chars are all identical? */
dec %cx
lodsb /* %ds:(%si) -> %al*/
cmp %es:(%di),%al
jz LABEL_GO_ON
jmp LABEL_DIFFERENT /* Different */

LABEL_GO_ON:
inc %di
jmp LABEL_CMP_FILENAME /* Go on loop */

LABEL_DIFFERENT:
and $0xffe0,%di /* Go to head of this entry */
add $0x20,%di
mov $LoaderFileName,%si /* Next entry */
jmp LABEL_SEARCH_FOR_LOADERBIN

LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR:
addw $1,(wSectorNo)
jmp LABEL_SEARCH_IN_ROOT_DIR_BEGIN

/* Not found LOADER.BIN in root dir. */
LABEL_NO_LOADERBIN:
mov $2,%dh
call DispStr /* Display string(index 2) */
jmp . /* Infinite loop */

/* Found. */
LABEL_FILENAME_FOUND:
mov $RootDirSectors,%ax
and $0xffe0,%di /* Start of current entry, 32 bytes per entry */
add $0x1a,%di /* First sector of this file */
mov %es:(%di),%cx
push %cx /* Save index of this sector in FAT */
add %ax,%cx
add $DeltaSecNo,%cx /* LOADER.BIN's start sector saved in %cl */
mov $BaseOfLoader,%ax
mov %ax,%es /* %es <- BaseOfLoader */
mov $OffsetOfLoader,%bx /* %bx <- OffsetOfLoader */
mov %cx,%ax /* %ax <- Sector number */

/* Load LOADER.BIN's sector's to memory. */
LABEL_GOON_LOADING_FILE:
push %ax
push %bx
mov $0x0e,%ah
mov $'.',%al /* Char to print */
mov $0x0f,%bl /* Front color: white */
int $0x10 /* BIOS int 10h, ah=0xe: Print char */
pop %bx
pop %ax

mov $1,%cl
call ReadSector
pop %ax /* Got index of this sector in FAT */
call GetFATEntry
cmp $0x0fff,%ax
jz LABEL_FILE_LOADED
push %ax /* Save index of this sector in FAT */
mov $RootDirSectors,%dx
add %dx,%ax
add $DeltaSecNo,%ax
add (BPB_BytsPerSec),%bx
jmp LABEL_GOON_LOADING_FILE

LABEL_FILE_LOADED:
mov $1,%dh
call DispStr /* Display string(index 1) */

/*******************************************************************
Jump to LOADER.BIN's start address in memory.
*/
jmp $BaseOfLoader,$OffsetOfLoader
/*******************************************************************/

/* ==================================================================
Variable table
*/
wRootDirSizeForLoop: .2byte RootDirSectors
wSectorNo: .2byte 0 /* Sector number to read */
bOdd: .byte 0 /* odd or even? */

/* ==================================================================
String table
*/
LoaderFileName: .asciz "LOADER BIN" /* File name */
.set MessageLength,9
BootMessage: .ascii "Booting**" /* index 0 */
Message1: .ascii "Loaded in" /* index 1 */
Message2: .ascii "No LOADER" /* index 2 */

/* ==================================================================
Routine: DispStr
Action: Display a string, string index stored in %dh
*/
DispStr:
mov $MessageLength, %ax
mul %dh
add $BootMessage,%ax
mov %ax,%bp /* String address */
mov %ds,%ax
mov %ax,%es
mov $MessageLength,%cx /* String length */
mov $0x1301,%ax /* ah = 0x13, al = 0x01(W) */
mov $0x07,%bx /* PageNum 0(bh = 0), bw(bl= 0x07)*/
mov $0,%dl /* Start row and column */
int $0x10 /* BIOS INT 10h, display string */
ret

/* ==================================================================
Routine: ReadSector
Action: Read %cl Sectors From %ax sector(floppy) to %es:%bx(memory)
Assume sector number is 'x', then:
x/(BPB_SecPerTrk) = y,
x%(BPB_SecPerTrk) = z.
The remainder 'z' PLUS 1 is the start sector number;
The quotient 'y' devide by BPB_NumHeads(RIGHT SHIFT 1 bit)is cylinder
number;
AND 'y' by 1 can got magnetic header.
*/
ReadSector:
push %ebp
mov %esp,%ebp
sub $2,%esp /* Reserve space for saving %cl */
mov %cl,-2(%ebp)
push %bx /* Save bx */
mov (BPB_SecPerTrk), %bl /* %bl: the devider */
div %bl /* 'y' in %al, 'z' in %ah */
inc %ah /* z++, got start sector */
mov %ah,%cl /* %cl <- start sector number */
mov %al,%dh /* %dh <- 'y' */
shr $1,%al /* 'y'/BPB_NumHeads */
mov %al,%ch /* %ch <- Cylinder number(y>>1) */
and $1,%dh /* %dh <- Magnetic header(y&1) */
pop %bx /* Restore %bx */
/* Now, we got cylinder number in %ch, start sector number in %cl, magnetic
header in %dh. */
mov (BS_DrvNum), %dl
GoOnReading:
mov $2,%ah
mov -2(%ebp),%al /* Read %al sectors */
int $0x13
jc GoOnReading /* If CF set 1, mean read error, reread. */
add $2,%esp
pop %ebp
ret

/* ==================================================================
Routine: GetFATEntry
Action: Find %ax sector's index in FAT, save result in %ax
*/
GetFATEntry:
push %es
push %bx
push %ax
mov $BaseOfLoader,%ax
sub $0x0100,%ax
mov %ax,%es /* Left 4K bytes for FAT */
pop %ax
movb $0,(bOdd)
mov $3,%bx
mul %bx /* %dx:%ax = %ax*3 */
mov $2,%bx
div %bx /* %dx:%ax/2 */
cmp $0,%bx /* remainder %dx = 0 ? */
jz LABEL_EVEN
movb $1,(bOdd)

LABEL_EVEN:
xor %dx,%dx /* Now %ax is the offset of FATEntry in FAT */
mov (BPB_BytsPerSec),%bx
div %bx /* %dx:%ax/BPB_BytsPerSec */
push %dx
mov $0,%bx
add $SecNoOfFAT1,%ax /* %ax <- FATEntry's sector */
mov $2,%cl /* Read 2 sectors in 1 time, because FATEntry */
call ReadSector /* may be in 2 sectors. */
pop %dx
add %dx,%bx
mov %es:(%bx),%ax
cmpb $1,(bOdd)
jnz LABEL_EVEN_2
shr $4,%ax

LABEL_EVEN_2:
and $0x0fff,%ax

LABEL_GET_FAT_ENTRY_OK:
pop %bx
pop %es
ret

.org 510 /* Skip to address 0x510. */
.2byte 0xaa55 /* Write boot flag to 1st sector(512 bytes) end */
::::::::::::::
loader.S
::::::::::::::
.code16
.text
mov $0xb800,%ax
movw %ax,%gs
mov $0xf,%ah
mov $'L',%al
mov %ax,%gs:((80*0+39)*2)
jmp .
::::::::::::::
solrex_x86_boot.ld
::::::::::::::
SECTIONS
{
. = 0x7c00;
.text :
{
_ftext = .;
} = 0
}
::::::::::::::
solrex_x86_dos.ld
::::::::::::::
SECTIONS
{
. = 0x0100;
.text :
{
_ftext = .;
} = 0
}
::::::::::::::
Makefile
::::::::::::::
CC=gcc
LD=ld
OBJCOPY=objcopy

CFLAGS=-c
TRIM_FLAGS=-R .pdr -R .comment -R.note -S -O binary

LDFILE_BOOT=solrex_x86_boot.ld
LDFILE_DOS=solrex_x86_dos.ld
LDFLAGS_BOOT=-e c -T$(LDFILE_BOOT)
LDFLAGS_DOS=-e c -T$(LDFILE_DOS)

all: boot.img LOADER.BIN

boot.bin: boot.S
$(CC) $(CFLAGS) boot.S
$(LD) boot.o -o boot.elf $(LDFLAGS_BOOT)
$(OBJCOPY) $(TRIM_FLAGS) boot.elf $@

LOADER.BIN: loader.S
$(CC) $(CFLAGS) loader.S
$(LD) loader.o -o loader.elf $(LDFLAGS_DOS)
$(OBJCOPY) $(TRIM_FLAGS) loader.elf $@

boot.img: boot.bin
dd if=/dev/zero of=emptydisk.img bs=512 count=2880
dd if=boot.bin of=boot.img bs=512 count=1
dd if=emptydisk.img of=boot.img skip=1 seek=1 bs=512 count=2879
rm emptydisk.img

# You must have the authority to do mount, or you must use "su root" or
# "sudo" command to do "make copy"
copy: boot.img LOADER.BIN
mkdir -p /tmp/floppy;
mount -o loop boot.img /tmp/floppy/ -o fat=12;
cp LOADER.BIN /tmp/floppy/;
umount /tmp/floppy/;
rm -rf /tmp/floppy/;

clean:
@rm -f *.o *.elf *.bin *.BIN

distclean:
@rm -f *.img